Skip to content

Commit

Permalink
fix: do not show private repos in starlist (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 authored Jan 31, 2023
1 parent cecd873 commit 438ece9
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions stars.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,39 @@ var recentStarsQuery struct {
StarredAt githubv4.DateTime
Node qlRepository
}
} `graphql:"starredRepositories(first: $count, orderBy: {field: STARRED_AT, direction: DESC})"`
} `graphql:"starredRepositories(first: $count, after:$after, orderBy: {field: STARRED_AT, direction: DESC})"`
} `graphql:"user(login:$username)"`
}

func recentStars(count int) []Star {
var starredRepos []Star
variables := map[string]interface{}{
"username": githubv4.String(username),
"count": githubv4.Int(count),
}
err := gitHubClient.Query(context.Background(), &recentStarsQuery, variables)
if err != nil {
panic(err)
}
var after *githubv4.String

outer:
for {
variables := map[string]interface{}{
"username": githubv4.String(username),
"count": githubv4.Int(count),
"after": after,
}
err := gitHubClient.Query(context.Background(), &recentStarsQuery, variables)
if err != nil {
panic(err)
}

for _, v := range recentStarsQuery.User.Stars.Edges {
starredRepos = append(starredRepos, Star{
StarredAt: v.StarredAt.Time,
Repo: repoFromQL(v.Node),
})
for _, v := range recentStarsQuery.User.Stars.Edges {
if v.Node.IsPrivate {
continue
}
starredRepos = append(starredRepos, Star{
StarredAt: v.StarredAt.Time,
Repo: repoFromQL(v.Node),
})
if len(starredRepos) >= count {
break outer
}
after = githubv4.NewString(v.Cursor)
}
}

return starredRepos
Expand Down

0 comments on commit 438ece9

Please sign in to comment.