Skip to content

Commit

Permalink
cmd/gitmirror: change Gerrit API URL to include "-review"
Browse files Browse the repository at this point in the history
Using "https://go.googlesource.com" without "-review" as the Gerrit API
URL no longer works. Use "https://go-review.googlesource.com" instead.
This is the canonical Gerrit API URL for the Go project, and it's
already being used in many other places in x/build.

Return and handle errors from gerritMetaMap. Make it so gitmirror treats
an error from gerritMetaMap on startup as fatal, otherwise it would have
started in an incorrect state. While running, skip transient errors from
gerritMetaMap as before, but also log them when they happen.

Remove unneeded trailing slashes from the Gerrit API URLs in packages
maintner/maintnerd and maintner/maintnerd/maintapi for consistency.
This is a no-op as the gerrit client library used to trim them anyway.

Fixes golang/go#32931

Change-Id: Icc20b798946d6317ee89533691f92b1f4d1564f0
Reviewed-on: https://go-review.googlesource.com/c/build/+/184922
Run-TryBot: Dmitri Shuralyov <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Alexander Rakoczy <[email protected]>
  • Loading branch information
dmitshur committed Jul 4, 2019
1 parent a473c25 commit 25c4be9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
22 changes: 15 additions & 7 deletions cmd/gitmirror/gitmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1493,21 +1502,20 @@ 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 {
if master, ok := v.Branches["master"]; ok {
m[repo] = master
}
}
return m
return m, nil
}

func (r *Repo) getLocalRefs() (map[string]string, error) {
Expand Down
4 changes: 2 additions & 2 deletions gerrit/gerrit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion maintner/maintnerd/maintapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion maintner/maintnerd/maintnerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 25c4be9

Please sign in to comment.