Skip to content

Commit

Permalink
zoekt-mirror-github: handle onlyActive option (#3)
Browse files Browse the repository at this point in the history
This filters out archived GitHub repos

Co-authored-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
  • Loading branch information
tcardonne and tcardonne authored Feb 16, 2022
1 parent 3cac683 commit b13d18d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/zoekt-indexserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions cmd/zoekt-mirror-github/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (f *topicsFlag) Set(value string) error {
type reposFilters struct {
topics []string
excludeTopics []string
onlyActive *bool
}

func main() {
Expand All @@ -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()

Expand Down Expand Up @@ -130,6 +132,7 @@ func main() {
reposFilters := reposFilters{
topics: topics,
excludeTopics: excludeTopics,
onlyActive: onlyActive,
}
var repos []*github.Repository
var err error
Expand Down Expand Up @@ -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{}
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b13d18d

Please sign in to comment.