Skip to content

Commit

Permalink
Add ignore option
Browse files Browse the repository at this point in the history
  • Loading branch information
rverst committed Jul 7, 2021
1 parent 3aa1b34 commit 6f025c6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ RUN mkdir /data
ENV OUTPUT_FILE "/data/README.md"
ENV GITHUB_USER ""
ENV ACCESS_TOKEN ""
ENV IGNORE_REPOS ""

ENTRYPOINT ["stargazer"]
4 changes: 4 additions & 0 deletions github.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func fetchStars(user string, token string) (stars map[string][]Star, total int,
if e.Node.IsPrivate {
continue
}
if isIgnored(e.Node.NameWithOwner) {
continue
}

total++
lng := "Unknown"
if len(e.Node.Languages.Edges) > 0 {
Expand Down
35 changes: 34 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ const (
envUser = "GITHUB_USER"
envToken = "ACCESS_TOKEN"
envOutput = "OUTPUT_FILE"
envIgnore = "IGNORE_REPOS"
)

var (
version = ""
commit = "none"
date = "unknown"
builtBy = "unknown"
ignored []string
)

func main() {
Expand All @@ -40,6 +42,7 @@ func main() {
flaggy.String(&output, "o", "output-file", "the file to create (default:"+defaultOutput+" )")
flaggy.String(&user, "u", "github-user", "github user name")
flaggy.String(&token, "", "access-token", "github access token")
flaggy.StringSlice(&ignored, "i", "ignore", "repositories to ignore (flag can be specified multiple times)")
flaggy.Bool(&test, "t", "test", "just put out some test data")

flaggy.Parse()
Expand Down Expand Up @@ -71,6 +74,20 @@ func main() {
token = v
}
}
if len(ignored) == 0 {
ig := os.Getenv(envIgnore)
if v, ok := env[envIgnore]; ok {
ig = v
}
sp := strings.Split(ig, ",")
ignored = make([]string, 0)
for _, s := range sp {
s := strings.Trim(s, " ")
if s != "" {
ignored = append(ignored, s)
}
}
}

var stars map[string][]Star
var total int
Expand All @@ -89,11 +106,23 @@ func main() {
}
}

func isIgnored(name string) bool {
if len(ignored) == 0 {
return false
}
for _, i := range ignored {
if strings.ToLower(i) == strings.ToLower(name) {
return true
}
}
return false
}

func testStars() (stars map[string][]Star, total int) {

stars = make(map[string][]Star)
stars["go"] = make([]Star, 1)
stars["go"][0] = Star{
s := Star{
Url: "https://github.com/rverst/stargazer",
Name: "stargazer",
NameWithOwner: "rverst/stargazer",
Expand All @@ -103,6 +132,10 @@ func testStars() (stars map[string][]Star, total int) {
StarredAt: time.Now(),
}

if !isIgnored(s.NameWithOwner) {
stars["go"][0] = s
}

total = 1
return
}
Expand Down

0 comments on commit 6f025c6

Please sign in to comment.