Automate fetching the default branch for knative orgs
@@ -21,6 +21,7 @@ package main
import (
"bytes"
+ "context"
"flag"
"fmt"
"io"
@@ -35,6 +36,7 @@ import (
"text/template"
"time"
+ "github.com/google/go-github/v32/github"
"gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/util/sets"
@@ -59,22 +61,10 @@ var (
// GitHub repos that are not using knative.dev path alias.
nonPathAliasRepos = sets.NewString("knative/docs")
- // Repos that have changed the branch name from master to main
+ // Repos that have changed the branch name from master to main. We'll automatically
+ // look up everything in the knative and knative-sandbox org.
mainBranchRepos = sets.NewString(
"google/knative-gcp",
- "knative/release",
- "knative/specs",
- "knative/ux",
- "knative-sandbox/actions-kind",
- "knative-sandbox/control-protocol",
- "knative-sandbox/kn-plugin-diag",
- "knative-sandbox/kn-plugin-event",
- "knative-sandbox/kn-plugin-migration",
- "knative-sandbox/kn-plugin-sample",
- "knative-sandbox/kn-plugin-service-log",
- "knative-sandbox/kn-plugin-source-kamelet",
- "knative-sandbox/net-ingressv2",
- "knative-sandbox/sample-controller",
)
)
@@ -253,6 +243,7 @@ func newbaseProwJobTemplateData(repo string) baseProwJobTemplateData {
data.ExtraRefs = append(data.ExtraRefs, " "+data.PathAlias)
}
data.RepoNameForJob = strings.ToLower(strings.Replace(repo, "/", "-", -1))
+
if mainBranchRepos.Has(repo) {
data.RepoBranch = "main" // Default to be main for repos that have changed the branch name from master to main
} else {
@@ -775,6 +766,23 @@ func main() {
}
}
+ // Fill in the main exception list. We fetch this once for all of our orgs to avoid
+ // rate-limiting issues with Github.
+ client := github.NewClient(nil)
+ for org := range pathAliasOrgs {
+ repos, _, err := client.Repositories.List(context.Background(), org, &github.RepositoryListOptions{
+ ListOptions: github.ListOptions{PerPage: 200},
+ })
+ if err != nil {
+ logFatalf("Cannot fetch default repos for %s org: %v", org, err)
+ }
+ for _, r := range repos {
+ if r.DefaultBranch != nil && *r.DefaultBranch == "main" {
+ mainBranchRepos.Insert(*r.FullName)
+ }
+ }
+ }
+
configFileContent, err := ioutil.ReadFile(configFileName)
if err != nil {
logFatalf("Cannot read file %q: %v", configFileName, err)
