cmd/fetchlogs: fetch repo data using the 'repo' query param
The repo flag for fetchlogs is not currently that useful because it
queries the main Go dashboard data, which only has a few commits for
each subrepo. This was probably because the data at
https://build.golang.org/?repo=<import path>&mode=json
was incorrect due to golang/go#35515.
With golang.org/cl/232897, this data should be corrected. Update
fetchlogs to now query data from the subrepo dashboard.
Change-Id: I352662abf7da6abb7bc23888b11e03927f567cab
Reviewed-on: https://go-review.googlesource.com/c/build/+/232898
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
diff --git a/cmd/fetchlogs/fetchlogs.go b/cmd/fetchlogs/fetchlogs.go
index b8c636b..8191383 100644
--- a/cmd/fetchlogs/fetchlogs.go
+++ b/cmd/fetchlogs/fetchlogs.go
@@ -33,21 +33,24 @@
"io"
"log"
"net/http"
+ "net/url"
"os"
"path/filepath"
"sync"
"time"
+ "golang.org/x/build/repos"
"golang.org/x/build/types"
)
var defaultDir = filepath.Join(xdgCacheDir(), "fetchlogs")
var (
- flagN = flag.Int("n", 300, "limit to most recent `N` commits")
- flagPar = flag.Int("j", 5, "number of concurrent download `jobs`")
- flagDir = flag.String("dir", defaultDir, "`directory` to save logs to")
- flagRepo = flag.String("repo", "go", `repo to fetch logs for`)
+ flagN = flag.Int("n", 300, "limit to most recent `N` commits")
+ flagPar = flag.Int("j", 5, "number of concurrent download `jobs`")
+ flagDir = flag.String("dir", defaultDir, "`directory` to save logs to")
+ flagRepo = flag.String("repo", "go", `repo to fetch logs for`)
+ flagDashboard = flag.String("dashboard", "https://build.golang.org", `the dashboard root url`)
)
func main() {
@@ -82,8 +85,15 @@
// Fetch dashboard pages.
haveCommits := 0
for page := 0; haveCommits < *flagN; page++ {
- url := fmt.Sprintf("https://build.golang.org/?mode=json&page=%d", page)
- index, err := fetcher.get(url)
+ dashURL := fmt.Sprintf("%s/?mode=json&page=%d", *flagDashboard, page)
+ if *flagRepo != "go" {
+ repo := repos.ByGerritProject[*flagRepo]
+ if repo == nil {
+ log.Fatalf("unknown repo %s", *flagRepo)
+ }
+ dashURL += "&repo=" + url.QueryEscape(repo.ImportPath)
+ }
+ index, err := fetcher.get(dashURL)
if err != nil {
log.Fatal(err)
}