cmd/coordinator: move skip branch policy into dashboard

This change takes care of a TODO comment. It makes the builder
configuration more centralized and contained in the dashboard
package.

Invert it for consistency with BuildConfig.BuildRepo method.

Updates golang/go#26791

Change-Id: I46368adadb85f2ec730da4fc0abe5fd6a112a7c7
Reviewed-on: https://go-review.googlesource.com/c/149738
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/cmd/coordinator/coordinator.go b/cmd/coordinator/coordinator.go
index 7bb9774..087d6e7 100644
--- a/cmd/coordinator/coordinator.go
+++ b/cmd/coordinator/coordinator.go
@@ -884,10 +884,6 @@
 				continue
 			}
 			builder := bs.Builders[i]
-			if skipBranchForBuilder(br.Repo, br.Branch, br.GoBranch, builder) {
-				continue
-			}
-
 			builderInfo, ok := dashboard.Builders[builder]
 			if !ok || builderInfo.TryOnly {
 				// Not managed by the coordinator, or a trybot-only one.
@@ -896,6 +892,9 @@
 			if !builderInfo.BuildRepo(br.Repo) {
 				continue
 			}
+			if !builderInfo.BuildBranch(br.Repo, br.Branch, br.GoBranch) {
+				continue
+			}
 
 			var rev buildgo.BuilderRev
 			if br.Repo == "go" {
@@ -934,7 +933,7 @@
 		if builderInfo.TryOnly || knownToDashboard[b] {
 			continue
 		}
-		if skipBranchForBuilder("go", "master", "master", b) {
+		if !builderInfo.BuildBranch("go", "master", "") {
 			continue
 		}
 		for _, rev := range goRevisions {
@@ -3633,41 +3632,3 @@
 	}
 	return fmt.Sprintf("%x", buf)[:n]
 }
-
-// repo is "go", "net", etc.
-// branch is the branch of the repo (usually "master").
-// goGranch is non-empty for a non-"go" repo, and is the branch of Go the subrepo is being tested at.
-// builder is a build config name.
-func skipBranchForBuilder(repo, branch, goBranch, builder string) bool {
-	// TODO: move this policy into a new BuildConfig policy func
-	// in dashboard/builders.go.
-	if strings.HasPrefix(builder, "darwin-") {
-		switch builder {
-		case "darwin-amd64-10_8", "darwin-amd64-10_10", "darwin-amd64-10_11",
-			"darwin-386-10_8", "darwin-386-10_10", "darwin-386-10_11":
-			// OS X before Sierra can build any branch.
-			// (We've never had a 10.9 builder.)
-		default:
-			// Sierra or after, however, requires the 1.7 branch:
-			switch branch {
-			case "release-branch.go1.6",
-				"release-branch.go1.5",
-				"release-branch.go1.4",
-				"release-branch.go1.3",
-				"release-branch.go1.2",
-				"release-branch.go1.1",
-				"release-branch.go1":
-				return true
-			}
-		}
-	}
-	// NetBSD support was resurrected during the Go 1.10 dev cycle.
-	// Skip subrepo builds against Go 1.8 and Go 1.9. Failures there aren't interesting.
-	if strings.HasPrefix(builder, "netbsd-") {
-		switch goBranch {
-		case "release-branch.go1.8", "release-branch.go1.9":
-			return true
-		}
-	}
-	return false
-}
diff --git a/dashboard/builders.go b/dashboard/builders.go
index 46120ff..1d1a877 100644
--- a/dashboard/builders.go
+++ b/dashboard/builders.go
@@ -835,6 +835,43 @@
 	return c.buildSubrepos()
 }
 
+// BuildBranch reports whether we should do post-submit builds of the provided
+// branch.
+// repo is "go", "sys", "net", etc.
+// branch is the branch of the repo (usually "master").
+// goBranch is non-empty for a non-"go" repo, and is the branch of Go the subrepo is being tested at.
+func (c *BuildConfig) BuildBranch(repo, branch, goBranch string) bool {
+	if strings.HasPrefix(c.Name, "darwin-") {
+		switch c.Name {
+		case "darwin-amd64-10_8", "darwin-amd64-10_10", "darwin-amd64-10_11",
+			"darwin-386-10_8", "darwin-386-10_10", "darwin-386-10_11":
+			// OS X before Sierra can build any branch.
+			// (We've never had a 10.9 builder.)
+		default:
+			// Sierra or after, however, requires the 1.7 branch:
+			switch branch {
+			case "release-branch.go1.6",
+				"release-branch.go1.5",
+				"release-branch.go1.4",
+				"release-branch.go1.3",
+				"release-branch.go1.2",
+				"release-branch.go1.1",
+				"release-branch.go1":
+				return false
+			}
+		}
+	}
+	// NetBSD support was resurrected during the Go 1.10 dev cycle.
+	// Skip subrepo builds against Go 1.8 and Go 1.9. Failures there aren't interesting.
+	if strings.HasPrefix(c.Name, "netbsd-") {
+		switch goBranch {
+		case "release-branch.go1.8", "release-branch.go1.9":
+			return false
+		}
+	}
+	return true
+}
+
 // AllScriptArgs returns the set of arguments that should be passed to the
 // all.bash-equivalent script. Usually empty.
 func (c *BuildConfig) AllScriptArgs() []string {