Skip to content

Commit

Permalink
Integrate Merge PR API (#8232)
Browse files Browse the repository at this point in the history
* Update src-dest UI in Pulls list

* Show closed/merged timestamp in the Pulls list

* Show merged commit link in merged PR details

* Cleanup

* Handle empty diffs

* Handle deleted branch errors

* Disable button when branch not found

* Update field name

* Fix PR comments

* Integrate Merge PR API

* Remove log

* Update error message
  • Loading branch information
itaigilo authored Sep 29, 2024
1 parent d42d757 commit aa44bac
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
7 changes: 4 additions & 3 deletions webui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"bootstrap": "^5.3.2",
"csstype": "^3.1.3",
"dayjs": "^1.11.10",
"exponential-backoff": "^3.1.1",
"lodash": "^4.17.21",
"p-map": "^7.0.0",
"prismjs": "^1.29.0",
Expand Down
20 changes: 20 additions & 0 deletions webui/src/lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,26 @@ class Pulls {
return response.json()
}

async merge(repoId, pullId) {
const response = await apiRequest(`/repositories/${encodeURIComponent(repoId)}/pulls/${encodeURIComponent(pullId)}/merge`, {
method: 'PUT',
});
if (response.status !== 200) {
const baseMessage = 'Could not merge pull request';
switch (response.status) {
case 400:
case 401:
case 403:
case 404:
case 409:
case 412:
throw new Error(`${baseMessage}: ${(await response.json()).message}`);
default:
throw new Error(`${baseMessage} (status = ${response.status}).`);
}
}
}

async update(repoId, pullId, pullDetails) {
const response = await apiRequest(`/repositories/${encodeURIComponent(repoId)}/pulls/${encodeURIComponent(pullId)}`, {
method: 'PATCH',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const CreatePullForm = ({repo, reference, compare}) => {
{error && <AlertError error={error} onDismiss={() => setError(null)}/>}
<div>
<Button variant="success"
disabled={!title || !description || loading || isEmptyDiff}
disabled={!title || loading || isEmptyDiff}
onClick={submitForm}>
{loading && <><span className="spinner-border spinner-border-sm text-light" role="status"/> {""}</>}
Create Pull Request
Expand Down
13 changes: 3 additions & 10 deletions webui/src/pages/repositories/repository/pulls/pullDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import Card from "react-bootstrap/Card";
import {GitMergeIcon, GitPullRequestClosedIcon, GitPullRequestIcon} from "@primer/octicons-react";
import dayjs from "dayjs";
import Markdown from 'react-markdown'
import {backOff} from "exponential-backoff";

import {AlertError, Loading} from "../../../../lib/components/controls";
import {useRefs} from "../../../../lib/hooks/repo";
import {useRouter} from "../../../../lib/hooks/router";
import {RepoError} from "../error";
import {pulls as pullsAPI, refs as refsAPI} from "../../../../lib/api";
import {pulls as pullsAPI} from "../../../../lib/api";
import {useAPI} from "../../../../lib/hooks/api";
import {Link} from "../../../../lib/components/nav";
import CompareBranches from "../../../../lib/components/repository/compareBranches";
Expand All @@ -32,18 +31,12 @@ const PullDetailsContent = ({repo, pull}) => {
setError(null);
setLoading(true);
try {
await refsAPI.merge(repo.id, pull.source_branch, pull.destination_branch);
await pullsAPI.merge(repo.id, pull.id);
} catch (error) {
setError(`Failed to merge pull request: ${error.message}`);
setError(error.message);
setLoading(false);
return;
}
try {
await backOff(() => pullsAPI.update(repo.id, pull.id, {status: PullStatus.merged}));
} catch (error) {
setError(`Failed to update pull request status: ${error.message}`);
setLoading(false);
}
window.location.reload(); // TODO (gilo): replace with a more elegant solution
}

Expand Down

0 comments on commit aa44bac

Please sign in to comment.