Skip to content

Commit

Permalink
Add support for merge_queue events
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap committed Sep 17, 2024
1 parent f66dda1 commit d48f432
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ async function action() {
const skipRegexFlags = core.getInput("skipDescriptionRegexFlags");
const skipDescriptionRegex = !!skipRegexPattern ? new RegExp(skipRegexPattern, skipRegexFlags) : false;

const issueNumber =
let issueNumber =
core.getInput("issueNumber") || github.context.issue?.number;

if (!issueNumber && github.context.eventName == "merge_queue") {
// Parse out of the ref for merge queue
// e.g. refs/heads/gh-readonly-queue/main/pr-17-a3c310584587d4b97c2df0cb46fe050cc46a15d6
const lastPart = github.context.ref.split("/").pop();
issueNumber = lastPart.match(/pr-(\d+)-/)[1];
}

core.debug(`issue number: ${issueNumber}`);

if (!issueNumber) {
Expand Down
25 changes: 24 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ describe("Require Checklist", () => {
});
});

it.only("parses the issue number out of the ref for merge_queue runs", async () => {
delete process.env.INPUT_ISSUENUMBER;
process.env.INPUT_REQUIRECHECKLIST = "false";

const runTools = mockEvent("merge_queue", {}, {
ref: "refs/heads/gh-readonly-queue/main/pr-17-a3c310584587d4b97c2df0cb46fe050cc46a15d6"
});

mockIssueBody("No checklist in the body");
mockIssueComments(["Or in the comments"]);

console.log = jest.fn();
await action(runTools);
expect(console.log).toBeCalledWith(
"There are no incomplete task list items"
);
});

it("handles issues with no checklist, requireChecklist disabled", async () => {
process.env.INPUT_REQUIRECHECKLIST = "false";

Expand Down Expand Up @@ -332,8 +350,13 @@ function mockIssueComments(comments, issueNumber = 17) {
);
}

function mockEvent(name, mockPayload) {
function mockEvent(name, mockPayload, additionalContext = {}) {
github.context.payload = mockPayload;
github.context.eventName = name;

for (const key in additionalContext) {
github.context[key] = additionalContext[key];
}

process.env.GITHUB_EVENT_NAME = name;
process.env.GITHUB_EVENT_PATH = "/github/workspace/event.json";
Expand Down

0 comments on commit d48f432

Please sign in to comment.