Skip to content

Commit

Permalink
Create Dr.CI comment if it doesn't exist (#4949)
Browse files Browse the repository at this point in the history
This happened in
pytorch/pytorch#119774 (comment)
where the bot failed to create the comment due to a GitHub hiccup losing
the event.

Atm, the comment is only created by the bot when the PR is opened or
sync
https://github.com/pytorch/test-infra/blob/main/torchci/lib/bot/drciBot.ts#L6.

When a workflow finishes, making an API call to Dr.CI returns early when
there is no Dr.CI comment
https://github.com/pytorch/test-infra/blob/main/torchci/pages/api/drci/drci.ts#L136-L141

### Testing

Not sure how to test this because there is no mock setup. But this looks
benign enough to jump the bullet?

Co-authored-by: tfsingh <105320310+tfsingh@users.noreply.github.com>
  • Loading branch information
huydhn and tfsingh authored Feb 14, 2024
1 parent a06fd6c commit 9a8bf7e
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions torchci/pages/api/drci/drci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,31 @@ export async function updateDrciComments(
const { id, body } =
existingDrCiComments.get(pr_info.pr_number) ||
(await getDrciComment(octokit, OWNER, repo, pr_info.pr_number));
if (id === 0 || body === comment) {

// The comment is there and remains unchanged, so there is no need to do anything
if (body === comment) {
return;
}

await octokit.rest.issues.updateComment({
body: comment,
owner: OWNER,
repo: repo,
comment_id: id,
});
// If the id is 0, it means that the bot has failed to create the comment, so we
// are free to create a new one here
if (id === 0) {
await octokit.rest.issues.createComment({
body: comment,
owner: OWNER,
repo: repo,
issue_number: pr_info.pr_number,
});
}
// Otherwise, update the existing comment
else {
await octokit.rest.issues.updateComment({
body: comment,
owner: OWNER,
repo: repo,
comment_id: id,
});
}

// Also update the check run status. As this is run under pytorch-bot,
// the check run will show up under that GitHub app
Expand Down

0 comments on commit 9a8bf7e

Please sign in to comment.