1
0
Fork 0
mirror of https://github.com/Luzifer/repo-template.git synced 2024-12-23 04:31:20 +00:00

Allow filtering repos by topic

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-07-11 23:43:51 +02:00
parent 58d97b741f
commit f44f1442a8
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

24
main.go
View file

@ -29,6 +29,7 @@ var (
NameRegex string `flag:"name-regex" default:".*" description:"Regex to match the name against"` 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)"` 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"` 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"` VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"`
}{} }{}
@ -77,6 +78,10 @@ func main() {
continue continue
} }
if !matchTopicFilter(repo) {
continue
}
skip := false skip := false
for _, f := range cfg.Filters { for _, f := range cfg.Filters {
@ -165,6 +170,25 @@ func fetchRepos() ([]*github.Repository, error) {
return repos, nil 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 { func render(repo *github.Repository) error {
var outFile io.Writer var outFile io.Writer
if cfg.Output == "-" { if cfg.Output == "-" {