From 3505c81287da4032a2f829bcb2961eb8e3cb335b Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 12 Jul 2018 00:05:59 +0200 Subject: [PATCH] Refactor: Extract filters to function Signed-off-by: Knut Ahlers --- main.go | 56 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/main.go b/main.go index a1034d4..2fc5a8c 100644 --- a/main.go +++ b/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 == "" {