@@ -676,10 +676,23 @@ func (b *gopherbot) addGitHubComment(ctx context.Context, repo *maintner.GitHubR
676
676
log .Printf ("[dry-run] would add comment to github.com/%s/issues/%d: %v" , repo .ID (), issueNum , msg )
677
677
return nil
678
678
}
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 {
680
680
Body : github .String (msg ),
681
681
})
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
683
696
}
684
697
685
698
// createGitHubIssue returns the number of the created issue, or 4242 in dry-run mode.
0 commit comments