Skip to content

Commit 1aa9c6a

Browse files
dmitshurgopherbot
authored andcommitted
cmd/gopherbot: skip more deleted issues in addGitHubComment
The deleted issue 55403 wasn't being detected as deleted and causing errors. Add a little logic to handle this category of deleted issues. For golang/go#28320. Updates golang/go#30184. Change-Id: I37f06a1330b6993e5526ea196074102c96fe98f9 Reviewed-on: https://go-review.googlesource.com/c/build/+/442156 Run-TryBot: Dmitri Shuralyov <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent 209d901 commit 1aa9c6a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

cmd/gopherbot/gopherbot.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,23 @@ func (b *gopherbot) addGitHubComment(ctx context.Context, repo *maintner.GitHubR
676676
log.Printf("[dry-run] would add comment to github.com/%s/issues/%d: %v", repo.ID(), issueNum, msg)
677677
return nil
678678
}
679-
_, _, err = b.ghc.Issues.CreateComment(ctx, repo.ID().Owner, repo.ID().Repo, int(issueNum), &github.IssueComment{
679+
_, resp, createError := b.ghc.Issues.CreateComment(ctx, repo.ID().Owner, repo.ID().Repo, int(issueNum), &github.IssueComment{
680680
Body: github.String(msg),
681681
})
682-
return err
682+
if createError != nil && resp != nil && resp.StatusCode == http.StatusUnprocessableEntity {
683+
// While maintner's tracking of deleted issues is incomplete (see go.dev/issue/30184),
684+
// we sometimes see a deleted issue whose /comments endpoint returns 200 OK with an
685+
// empty list, so the error check from ListComments doesn't catch it. (The deleted
686+
// issue 55403 is an example of such a case.) So check again with the Get endpoint,
687+
// which seems to return 404 more reliably in such cases at least as of 2022-10-11.
688+
if _, resp, err := b.ghc.Issues.Get(ctx, repo.ID().Owner, repo.ID().Repo, int(issueNum)); err != nil &&
689+
resp != nil && resp.StatusCode == http.StatusNotFound {
690+
log.Printf("addGitHubComment: Issue %v#%v returned a 404 after posting comment failed with 422. Skipping. See go.dev/issue/30184.", repo.ID(), issueNum)
691+
b.deletedIssues[githubIssue{repo.ID(), issueNum}] = true
692+
return nil
693+
}
694+
}
695+
return createError
683696
}
684697

685698
// createGitHubIssue returns the number of the created issue, or 4242 in dry-run mode.

0 commit comments

Comments
 (0)