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:
parent
a8b4e64d76
commit
89a4b6aafa
2 changed files with 17 additions and 0 deletions
16
filters.go
16
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)
|
||||
|
|
1
main.go
1
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)"`
|
||||
|
|
Loading…
Reference in a new issue