Skip to content

Commit

Permalink
[BE] [PyTorchBot] More understandable error message when labels canno…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
ZainRizvi authored Dec 18, 2024
1 parent 261e7f9 commit 853a7f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 7 additions & 1 deletion torchci/lib/bot/ciflowPushTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ async function handleLabelEvent(
}
}
if (!has_ci_approved) {
let body = `Please seek CI approval before scheduling CIFlow labels`;
let body =
"To add the ciflow label `" +
label +
"` please first approve the workflows " +
"that are awaiting approval (scroll to the bottom of this page).\n\n" +
"This helps ensure we don't trigger CI on this PR until it is actually authorized to do so. " +
"Please ping one of the reviewers if you do not have access to approve and run workflows.";
await context.octokit.issues.createComment(
context.repo({
body,
Expand Down
7 changes: 5 additions & 2 deletions torchci/lib/bot/pytorchBotHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,12 @@ The explanation needs to be clear on why this is needed. Here are some good exam
))
) {
return await this.addComment(
"Can't add following labels to PR: " +
"To add these label(s) (" +
ciflowLabels.join(", ") +
". Please ping one of the reviewers for help."
") to the PR, please first approve the " +
"workflows that are awaiting approval (scroll to the bottom of this page).\n\n" +
"This helps ensure we don't trigger CI on this PR until it is actually authorized to do so. " +
"Please ping one of the reviewers if you do not have access to approve and run workflows."
);
}
if (invalidLabels.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion torchci/test/labelCommands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe("label-bot", () => {
.reply(200, existingRepoLabelsResponse)
.post(`/repos/${owner}/${repo}/issues/${pr_number}/comments`, (body) => {
expect(JSON.stringify(body)).toContain(
`{"body":"Can't add following labels to PR: ciflow/trunk`
`{"body":"To add these label(s) (ciflow/trunk`
);
return true;
})
Expand Down

0 comments on commit 853a7f2

Please sign in to comment.