Skip to content

Commit

Permalink
fix: allow merging commits with no statuses (#89)
Browse files Browse the repository at this point in the history
- When no statuses are set for a commit, github api returns combined status "pending" even if all check-runs
etc are completed. Requiring a hard "success" will never pass in this configuration...
- If no statuses are set, none should be expected, and so they can be treated as "success" regardless

Co-authored-by: Felix Marcus Millne <[email protected]>
  • Loading branch information
FelixMarcus and FelixMarcusMillne committed Oct 23, 2023
1 parent baae22d commit 8263e63
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ export async function getCommitStatusesStatus(
ref: commitRef,
});

if (data.statuses === undefined || data.statuses.length === 0)
return "success";

return data.state as "success" | "pending" | "failure";
}
20 changes: 14 additions & 6 deletions lib/handle-schedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe("handleSchedule", () => {

expect(mockStdout.mock.calls).toEqual([
[`Loading open pull requests\n`],
[`6 scheduled pull requests found\n`],
[`5 due pull requests found\n`],
[`7 scheduled pull requests found\n`],
[`6 due pull requests found\n`],
[`https://github.com/gr2m/merge-schedule-action/pull/2 merged\n`],
[
`Comment created: https://github.com/gr2m/merge-schedule-action/issues/2#issuecomment-22\n`,
Expand All @@ -55,8 +55,12 @@ describe("handleSchedule", () => {
[
`Comment created: https://github.com/gr2m/merge-schedule-action/issues/7#issuecomment-72\n`,
],
[`https://github.com/gr2m/merge-schedule-action/pull/14 merged\n`],
[
`Comment created: https://github.com/gr2m/merge-schedule-action/issues/14#issuecomment-142\n`,
],
]);
expect(createComment.mock.calls).toHaveLength(3);
expect(createComment.mock.calls).toHaveLength(4);
expect(createComment.mock.calls[0][2]).toMatchInlineSnapshot(`
":white_check_mark: **Merge Schedule**
Scheduled on 2022-06-08 (UTC) successfully merged
Expand Down Expand Up @@ -97,8 +101,8 @@ describe("handleSchedule", () => {

expect(mockStdout.mock.calls).toEqual([
[`Loading open pull requests\n`],
[`6 scheduled pull requests found\n`],
[`5 due pull requests found\n`],
[`7 scheduled pull requests found\n`],
[`6 due pull requests found\n`],
[`https://github.com/gr2m/merge-schedule-action/pull/2 merged\n`],
[
`Comment created: https://github.com/gr2m/merge-schedule-action/issues/2#issuecomment-22\n`,
Expand All @@ -118,8 +122,12 @@ describe("handleSchedule", () => {
[
`Comment created: https://github.com/gr2m/merge-schedule-action/issues/7#issuecomment-72\n`,
],
[`https://github.com/gr2m/merge-schedule-action/pull/14 merged\n`],
[
`Comment created: https://github.com/gr2m/merge-schedule-action/issues/14#issuecomment-142\n`,
],
]);
expect(createComment.mock.calls).toHaveLength(3);
expect(createComment.mock.calls).toHaveLength(4);
expect(createComment.mock.calls[0][2]).toMatchInlineSnapshot(`
":white_check_mark: **Merge Schedule**
Scheduled on 2022-06-08 (UTC) successfully merged
Expand Down
15 changes: 14 additions & 1 deletion test/mocks/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ const pullRequests = [
},
labels: [],
},
{
number: 14,
html_url: githubPullRequestUrl(14),
state: "open",
body: "Simple body\n/schedule 2022-06-09",
head: {
sha: "abc123pending-empty",
repo: {
fork: false,
},
},
labels: [],
},
];
const pullRequestComments = pullRequests.map((pullRequest) => {
let body = "";
Expand Down Expand Up @@ -258,7 +271,7 @@ export const githubHandlers = [
ctx.status(200),
ctx.json({
state: req.params.ref.endsWith("success") ? "success" : "pending",
statuses: [],
statuses: req.params.ref.endsWith("pending-empty") ? [] : ["pending"],
})
);
}
Expand Down

0 comments on commit 8263e63

Please sign in to comment.