Skip to content

Commit

Permalink
Adding label support
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonEgger committed Oct 2, 2020
1 parent 45a6431 commit 6cc599a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls=
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
Expand Down
27 changes: 25 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main
import (
"context"
"os"
"strings"

"golang.org/x/oauth2"

Expand All @@ -31,6 +32,7 @@ var (
githubOrg = kingpin.Flag("gh-org", "github org to fetch repos of").Short('o').String()
topic = kingpin.Flag("topic", "topic to add to repos").Default("hacktoberfest").String()
remove = kingpin.Flag("remove", "Remove hacktoberfest topic from all repos").Short('r').Default("false").Bool()
labels = kingpin.Flag("labels", "Add spam, invalid, and hacktoberfest-accepted labels to repo").Short('l').Default("true").Bool()
)

func main() {
Expand All @@ -49,7 +51,7 @@ func main() {
}

if *githubOrg == "" && *githubUser == "" {
log.Fatalf("Niether githubOrg or githubUser was set.")
log.Fatalf("Neither githubOrg or githubUser was set.")
} else if *githubOrg != "" && *githubUser != "" {
log.Fatalf("Both githubOrg and githubUser cannot be set")
}
Expand Down Expand Up @@ -100,7 +102,28 @@ func main() {
_, _, err := client.Repositories.ReplaceAllTopics(ctx, owner, *repo.Name, topics)
log.WithField("repo", *repo.Name).WithField("topic", *topic).Infof("%s topic", operation)
if err != nil {
log.WithError(err).Fatalf("issue adding hacktoberfest label")
log.WithError(err).Fatalf("issue adding hacktoberfest topic to repo")
}

labelColors := map[string]string{
"hacktoberfest-accepted": "9c4668",
"invalid": "ca0b00",
"spam": "b33a3a",
}
if *labels == true {

for label, color := range labelColors {
_, _, err := client.Issues.CreateLabel(ctx, owner, *repo.Name, &github.Label{Name: github.String(label), Color: github.String(color)})
if err != nil {
if strings.Contains(err.Error(), "already_exists") {
continue
} else {
log.WithError(err).Fatalf("issue adding hacktoberfest label to repo")
}
} else {
log.WithField("repo", *repo.Name).WithField("label", label).Info("adding labels")
}
}
}
}

Expand Down

0 comments on commit 6cc599a

Please sign in to comment.