cmd/coordinator: use better value for GoBranch

Previously, we were using the branch of golang.org/x repo as the
GoBranch, which is inaccurate. It made little difference because
few builder policies filter by GoBranch at this time.

Fixes golang/go#38303.

Change-Id: Iaeff8ca7ceeb81eb57073d3bc5533db3c9e30504
Reviewed-on: https://go-review.googlesource.com/c/build/+/319791
Reviewed-by: Carlos Amedee <carlos@golang.org>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/cmd/coordinator/coordinator.go b/cmd/coordinator/coordinator.go
index b5056ef..8edb6cf 100644
--- a/cmd/coordinator/coordinator.go
+++ b/cmd/coordinator/coordinator.go
@@ -1184,14 +1184,17 @@
 //
 // Must hold statusMu.
 func newTrySet(work *apipb.GerritTryWorkItem) *trySet {
-	key := tryWorkItemKey(work)
-	// TODO(golang.org/issue/38303): compute goBranch value better
-	goBranch := key.Branch // assume same as repo's branch for now
-
-	tryBots := dashboard.TryBuildersForProject(key.Project, key.Branch, goBranch)
+	goBranch := work.Branch
+	if work.Project != "go" && len(work.GoBranch) > 0 {
+		// work.GoBranch is non-empty when work.Project != "go",
+		// so prefer work.GoBranch[0] over work.Branch.
+		goBranch = work.GoBranch[0]
+	}
+	tryBots := dashboard.TryBuildersForProject(work.Project, work.Branch, goBranch)
 	slowBots := slowBotsFromComments(work)
 	builders := joinBuilders(tryBots, slowBots)
 
+	key := tryWorkItemKey(work)
 	log.Printf("Starting new trybot set for %v", key)
 	ts := &trySet{
 		tryKey: key,