mirror of
https://github.com/Luzifer/repo-template.git
synced 2024-12-22 20:21:19 +00:00
Refactor: Extract filters to function
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
3dd8c37a46
commit
3505c81287
1 changed files with 29 additions and 27 deletions
56
main.go
56
main.go
|
@ -82,33 +82,7 @@ func main() {
|
|||
continue
|
||||
}
|
||||
|
||||
skip := false
|
||||
|
||||
for _, f := range cfg.Filters {
|
||||
if f == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
var (
|
||||
inverse = false
|
||||
filter = f
|
||||
)
|
||||
|
||||
if strings.HasPrefix(filter, "no-") {
|
||||
inverse = true
|
||||
filter = filter[3:]
|
||||
}
|
||||
|
||||
if filters[filter](repo) == inverse {
|
||||
log.WithFields(log.Fields{
|
||||
"filter": filter,
|
||||
"repo": *repo.FullName,
|
||||
}).Debug("Repo was filtered")
|
||||
skip = true
|
||||
}
|
||||
}
|
||||
|
||||
if skip {
|
||||
if !matchFilters(repo) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -170,6 +144,34 @@ func fetchRepos() ([]*github.Repository, error) {
|
|||
return repos, nil
|
||||
}
|
||||
|
||||
func matchFilters(repo *github.Repository) bool {
|
||||
for _, f := range cfg.Filters {
|
||||
if f == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
var (
|
||||
inverse = false
|
||||
filter = f
|
||||
)
|
||||
|
||||
if strings.HasPrefix(filter, "no-") {
|
||||
inverse = true
|
||||
filter = filter[3:]
|
||||
}
|
||||
|
||||
if filters[filter](repo) == inverse {
|
||||
log.WithFields(log.Fields{
|
||||
"filter": filter,
|
||||
"repo": *repo.FullName,
|
||||
}).Debug("Repo was filtered")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func matchTopicFilter(repo *github.Repository) bool {
|
||||
for _, topic := range cfg.TopicFilter {
|
||||
if topic == "" {
|
||||
|
|
Loading…
Reference in a new issue