cmd/gopherbot: handle 404 GitHub issues in freezeOldIssues task
A GitHub issue can become 404. Attempting to lock it will produce a
404 response from the GitHub API. Don't treat it as a fatal error
when it happens.
Add a check for the NotExist field. This will help after golang/go#30184
is resolved.
Updates golang/go#30182
Change-Id: Ia04c59879909b1de00bd681606bfa331fe642cd4
Reviewed-on: https://go-review.googlesource.com/c/161906
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/cmd/gopherbot/gopherbot.go b/cmd/gopherbot/gopherbot.go
index b2c6076..4093817 100644
--- a/cmd/gopherbot/gopherbot.go
+++ b/cmd/gopherbot/gopherbot.go
@@ -701,7 +701,7 @@
func (b *gopherbot) freezeOldIssues(ctx context.Context) error {
tooOld := time.Now().Add(-365 * 24 * time.Hour)
return b.gorepo.ForeachIssue(func(gi *maintner.GitHubIssue) error {
- if !gi.Closed || gi.PullRequest || gi.Locked {
+ if gi.NotExist || !gi.Closed || gi.PullRequest || gi.Locked {
return nil
}
if gi.Updated.After(tooOld) {
@@ -712,7 +712,11 @@
return nil
}
_, err := b.ghc.Issues.Lock(ctx, "golang", "go", int(gi.Number), nil)
- if err != nil {
+ if ge, ok := err.(*github.ErrorResponse); ok && ge.Response.StatusCode == http.StatusNotFound {
+ // It's rare, but an issue can become 404 on GitHub. See golang.org/issue/30182.
+ // Nothing to do since the issue is gone.
+ return nil
+ } else if err != nil {
return err
}
return b.addLabel(ctx, gi, frozenDueToAge)