Skip to content

Commit

Permalink
zoekt-mirror-gerrit: allow to index only active projects (#2)
Browse files Browse the repository at this point in the history
Add -only-active option in configuration to ignore READ_ONLY Gerrit projects

Co-authored-by: denis.fortin <denis.fortin@adevinta.com>
  • Loading branch information
df11 and denis.fortin authored Dec 6, 2021
1 parent 4841e59 commit eaa0014
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cmd/zoekt-indexserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type ConfigEntry struct {
GerritApiURL string
Topics []string
ExcludeTopics []string
OnlyActive bool
}

func randomize(entries []ConfigEntry) []ConfigEntry {
Expand Down Expand Up @@ -251,6 +252,9 @@ func executeMirror(cfg []ConfigEntry, repoDir string, pendingRepos chan<- string
if c.Exclude != "" {
cmd.Args = append(cmd.Args, "-exclude", c.Exclude)
}
if c.OnlyActive {
cmd.Args = append(cmd.Args, "-only-active")
}
cmd.Args = append(cmd.Args, c.GerritApiURL)
}

Expand Down
12 changes: 8 additions & 4 deletions cmd/zoekt-mirror-gerrit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func main() {
excludePattern := flag.String("exclude", "", "don't mirror repos whose names match this regexp.")
deleteRepos := flag.Bool("delete", false, "delete missing repos")
httpCrendentialsPath := flag.String("http-credentials", "", "path to a file containing http credentials stored like 'user:password'.")
onlyActive := flag.Bool("only-active", false, "mirror only active projects")
flag.Parse()

if len(flag.Args()) < 1 {
Expand Down Expand Up @@ -129,20 +130,23 @@ func main() {
}

projects := make(map[string]gerrit.ProjectInfo)
skip := "0"
skip := 0
for {
page, _, err := client.Projects.ListProjects(&gerrit.ProjectOptions{Skip: skip})
page, _, err := client.Projects.ListProjects(&gerrit.ProjectOptions{Skip: strconv.Itoa(skip)})
if err != nil {
log.Fatalf("ListProjects: %v", err)
}

if len(*page) == 0 {
break
}

for k, v := range *page {
projects[k] = v
if *onlyActive == false || "ACTIVE" == v.State {
projects[k] = v
}
skip = skip + 1
}
skip = strconv.Itoa(len(projects))
}

for k, v := range projects {
Expand Down

0 comments on commit eaa0014

Please sign in to comment.