Skip to content

Commit

Permalink
feat: fetch recently pushed repos for an org
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Jul 16, 2024
1 parent 2949194 commit bee5059
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@ Published: {{humanize .LastRelease.PublishedAt}}
This function requires GitHub authentication with the following API scopes:
`repo:status`, `public_repo`, `read:user`.

### Recent pushes in an organization

```
{{range orgRecentReleases "charmbracelet" 10}}
Name: {{.Name}}
URL: {{.URL}}
Description: {{.Description}}
Stars: {{.Stargazers}}
{{end}}
```

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

> [!TIP]
> Use `{{with repo "charmbracelet .Name"}}` to create a pipeline that grabs additional information about the repo including releases.
### Your published gists

```
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func main() {
funcMap["recentRepos"] = recentRepos
funcMap["recentForks"] = recentForks
funcMap["recentReleases"] = recentReleases
funcMap["orgRecentPushes"] = orgRecentPushes
funcMap["followers"] = recentFollowers
funcMap["recentStars"] = recentStars
funcMap["gists"] = gists
Expand Down
56 changes: 56 additions & 0 deletions repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,62 @@ func recentReleases(count int) []Repo {
return repos
}

/*{
* organization(login: "charmbracelet") {
* login
* repositories(
* first: 5
* privacy: PUBLIC
* orderBy: {field: PUSHED_AT, direction: DESC}
* ) {
* totalCount
* edges {
* cursor
* node {
* nameWithOwner
* pushedAt
* latestRelease {
* tagName
* createdAt
* }
* }
* }
* }
* }
*}
* */
func orgRecentPushes(owner string, count int) []Repo {
var query struct {
Organization struct {
Repositories struct {
Edges []struct {
Node qlRepository
}
} `graphql:"repositories(first: $count, privacy: PUBLIC, orderBy: {field: STARGAZERS, direction: DESC})"`
} `graphql:"organization(login: $owner)"`
}
fmt.Printf("Finding repos with recent pushes in the %s org\n", owner)
var repos []Repo
variables := map[string]interface{}{
"count": githubv4.Int(count),
"owner": githubv4.String(owner),
}
err := gitHubClient.Query(context.Background(), &query, variables)
if err != nil {
panic(err)
}

for _, v := range query.Organization.Repositories.Edges {
// ignore meta-repo
repos = append(repos, repoFromQL(v.Node))
if len(repos) == count {
break
}
}
fmt.Printf("Found %d repos!\n", len(repos))
return repos
}

func repo(owner, name string) Repo {
variables := map[string]interface{}{
"owner": githubv4.String(owner),
Expand Down

0 comments on commit bee5059

Please sign in to comment.