diff --git a/filters.go b/filters.go index d8a2a12..e14cc96 100644 --- a/filters.go +++ b/filters.go @@ -16,6 +16,7 @@ var filters = map[string]filterFunc{ "archived": filterArchived, "dockerfile": filterDockerfile, "fork": filterFork, + "has-file": filterHasFile, "make-jenkins": filterMakeJenkins, "public": filterPublic, } @@ -39,6 +40,21 @@ func filterDockerfile(repo *github.Repository) bool { func filterFork(repo *github.Repository) bool { return repo.Fork != nil && *repo.Fork } +func filterHasFile(repo *github.Repository) bool { + ctx := context.Background() + _, _, resp, err := client.Repositories.GetContents(ctx, *repo.Owner.Login, *repo.Name, cfg.FilterHasFile, nil) + if err != nil { + if resp.StatusCode == 404 { + return false + } + + log.WithError(err).Error("Error while looking for file") + return false + } + + return true +} + func filterMakeJenkins(repo *github.Repository) bool { ctx := context.Background() fc, _, resp, err := client.Repositories.GetContents(ctx, *repo.Owner.Login, *repo.Name, "Makefile", nil) diff --git a/main.go b/main.go index d66d990..50b5417 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ var ( cfg = struct { Blacklist []string `flag:"blacklist,b" default:"" description:"Repos to ignore even when matched through filters"` ExpandMatches bool `flag:"expand-matches" default:"false" description:"Replace matched repos with their full version"` + FilterHasFile string `flag:"filter-has-file" default:"" description:"Input for 'has-file' filter: Repo needs to contain this file"` Filters []string `flag:"filter,f" default:"" description:"Filters to match the repos against"` GithubToken string `flag:"token" default:"" env:"GITHUB_TOKEN" description:"Token to access Github API"` LogLevel string `flag:"log-level" default:"info" description:"Log level for output (debug, info, warn, error, fatal)"`