diff --git a/cmd/gitmirror/gitmirror.go b/cmd/gitmirror/gitmirror.go index 3ecf33bc0a..18c4767f02 100644 --- a/cmd/gitmirror/gitmirror.go +++ b/cmd/gitmirror/gitmirror.go @@ -78,7 +78,7 @@ var httpClient = &http.Client{ Timeout: 30 * time.Second, // overkill } -var gerritClient = gerrit.NewClient(goBase, gerrit.NoAuth) +var gerritClient = gerrit.NewClient("https://go-review.googlesource.com", gerrit.NoAuth) var ( // gitLogFn returns the list of unseen Commits on a Repo, @@ -225,7 +225,11 @@ func runGitMirror() error { go startRepo(name, path, true) } if *mirror { - for name := range gerritMetaMap() { + gerritRepos, err := gerritMetaMap() + if err != nil { + return fmt.Errorf("gerritMetaMap: %v", err) + } + for name := range gerritRepos { if seen[name] { // Repo already picked up by dashboard list. continue @@ -1427,7 +1431,12 @@ func repoTickler(repo string) chan bool { func pollGerritAndTickle() { last := map[string]string{} // repo -> last seen hash for { - for repo, hash := range gerritMetaMap() { + gerritRepos, err := gerritMetaMap() + if err != nil { + log.Printf("pollGerritAndTickle: gerritMetaMap failed, skipping: %v", err) + gerritRepos = nil + } + for repo, hash := range gerritRepos { if hash != last[repo] { last[repo] = hash select { @@ -1493,13 +1502,12 @@ func subscribeToMaintnerAndTickle() error { // gerritMetaMap returns the map from repo name (e.g. "go") to its // latest master hash. -// The returned map is nil on any transient error. -func gerritMetaMap() map[string]string { +func gerritMetaMap() (map[string]string, error) { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() meta, err := gerritClient.GetProjects(ctx, "master") if err != nil { - return nil + return nil, fmt.Errorf("gerritClient.GetProjects: %v", err) } m := map[string]string{} for repo, v := range meta { @@ -1507,7 +1515,7 @@ func gerritMetaMap() map[string]string { m[repo] = master } } - return m + return m, nil } func (r *Repo) getLocalRefs() (map[string]string, error) { diff --git a/gerrit/gerrit.go b/gerrit/gerrit.go index 91d2cdfa1a..ec53276cfc 100644 --- a/gerrit/gerrit.go +++ b/gerrit/gerrit.go @@ -27,7 +27,7 @@ import ( // Client is a Gerrit client. type Client struct { - url string // URL prefix, e.g. "https://go-review.googlesource.com/a" (without trailing slash) + url string // URL prefix, e.g. "https://go-review.googlesource.com" (without trailing slash) auth Auth // HTTPClient optionally specifies an HTTP client to use @@ -37,7 +37,7 @@ type Client struct { // NewClient returns a new Gerrit client with the given URL prefix // and authentication mode. -// The url should be just the scheme and hostname. +// The url should be just the scheme and hostname. For example, "https://go-review.googlesource.com". // If auth is nil, a default is used, or requests are made unauthenticated. func NewClient(url string, auth Auth) *Client { if auth == nil { diff --git a/maintner/maintnerd/maintapi/api.go b/maintner/maintnerd/maintapi/api.go index 39b9692817..f5a1538ba6 100644 --- a/maintner/maintnerd/maintapi/api.go +++ b/maintner/maintnerd/maintapi/api.go @@ -126,7 +126,7 @@ var tryCache struct { val *apipb.GoFindTryWorkResponse } -var tryBotGerrit = gerrit.NewClient("https://go-review.googlesource.com/", gerrit.NoAuth) +var tryBotGerrit = gerrit.NewClient("https://go-review.googlesource.com", gerrit.NoAuth) func (s apiService) GoFindTryWork(ctx context.Context, req *apipb.GoFindTryWorkRequest) (*apipb.GoFindTryWorkResponse, error) { tryCache.Lock() diff --git a/maintner/maintnerd/maintnerd.go b/maintner/maintnerd/maintnerd.go index 57f8303b42..6667ec26f4 100644 --- a/maintner/maintnerd/maintnerd.go +++ b/maintner/maintnerd/maintnerd.go @@ -351,7 +351,7 @@ func setGoConfig() { *pubsub = "https://pubsubhelper.golang.org" *watchGithub = strings.Join(goGitHubProjects, ",") - gerrc := gerrit.NewClient("https://go-review.googlesource.com/", gerrit.NoAuth) + gerrc := gerrit.NewClient("https://go-review.googlesource.com", gerrit.NoAuth) projs, err := gerrc.ListProjects(context.Background()) if err != nil { log.Fatalf("error listing Go's gerrit projects: %v", err)