Skip to content

Commit 865c77c

Browse files
authored
Restrict actionable label to users with write access (#8008)
- Add `actionable` to the `labels_requiring_write_access` list in `pytorchBotHandler.handleLabel`, so `@pytorchbot label 'actionable'` is only applied when the commenter has write access to the repo; otherwise the bot responds with the existing "Only regular contributors are expected to mark issues as actionable" message.
1 parent f98b5b5 commit 865c77c

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

torchci/lib/bot/pytorchBotHandler.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,15 @@ The explanation needs to be clear on why this is needed. Here are some good exam
447447
);
448448
}
449449

450+
if (
451+
labelsToAdd.includes("actionable") &&
452+
!(await this.hasWritePermissions(ctx.payload?.comment?.user?.login))
453+
) {
454+
return await this.addComment(
455+
"Only regular contributors are expected to mark issues as actionable."
456+
);
457+
}
458+
450459
// Labels only people with write access to the repo should be able to add
451460
const labels_requiring_write_access: string[] = ["skip-pr-sanity-check"];
452461
const write_required_labels = labelsToAdd.filter((l: string) =>

torchci/test/labelCommands.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,4 +352,32 @@ describe("label-bot", () => {
352352
await probot.receive(event);
353353
handleScope(scope);
354354
});
355+
356+
test("label actionable without write permissions is rejected", async () => {
357+
const event = require("./fixtures/issue_comment.json");
358+
event.payload.comment.body = "@pytorchbot label 'actionable'";
359+
const owner = event.payload.repository.owner.login;
360+
const repo = event.payload.repository.name;
361+
const issue_number = event.payload.issue.number;
362+
const user = event.payload.comment.user.login;
363+
364+
const scope = nock("https://api.github.com")
365+
.get(`/repos/${owner}/${repo}/labels`)
366+
.reply(200, existingRepoLabelsResponse)
367+
.get(`/repos/${owner}/${repo}/collaborators/${user}/permission`)
368+
.reply(200, { permission: "read" })
369+
.post(
370+
`/repos/${owner}/${repo}/issues/${issue_number}/comments`,
371+
(body) => {
372+
expect(JSON.stringify(body)).toContain(
373+
"Only regular contributors are expected to mark issues as actionable."
374+
);
375+
return true;
376+
}
377+
)
378+
.reply(200, {});
379+
380+
await probot.receive(event);
381+
handleScope(scope);
382+
});
355383
});

0 commit comments

Comments
 (0)