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:
parent
58d97b741f
commit
f44f1442a8
1 changed files with 24 additions and 0 deletions
24
main.go
24
main.go
|
@ -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 == "-" {
|
||||||
|
|
Loading…
Reference in a new issue