1
0
Fork 0
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:
Knut Ahlers 2018-07-12 00:05:59 +02:00
parent 3dd8c37a46
commit 3505c81287
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

56
main.go
View file

@ -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 == "" {