1
0
Fork 0
mirror of https://github.com/Luzifer/repo-template.git synced 2024-12-22 20:21:19 +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"`
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 == "-" {