Skip to content

Commit 3a7064f

Browse files
authored
[bots] Remove ciflow labels on sync if no perms, follow up to #6328 (#6342)
Follow up to #6328 Remove the ciflow labels on sync to reduce confusion Cons: * add more events to the PR timeline
1 parent bc59f8d commit 3a7064f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

torchci/lib/bot/ciflowPushTrigger.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ async function handleSyncEvent(
9292

9393
if (!(await canRunWorkflows(context as any))) {
9494
context.log.info("PR does not have permissions to run workflows");
95+
for (const label of payload.pull_request.labels) {
96+
if (isCIFlowLabel(label.name)) {
97+
await context.octokit.issues.removeLabel(
98+
context.repo({
99+
issue_number: payload.pull_request.number,
100+
name: label.name,
101+
})
102+
);
103+
}
104+
}
95105
return;
96106
}
97107

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import {
99

1010
nock.disableNetConnect();
1111

12+
function mockDeleteLabel(repoFullName: string, number: number, label: string) {
13+
return nock("https://api.github.com")
14+
.delete(
15+
`/repos/${repoFullName}/issues/${number}/labels/${encodeURIComponent(
16+
label
17+
)}`
18+
)
19+
.reply(200);
20+
}
21+
1222
describe("Push trigger integration tests", () => {
1323
let probot: Probot;
1424
beforeEach(() => {
@@ -238,6 +248,16 @@ describe("Push trigger integration tests", () => {
238248
payload.pull_request.user.login,
239249
"read"
240250
);
251+
mockDeleteLabel(
252+
payload.repository.full_name,
253+
payload.pull_request.number,
254+
"ciflow/test"
255+
);
256+
mockDeleteLabel(
257+
payload.repository.full_name,
258+
payload.pull_request.number,
259+
"ciflow/1"
260+
);
241261
await probot.receive({ name: "pull_request", id: "123", payload });
242262
});
243263

0 commit comments

Comments
 (0)