cmd/gopherbot: skip labeling nonexistent issues

When an issue is transferred, we incorrectly continue trying to manage
the issue with Gopherbot, even though we should be able to pick up the
new issue and decide if it is Gopherbot's responsibility. As a temporary
fix, this change skips issues which return a 404 when adding labels.

For golang/go#40640

Change-Id: Ib84490c1e41a71b14c0f736a41d1f6032a3c2c92
Reviewed-on: https://go-review.googlesource.com/c/build/+/256040
Trust: Alexander Rakoczy <alex@golang.org>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
diff --git a/cmd/gopherbot/gopherbot.go b/cmd/gopherbot/gopherbot.go
index f1cddda..7a55dbe 100644
--- a/cmd/gopherbot/gopherbot.go
+++ b/cmd/gopherbot/gopherbot.go
@@ -408,7 +408,13 @@
 		return nil
 	}
 
-	_, _, err := b.is.AddLabelsToIssue(ctx, repoID.Owner, repoID.Repo, int(gi.Number), toAdd)
+	_, resp, err := b.is.AddLabelsToIssue(ctx, repoID.Owner, repoID.Repo, int(gi.Number), toAdd)
+	if err != nil && resp != nil && resp.StatusCode == http.StatusNotFound {
+		// TODO(golang/go#40640) - This issue was transferred or otherwise is gone. We should permanently skip it. This
+		// is a temporary fix to keep gopherbot working.
+		log.Printf("addLabels: Issue %v#%v returned a 404 when trying to add labels. Skipping. See golang/go#40640.", repoID, gi.Number)
+		return nil
+	}
 	return err
 }