Skip to content

Commit c8fcc2b

Browse files
committed
fix(ci): cancel stale labeler runs on human label changes
Listen for labeled and unlabeled pull_request_target events so a human type-label edit enqueues a fresher run in the per-PR concurrency group and cancels any in-flight title sync. Add workflow contract tests for the activity types and preserved security settings.
1 parent 34c6a66 commit c8fcc2b

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎.github/scripts/pr-labeler.test.cjs‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use strict";
22

3+
const fs = require("node:fs");
4+
const path = require("node:path");
35
const { describe, it } = require("node:test");
46
const assert = require("node:assert/strict");
57
const {
@@ -142,3 +144,29 @@ describe("planTypeLabelSync", () => {
142144
assert.deepEqual(plan, { skip: true, reason: "no-prefix" });
143145
});
144146
});
147+
148+
describe("pr-labeler workflow", () => {
149+
const workflowPath = path.join(__dirname, "../workflows/pr-labeler.yml");
150+
const workflow = fs.readFileSync(workflowPath, "utf8");
151+
152+
function pullRequestTargetTypes() {
153+
const match = workflow.match(/pull_request_target:\s*\n(?:[ \t].*\n)*?[ \t]+types:\s*\[([^\]]+)\]/);
154+
assert.ok(match, "expected pull_request_target types array in pr-labeler.yml");
155+
return match[1].split(",").map((type) => type.trim());
156+
}
157+
158+
it("listens for labeled and unlabeled so human overrides cancel stale sync runs", () => {
159+
const types = pullRequestTargetTypes();
160+
assert.ok(types.includes("labeled"), "missing pull_request_target type: labeled");
161+
assert.ok(types.includes("unlabeled"), "missing pull_request_target type: unlabeled");
162+
assert.ok(types.includes("synchronize"), "missing pull_request_target type: synchronize");
163+
});
164+
165+
it("keeps trusted default-branch checkout, concurrency cancel, and minimal permissions", () => {
166+
assert.match(workflow, /ref:\s*\$\{\{\s*github\.event\.repository\.default_branch\s*\}\}/);
167+
assert.match(workflow, /cancel-in-progress:\s*true/);
168+
assert.match(workflow, /pull-requests:\s*read/);
169+
assert.match(workflow, /issues:\s*write/);
170+
assert.doesNotMatch(workflow, /pull-requests:\s*write/);
171+
});
172+
});

‎.github/workflows/pr-labeler.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ name: PR Labeler
66
# branch — same promotion model as enforce-issue-quality.yml.
77
on:
88
pull_request_target:
9-
types: [opened, edited, synchronize]
9+
# labeled/unlabeled let a human type-label change enqueue a fresher run in the
10+
# per-PR concurrency group, cancelling any in-flight title sync that started
11+
# before the override (PR #518 race).
12+
types: [opened, edited, synchronize, labeled, unlabeled]
1013

1114
concurrency:
1215
group: pr-labeler-${{ github.event.pull_request.number }}

0 commit comments

Comments
 (0)