Last active
April 6, 2024 17:53
-
-
Save ibakshay/ef354a1ac0b5ff3e64395cc769804fb3 to your computer and use it in GitHub Desktop.
GitHub Go Client for listing repositories in an org with pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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