From b13d18dc6a7f39d76167415b1763721c46149934 Mon Sep 17 00:00:00 2001 From: Thomas Cardonne Date: Wed, 16 Feb 2022 13:30:05 +0100 Subject: [PATCH] zoekt-mirror-github: handle onlyActive option (#3) This filters out archived GitHub repos Co-authored-by: Thomas Cardonne --- cmd/zoekt-indexserver/config.go | 3 +++ cmd/zoekt-mirror-github/main.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/cmd/zoekt-indexserver/config.go b/cmd/zoekt-indexserver/config.go index 695491b2b..75f216e84 100644 --- a/cmd/zoekt-indexserver/config.go +++ b/cmd/zoekt-indexserver/config.go @@ -189,6 +189,9 @@ func executeMirror(cfg []ConfigEntry, repoDir string, pendingRepos chan<- string for _, topic := range c.ExcludeTopics { cmd.Args = append(cmd.Args, "-exclude_topic", topic) } + if c.OnlyActive { + cmd.Args = append(cmd.Args, "-only-active") + } } else if c.GitilesURL != "" { cmd = exec.Command("zoekt-mirror-gitiles", "-dest", repoDir, "-name", c.Name) diff --git a/cmd/zoekt-mirror-github/main.go b/cmd/zoekt-mirror-github/main.go index 1b0d8f848..c28bec286 100644 --- a/cmd/zoekt-mirror-github/main.go +++ b/cmd/zoekt-mirror-github/main.go @@ -50,6 +50,7 @@ func (f *topicsFlag) Set(value string) error { type reposFilters struct { topics []string excludeTopics []string + onlyActive *bool } func main() { @@ -68,6 +69,7 @@ func main() { flag.Var(&topics, "topic", "only clone repos whose have one of given topics. You can add multiple topics by setting this more than once.") excludeTopics := topicsFlag{} flag.Var(&excludeTopics, "exclude_topic", "don't clone repos whose have one of given topics. You can add multiple topics by setting this more than once.") + onlyActive := flag.Bool("only-active", false, "mirror only active projects") flag.Parse() @@ -130,6 +132,7 @@ func main() { reposFilters := reposFilters{ topics: topics, excludeTopics: excludeTopics, + onlyActive: onlyActive, } var repos []*github.Repository var err error @@ -233,6 +236,15 @@ func filterByTopic(repos []*github.Repository, include []string, exclude []strin return } +func filterByState(repos []*github.Repository, onlyActive *bool) (filteredRepos []*github.Repository) { + for _, repo := range repos { + if !*onlyActive || !*repo.Archived { + filteredRepos = append(filteredRepos, repo) + } + } + return +} + func getOrgRepos(client *github.Client, org string, reposFilters reposFilters) ([]*github.Repository, error) { var allRepos []*github.Repository opt := &github.RepositoryListByOrgOptions{} @@ -247,6 +259,7 @@ func getOrgRepos(client *github.Client, org string, reposFilters reposFilters) ( opt.Page = resp.NextPage repos = filterByTopic(repos, reposFilters.topics, reposFilters.excludeTopics) + repos = filterByState(repos, reposFilters.onlyActive) allRepos = append(allRepos, repos...) if resp.NextPage == 0 { break @@ -269,6 +282,7 @@ func getUserRepos(client *github.Client, user string, reposFilters reposFilters) opt.Page = resp.NextPage repos = filterByTopic(repos, reposFilters.topics, reposFilters.excludeTopics) + repos = filterByState(repos, reposFilters.onlyActive) allRepos = append(allRepos, repos...) if resp.NextPage == 0 { break