Skip to content

Commit ec8cb08

Browse files
authored
Skip workflow_run events that are awaiting approval (#8028)
- `handleWorkflowRunEvent` (added in #7958, refined in #7970) listens to `workflow_run.requested`, which GitHub fires as soon as it creates the run record — including runs in `waiting` / `action_required` state on first-time-contributor PRs. - The handler never checked status, so it would mint ciflow tags off the *request* event, defeating the approval deferral that #7958 was built for. - Bail out early when `workflow_run.status` is `waiting` or `action_required`. Approved runs transition out of those states before subsequent `workflow_run` events, so legitimate post-approval triggers (and the `.completed` path) still work.
1 parent e04f082 commit ec8cb08

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

torchci/lib/bot/ciflowPushTrigger.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,15 @@ async function handleWorkflowRunEvent(context: Context<"workflow_run">) {
297297
return;
298298
}
299299

300+
// Skip runs that GitHub created but hasn't actually started yet, e.g. those
301+
// awaiting maintainer approval on first-time-contributor PRs. workflow_run.requested
302+
// fires when the run record is created, including in `waiting` / `action_required`
303+
// state, and creating tags here would defeat the deferral this handler exists for.
304+
const status = (payload.workflow_run as any).status;
305+
if (status === "waiting" || status === "action_required") {
306+
return;
307+
}
308+
300309
let prNumbers: number[] = (payload.workflow_run.pull_requests ?? []).map(
301310
(pr: any) => pr.number
302311
);

torchci/test/ciflow-push-trigger.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,38 @@ describe("Push trigger integration tests", () => {
518518
await probot.receive({ name: "pull_request", id: "123", payload });
519519
});
520520

521+
test("workflow_run awaiting approval does not create tags", async () => {
522+
// workflow_run.requested fires when GitHub creates the run record, including
523+
// for runs that haven't been approved yet on first-time-contributor PRs.
524+
// The handler must not mint tags off these events.
525+
const payload = {
526+
action: "requested",
527+
workflow_run: {
528+
event: "pull_request",
529+
status: "waiting",
530+
head_sha: "abc123",
531+
head_branch: "feature-branch",
532+
head_repository: {
533+
owner: { login: "fork-user" },
534+
},
535+
pull_requests: [{ number: 42 }],
536+
},
537+
repository: {
538+
owner: { login: "suo" },
539+
name: "actions-test",
540+
full_name: "suo/actions-test",
541+
},
542+
};
543+
544+
// No requests should be made -- the handler should bail out before
545+
// touching the GitHub API.
546+
await probot.receive({
547+
name: "workflow_run" as any,
548+
id: "789",
549+
payload: payload as any,
550+
});
551+
});
552+
521553
test("workflow_run with empty pull_requests falls back to SHA lookup", async () => {
522554
const head_sha = "abc123def456";
523555
const prNum = 42;

0 commit comments

Comments
 (0)