Skip to content

Commit 6e1808a

Browse files
committed
repos: flesh out package more, use it in maintnerd
This removes yet another list of all our repos. (Goal is to simplify https://github.com/golang/go/wiki/CreatingSubRepository) Most of the work was in earlier CL 208697. Updates golang/go#36047 Change-Id: I9147b959fe6574e2f809091d08d360051b69402e Reviewed-on: https://go-review.googlesource.com/c/build/+/210461 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Alexander Rakoczy <[email protected]>
1 parent 4cca772 commit 6e1808a

File tree

6 files changed

+133
-75
lines changed

6 files changed

+133
-75
lines changed

app/appengine/dash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ var goDash = &Dashboard{
125125
func init() {
126126
var add []*Package
127127
for _, r := range repos.ByGerritProject {
128-
if r.HideFromDashboard || !strings.HasPrefix(r.ImportPath, "golang.org/x") || r.GoGerritProject == "" {
128+
if !r.ShowOnDashboard() {
129129
continue
130130
}
131131
add = append(add, &Package{

app/appengine/ui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func repoImportPath(rh *apipb.DashRepoHead) string {
245245
return ""
246246
}
247247
ri, ok := repos.ByGerritProject[rh.GerritProject]
248-
if !ok || ri.HideFromDashboard {
248+
if !ok || !ri.ShowOnDashboard() {
249249
return ""
250250
}
251251
return ri.ImportPath

cmd/gitmirror/gitmirror.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,8 @@ func handleRoot(w http.ResponseWriter, r *http.Request) {
188188
// shouldMirrorTo returns the GitHub repository the named repo should be
189189
// mirrored to or "" if it should not be mirrored.
190190
func shouldMirrorTo(name string) (dst string) {
191-
if name == "protobuf" {
192-
return "[email protected]:protocolbuffers/protobuf-go.git"
193-
}
194-
if r, ok := repospkg.ByGerritProject[name]; ok && r.MirroredToGithub {
195-
return "[email protected]:golang/" + name + ".git"
191+
if r, ok := repospkg.ByGerritProject[name]; ok && r.MirrorToGitHub {
192+
return "[email protected]:" + r.GitHubRepo() + ".git"
196193
}
197194
return ""
198195
}

maintner/maintnerd/maintnerd.go

Lines changed: 36 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package main
88

99
import (
10-
"bytes"
1110
"context"
1211
"crypto/tls"
1312
"flag"
@@ -22,20 +21,21 @@ import (
2221
"os"
2322
"path/filepath"
2423
"runtime"
24+
"sort"
2525
"strconv"
2626
"strings"
2727
"time"
2828

2929
"cloud.google.com/go/compute/metadata"
3030
"cloud.google.com/go/storage"
3131
"golang.org/x/build/autocertcache"
32-
"golang.org/x/build/gerrit"
3332
"golang.org/x/build/internal/gitauth"
3433
"golang.org/x/build/maintner"
3534
"golang.org/x/build/maintner/godata"
3635
"golang.org/x/build/maintner/maintnerd/apipb"
3736
"golang.org/x/build/maintner/maintnerd/gcslog"
3837
"golang.org/x/build/maintner/maintnerd/maintapi"
38+
"golang.org/x/build/repos"
3939
"golang.org/x/crypto/acme/autocert"
4040
"golang.org/x/net/http2"
4141
"golang.org/x/time/rate"
@@ -306,46 +306,6 @@ func main() {
306306
log.Fatal(<-errc)
307307
}
308308

309-
// Projects to watch when using the "go" config.
310-
var goGitHubProjects = []string{
311-
"golang/arch",
312-
"golang/benchmarks",
313-
"golang/blog",
314-
"golang/build",
315-
"golang/crypto",
316-
"golang/debug",
317-
"golang/dl",
318-
"golang/example",
319-
"golang/exp",
320-
"golang/gddo",
321-
"golang/go",
322-
"golang/image",
323-
"golang/lint",
324-
"golang/mobile",
325-
"golang/mod",
326-
"golang/net",
327-
"golang/oauth2",
328-
"golang/perf",
329-
"golang/playground",
330-
"golang/proposal",
331-
"golang/review",
332-
"golang/scratch",
333-
"golang/sublime-build",
334-
"golang/sublime-config",
335-
"golang/sync",
336-
"golang/sys",
337-
"golang/talks",
338-
"golang/term",
339-
"golang/text",
340-
"golang/time",
341-
"golang/tools",
342-
"golang/tour",
343-
"golang/vgo",
344-
"golang/website",
345-
"golang/xerrors",
346-
"protocolbuffers/protobuf-go",
347-
}
348-
349309
func setGoConfig() {
350310
if *watchGithub != "" {
351311
log.Fatalf("can't set both --config and --watch-github")
@@ -354,20 +314,42 @@ func setGoConfig() {
354314
log.Fatalf("can't set both --config and --watch-gerrit")
355315
}
356316
*pubsub = "https://pubsubhelper.golang.org"
357-
*watchGithub = strings.Join(goGitHubProjects, ",")
317+
*watchGithub = strings.Join(goGitHubProjects(), ",")
318+
*watchGerrit = strings.Join(goGerritProjects(), ",")
319+
}
358320

359-
gerrc := gerrit.NewClient("https://go-review.googlesource.com", gerrit.NoAuth)
360-
projs, err := gerrc.ListProjects(context.Background())
361-
if err != nil {
362-
log.Fatalf("error listing Go's gerrit projects: %v", err)
363-
}
364-
var buf bytes.Buffer
365-
buf.WriteString("code.googlesource.com/gocloud,code.googlesource.com/google-api-go-client")
366-
for _, pi := range projs {
367-
buf.WriteString(",go.googlesource.com/")
368-
buf.WriteString(pi.ID)
321+
// goGitHubProjects returns the GitHub repos to track in --config=go.
322+
// The strings are of form "<org-or-user>/<repo>".
323+
func goGitHubProjects() []string {
324+
var ret []string
325+
for _, r := range repos.ByGerritProject {
326+
if gr := r.GitHubRepo(); gr != "" {
327+
ret = append(ret, gr)
328+
}
369329
}
370-
*watchGerrit = buf.String()
330+
sort.Strings(ret)
331+
return ret
332+
}
333+
334+
// goGerritProjects returns the Gerrit projects to track in --config=go.
335+
// The strings are of the form "<hostname>/<proj>".
336+
func goGerritProjects() []string {
337+
var ret []string
338+
// TODO: add these to the repos package at some point? Or
339+
// maybe just stop maintaining them in maintner if nothing's
340+
// using them? I think the only thing that uses them is the
341+
// stats tooling, to see where gophers are working. That's
342+
// probably enough reason to keep them in. So just keep hard-coding
343+
// them here for now.
344+
ret = append(ret,
345+
"code.googlesource.com/gocloud",
346+
"code.googlesource.com/google-api-go-client",
347+
)
348+
for p := range repos.ByGerritProject {
349+
ret = append(ret, "go.googlesource.com/"+p)
350+
}
351+
sort.Strings(ret)
352+
return ret
371353
}
372354

373355
func setGodataConfig() {

repos/repos.go

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,31 @@ package repos
88
import "fmt"
99

1010
type Repo struct {
11-
// GoGerritProject, if non-empty, is its Gerrit project name,
12-
// such as "go", "net", or "sys".
11+
// GoGerritProject, if non-empty, is the repo's Gerrit project
12+
// name, such as "go", "net", or "sys".
1313
GoGerritProject string
1414

1515
// ImportPath is the repo's import path.
1616
// It is empty for the main Go repo.
1717
ImportPath string
1818

19-
MirroredToGithub bool
19+
// MirrorToGitHub controls whether this repo is mirrored
20+
// from Gerrit to GitHub. If true, GoGerritProject and
21+
// gitHubRepo must both be defined.
22+
MirrorToGitHub bool
2023

21-
// HideFromDashboard, if true, makes the repo not appear at build.golang.org.
22-
HideFromDashboard bool
24+
// showOnDashboard is whether to show the repo on the bottom
25+
// of build.golang.org in the repo overview section.
26+
showOnDashboard bool
2327

2428
// CoordinatorCanBuild reports whether this a repo that the
2529
// build coordinator knows how to build.
2630
CoordinatorCanBuild bool
31+
32+
// gitHubRepo is the "org/repo" of where this repo exists on
33+
// GitHub. If MirrorToGitHub is true, this is the
34+
// destination.
35+
gitHubRepo string
2736
}
2837

2938
// ByGerritProject maps from a Gerrit project name ("go", "net", etc)
@@ -35,13 +44,14 @@ var ByGerritProject = map[string]*Repo{ /* initialized below */ }
3544
var ByImportPath = map[string]*Repo{ /* initialized below */ }
3645

3746
func init() {
38-
add(&Repo{GoGerritProject: "go", MirroredToGithub: true, CoordinatorCanBuild: true})
39-
add(&Repo{GoGerritProject: "dl", MirroredToGithub: true, ImportPath: "golang.org/dl", HideFromDashboard: true, CoordinatorCanBuild: true})
40-
add(&Repo{GoGerritProject: "protobuf", MirroredToGithub: true, ImportPath: "github.com/google/protobuf", HideFromDashboard: true})
41-
add(&Repo{GoGerritProject: "gddo", MirroredToGithub: true, ImportPath: "github.com/golang/gddo", HideFromDashboard: true})
42-
add(&Repo{GoGerritProject: "gofrontend", MirroredToGithub: true, HideFromDashboard: true})
43-
add(&Repo{GoGerritProject: "gollvm", MirroredToGithub: false, HideFromDashboard: true})
44-
add(&Repo{GoGerritProject: "grpc-review", MirroredToGithub: false, HideFromDashboard: true})
47+
addMirrored("go", coordinatorCanBuild, noDash)
48+
addMirrored("dl", importPath("golang.org/dl"), coordinatorCanBuild)
49+
addMirrored("gddo", importPath("github.com/golang/gddo"))
50+
addMirrored("gofrontend")
51+
addMirrored("proposal")
52+
addMirrored("sublime-build")
53+
addMirrored("sublime-config")
54+
4555
x("arch")
4656
x("benchmarks")
4757
x("blog")
@@ -71,21 +81,50 @@ func init() {
7181
x("vgo", noDash)
7282
x("website")
7383
x("xerrors", noDash)
84+
85+
add(&Repo{GoGerritProject: "gollvm"})
86+
add(&Repo{GoGerritProject: "grpc-review"})
87+
88+
add(&Repo{
89+
GoGerritProject: "protobuf",
90+
MirrorToGitHub: true,
91+
ImportPath: "github.com/google/protobuf",
92+
gitHubRepo: "protocolbuffers/protobuf-go",
93+
})
7494
}
7595

7696
type modifyRepo func(*Repo)
7797

7898
// noDash is an option to the x func that marks the repo as hidden on
7999
// the https://build.golang.org/ dashboard.
80-
func noDash(r *Repo) { r.HideFromDashboard = true }
100+
func noDash(r *Repo) { r.showOnDashboard = false }
101+
102+
func coordinatorCanBuild(r *Repo) { r.CoordinatorCanBuild = true }
103+
104+
func importPath(v string) modifyRepo { return func(r *Repo) { r.ImportPath = v } }
105+
106+
// addMirrored adds a repo that's on Gerrit and mirrored to GitHub.
107+
func addMirrored(proj string, opts ...modifyRepo) {
108+
repo := &Repo{
109+
GoGerritProject: proj,
110+
MirrorToGitHub: true,
111+
gitHubRepo: "golang/" + proj,
112+
}
113+
for _, o := range opts {
114+
o(repo)
115+
}
116+
add(repo)
117+
}
81118

82119
// x adds a golang.org/x repo.
83120
func x(proj string, opts ...modifyRepo) {
84121
repo := &Repo{
85122
GoGerritProject: proj,
86-
MirroredToGithub: true,
123+
MirrorToGitHub: true,
87124
CoordinatorCanBuild: true,
88125
ImportPath: "golang.org/x/" + proj,
126+
gitHubRepo: "golang/" + proj,
127+
showOnDashboard: true,
89128
}
90129
for _, o := range opts {
91130
o(repo)
@@ -94,6 +133,23 @@ func x(proj string, opts ...modifyRepo) {
94133
}
95134

96135
func add(r *Repo) {
136+
if r.MirrorToGitHub {
137+
if r.gitHubRepo == "" {
138+
panic(fmt.Sprintf("project %+v has MirrorToGitHub but no gitHubRepo", r))
139+
}
140+
if r.GoGerritProject == "" {
141+
panic(fmt.Sprintf("project %+v has MirrorToGitHub but no GoGerritProject", r))
142+
}
143+
}
144+
if r.showOnDashboard {
145+
if !r.CoordinatorCanBuild {
146+
panic(fmt.Sprintf("project %+v is showOnDashboard but not marked buildable by coordinator", r))
147+
}
148+
if r.GoGerritProject == "" {
149+
panic(fmt.Sprintf("project %+v is showOnDashboard but has no Gerrit project", r))
150+
}
151+
}
152+
97153
if p := r.GoGerritProject; p != "" {
98154
if _, dup := ByGerritProject[p]; dup {
99155
panic(fmt.Sprintf("duplicate Gerrit project %q in %+v", p, r))
@@ -107,3 +163,14 @@ func add(r *Repo) {
107163
ByImportPath[p] = r
108164
}
109165
}
166+
167+
// ShowOnDashboard reports whether this repo should show up on build.golang.org
168+
// in the list of repos at bottom.
169+
//
170+
// When this returns true, r.GoGerritProject is guaranteed to be non-empty.
171+
func (r *Repo) ShowOnDashboard() bool { return r.showOnDashboard }
172+
173+
// GitHubRepo returns the "<org>/<repo>" that this repo either lives
174+
// at or is mirrored to. It returns the empty string if this repo has no
175+
// GitHub presence.
176+
func (r *Repo) GitHubRepo() string { return r.gitHubRepo }

repos/repos_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package repos
6+
7+
import "testing"
8+
9+
func TestInitDoesNotPanic(t *testing.T) {
10+
// Verify that repos.go's init funcs don't panic when
11+
// validating the repos.
12+
}

0 commit comments

Comments
 (0)