Skip to content

Commit 853a7f2

Browse files
authored
[BE] [PyTorchBot] More understandable error message when labels cannot be added (#6088)
Fixes #5900 When a `ciflow` label is added to a PR, we normally trigger workflows against it. However, if the PR has not yet been authorized to actually run workflows then we do not allow the label to be added. (This feature was added by #4892) This change improves the reasoning given by the error messages, making it easier for the reviewer to understand why a label was not added to the PR and the steps they need to take to actually add the desired label.
1 parent 261e7f9 commit 853a7f2

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

torchci/lib/bot/ciflowPushTrigger.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,13 @@ async function handleLabelEvent(
193193
}
194194
}
195195
if (!has_ci_approved) {
196-
let body = `Please seek CI approval before scheduling CIFlow labels`;
196+
let body =
197+
"To add the ciflow label `" +
198+
label +
199+
"` please first approve the workflows " +
200+
"that are awaiting approval (scroll to the bottom of this page).\n\n" +
201+
"This helps ensure we don't trigger CI on this PR until it is actually authorized to do so. " +
202+
"Please ping one of the reviewers if you do not have access to approve and run workflows.";
197203
await context.octokit.issues.createComment(
198204
context.repo({
199205
body,

torchci/lib/bot/pytorchBotHandler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,12 @@ The explanation needs to be clear on why this is needed. Here are some good exam
481481
))
482482
) {
483483
return await this.addComment(
484-
"Can't add following labels to PR: " +
484+
"To add these label(s) (" +
485485
ciflowLabels.join(", ") +
486-
". Please ping one of the reviewers for help."
486+
") to the PR, please first approve the " +
487+
"workflows that are awaiting approval (scroll to the bottom of this page).\n\n" +
488+
"This helps ensure we don't trigger CI on this PR until it is actually authorized to do so. " +
489+
"Please ping one of the reviewers if you do not have access to approve and run workflows."
487490
);
488491
}
489492
if (invalidLabels.length > 0) {

torchci/test/labelCommands.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ describe("label-bot", () => {
162162
.reply(200, existingRepoLabelsResponse)
163163
.post(`/repos/${owner}/${repo}/issues/${pr_number}/comments`, (body) => {
164164
expect(JSON.stringify(body)).toContain(
165-
`{"body":"Can't add following labels to PR: ciflow/trunk`
165+
`{"body":"To add these label(s) (ciflow/trunk`
166166
);
167167
return true;
168168
})

0 commit comments

Comments
 (0)