From f44f1442a8be028a76564c87f24520575db67ad3 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 11 Jul 2018 23:43:51 +0200 Subject: [PATCH] Allow filtering repos by topic Signed-off-by: Knut Ahlers --- main.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/main.go b/main.go index 3f76d54..a1034d4 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ var ( NameRegex string `flag:"name-regex" default:".*" description:"Regex to match the name against"` Output string `flag:"out,o" default:"-" description:"File to write to (- = stdout)"` Template string `flag:"template" default:"" description:"Template file to use for rendering" validate:"nonzero"` + TopicFilter []string `flag:"topic,t" default:"" description:"Filter by topic (Format: 'topic' to include, '-topic' to exclude)"` VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"` }{} @@ -77,6 +78,10 @@ func main() { continue } + if !matchTopicFilter(repo) { + continue + } + skip := false for _, f := range cfg.Filters { @@ -165,6 +170,25 @@ func fetchRepos() ([]*github.Repository, error) { return repos, nil } +func matchTopicFilter(repo *github.Repository) bool { + for _, topic := range cfg.TopicFilter { + if topic == "" { + continue + } + + negate := topic[0] == '-' + if negate { + topic = topic[1:len(topic)] + } + + if str.StringInSlice(topic, repo.Topics) != negate { + return true + } + } + + return false +} + func render(repo *github.Repository) error { var outFile io.Writer if cfg.Output == "-" {