cmd/gopherbot: label gopls issues automatically

This change configures gopherbot to automatically label issues with
"gopls" or "lsp" in the title as "gopls".

Change-Id: I1b6639558551a29f22375732592cb13819748115
Reviewed-on: https://go-review.googlesource.com/c/build/+/172097
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/cmd/gopherbot/gopherbot.go b/cmd/gopherbot/gopherbot.go
index 71eb059..5a3e7cd 100644
--- a/cmd/gopherbot/gopherbot.go
+++ b/cmd/gopherbot/gopherbot.go
@@ -280,6 +280,7 @@
 	{"label build issues", (*gopherbot).labelBuildIssues},
 	{"label mobile issues", (*gopherbot).labelMobileIssues},
 	{"label documentation issues", (*gopherbot).labelDocumentationIssues},
+	{"label gopls issues", (*gopherbot).labelGoplsIssues},
 	{"close stale WaitingForInfo", (*gopherbot).closeStaleWaitingForInfo},
 	{"cl2issue", (*gopherbot).cl2issue},
 	{"update needs", (*gopherbot).updateNeeds},
@@ -832,6 +833,15 @@
 	})
 }
 
+func (b *gopherbot) labelGoplsIssues(ctx context.Context) error {
+	return b.gorepo.ForeachIssue(func(gi *maintner.GitHubIssue) error {
+		if gi.Closed || gi.PullRequest || !isGoplsTitle(gi.Title) || gi.HasLabel("gopls") || gi.HasEvent("unlabeled") {
+			return nil
+		}
+		return b.addLabel(ctx, gi, "gopls")
+	})
+}
+
 func (b *gopherbot) closeStaleWaitingForInfo(ctx context.Context) error {
 	const waitingForInfo = "WaitingForInfo"
 	now := time.Now()
@@ -1916,6 +1926,10 @@
 		strings.Contains(t, "docs ")
 }
 
+func isGoplsTitle(t string) bool {
+	return strings.Contains(t, "gopls") || strings.Contains(t, "lsp")
+}
+
 var lastTask string
 
 func printIssue(task string, gi *maintner.GitHubIssue) {