1
0
Fork 0
mirror of https://github.com/Luzifer/repo-template.git synced 2024-12-22 20:21:19 +00:00

Add generic has-file filter

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-04-11 13:50:32 +02:00
parent a8b4e64d76
commit 89a4b6aafa
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
2 changed files with 17 additions and 0 deletions

View file

@ -16,6 +16,7 @@ var filters = map[string]filterFunc{
"archived": filterArchived, "archived": filterArchived,
"dockerfile": filterDockerfile, "dockerfile": filterDockerfile,
"fork": filterFork, "fork": filterFork,
"has-file": filterHasFile,
"make-jenkins": filterMakeJenkins, "make-jenkins": filterMakeJenkins,
"public": filterPublic, "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 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 { func filterMakeJenkins(repo *github.Repository) bool {
ctx := context.Background() ctx := context.Background()
fc, _, resp, err := client.Repositories.GetContents(ctx, *repo.Owner.Login, *repo.Name, "Makefile", nil) fc, _, resp, err := client.Repositories.GetContents(ctx, *repo.Owner.Login, *repo.Name, "Makefile", nil)

View file

@ -23,6 +23,7 @@ var (
cfg = struct { cfg = struct {
Blacklist []string `flag:"blacklist,b" default:"" description:"Repos to ignore even when matched through filters"` 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"` 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"` 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"` 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)"` LogLevel string `flag:"log-level" default:"info" description:"Log level for output (debug, info, warn, error, fatal)"`