Skip to content

Instantly share code, notes, and snippets.

@ibakshay
Last active April 6, 2024 17:53
Show Gist options
  • Save ibakshay/ef354a1ac0b5ff3e64395cc769804fb3 to your computer and use it in GitHub Desktop.
Save ibakshay/ef354a1ac0b5ff3e64395cc769804fb3 to your computer and use it in GitHub Desktop.
GitHub Go Client for listing repositories in an org with pagination
package main
import (
"context"
"fmt"
"github.com/google/go-github/v61/github"
)
func main() {
// https://github.com/google/go-github/tree/master
ghClient := github.NewClient(nil).WithAuthToken("GITHUB_PAT_TOKEN")
opt := &github.RepositoryListByOrgOptions{
ListOptions: github.ListOptions{PerPage: 10},
}
var allRepos []*github.Repository
for {
repos, resp, err := ghClient.Repositories.ListByOrg(context.Background(), "sapcc", opt)
if err != nil {
fmt.Println(err)
return
}
allRepos = append(allRepos, repos...)
if resp.NextPage == 0 {
break
}
opt.Page = resp.NextPage
}
for k, repo := range allRepos {
fmt.Println(k)
fmt.Println(repo.GetName())
fmt.Println(repo.License.GetName())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment