Skip to content

Commit

Permalink
feat: support users and organizations for popular repos query
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Jul 16, 2024
1 parent 793409f commit c9ad3bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ This function requires GitHub authentication with the following API scopes:
### Repositories with the most stars

```
{{range orgPopularRepos "charmbracelet" 10}}
{{range popularRepos "charmbracelet" 10}}
Name: {{.Name}}
NameWithOwner: {{.NameWithOwner}}
Description: {{.Description}}
Expand All @@ -133,7 +133,7 @@ Stars: {{.Stargazers}}
```

This function requires GitHub authentication with the following API scopes:
`read:org`, `public_repo`
`read:org`, `public_repo`, `read:user`

> [!TIP]
> Use `{{with repo "charmbracelet .Name"}}` to create a pipeline that grabs additional information about the repo including releases.
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
funcMap["recentForks"] = recentForks
funcMap["recentReleases"] = recentReleases
funcMap["recentRepos"] = recentRepos
funcMap["orgPopularRepos"] = orgPopularRepos
funcMap["popularRepos"] = popularRepos
funcMap["followers"] = recentFollowers
funcMap["recentStars"] = recentStars
funcMap["gists"] = gists
Expand Down
19 changes: 10 additions & 9 deletions repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,34 @@ var recentReleasesQuery struct {
Order by stars
{
organization(login: "charmbracelet") {
repositoryOwner(login: "charmbracelet") {
id
login
repositories(
first: 3
first: 5
privacy: PUBLIC
orderBy: {field: STARGAZERS, direction: DESC}
) {
totalCount
edges {
cursor
node {
nameWithOwner
name
description
url
}
}
}
}
}
*/
func orgPopularRepos(owner string, count int) []Repo {
func popularRepos(owner string, count int) []Repo {
var query struct {
Organization struct {
Owner struct {
Repositories struct {
Edges []struct {
Node qlRepository
}
} `graphql:"repositories(first: $count, privacy: PUBLIC, orderBy: {field: STARGAZERS, direction: DESC})"`
} `graphql:"organization(login: $owner)"`
} `graphql:"repositoryOwner(login: $owner)"`
}

fmt.Println("Finding popular repos...")
Expand All @@ -114,7 +115,7 @@ func orgPopularRepos(owner string, count int) []Repo {
panic(err)
}

for _, v := range query.Organization.Repositories.Edges {
for _, v := range query.Owner.Repositories.Edges {
// ignore meta-repo
if string(v.Node.NameWithOwner) == fmt.Sprintf("%s/%s", owner, username) {
continue
Expand Down

0 comments on commit c9ad3bb

Please sign in to comment.