From 853a7f2216767e97b894574163cfba8e392e333e Mon Sep 17 00:00:00 2001 From: Zain Rizvi Date: Wed, 18 Dec 2024 13:17:12 -0600 Subject: [PATCH] [BE] [PyTorchBot] More understandable error message when labels cannot be added (#6088) Fixes https://github.com/pytorch/test-infra/issues/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 https://github.com/pytorch/test-infra/pull/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. --- torchci/lib/bot/ciflowPushTrigger.ts | 8 +++++++- torchci/lib/bot/pytorchBotHandler.ts | 7 +++++-- torchci/test/labelCommands.test.ts | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/torchci/lib/bot/ciflowPushTrigger.ts b/torchci/lib/bot/ciflowPushTrigger.ts index 893438aa46..07443ab815 100644 --- a/torchci/lib/bot/ciflowPushTrigger.ts +++ b/torchci/lib/bot/ciflowPushTrigger.ts @@ -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, diff --git a/torchci/lib/bot/pytorchBotHandler.ts b/torchci/lib/bot/pytorchBotHandler.ts index 041c84a519..71dfc0c1f4 100644 --- a/torchci/lib/bot/pytorchBotHandler.ts +++ b/torchci/lib/bot/pytorchBotHandler.ts @@ -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) { diff --git a/torchci/test/labelCommands.test.ts b/torchci/test/labelCommands.test.ts index 21f774852d..e2337ff5b7 100644 --- a/torchci/test/labelCommands.test.ts +++ b/torchci/test/labelCommands.test.ts @@ -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; })