Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Merge PR API #8232

Merged
merged 15 commits into from
Sep 29, 2024
Merged
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
Loading