aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2021-02-25 18:53:32 +0100
committerMartin Polden <mpolden@mpolden.no>2021-02-25 18:54:08 +0100
commit3896707f510821480e306aa7b3906a48c06121ed (patch)
tree19ae8c07c1ddcc4362a915469b127d77456dda67
parent2ca5d50afea2ea87efd6260c7c9942dc0004860d (diff)
git: List all repositories
-rw-r--r--git.go22
-rw-r--r--main.go2
2 files changed, 21 insertions, 3 deletions
diff --git a/git.go b/git.go
index 44708b2..bf35017 100644
--- a/git.go
+++ b/git.go
@@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "strconv"
)
type git struct {
@@ -23,8 +24,10 @@ type repository struct {
Archived bool `json:"archived"`
}
-func listRepositories(user string) ([]repository, error) {
- res, err := http.Get("https://api.github.com/users/" + user + "/repos")
+func listRepositories(user string, page int) ([]repository, error) {
+ // https://docs.github.com/en/rest/reference/repos#list-repositories-for-a-user
+ url := "https://api.github.com/users/" + user + "/repos?per_page=100&page=" + strconv.Itoa(page)
+ res, err := http.Get(url)
if err != nil {
return nil, err
}
@@ -37,6 +40,21 @@ func listRepositories(user string) ([]repository, error) {
return repos, nil
}
+func listAllRepositories(user string) ([]repository, error) {
+ var repos []repository
+ for page := 1; ; page++ {
+ rs, err := listRepositories(user, page)
+ if err != nil {
+ return nil, err
+ }
+ if len(rs) == 0 {
+ break
+ }
+ repos = append(repos, rs...)
+ }
+ return repos, nil
+}
+
func gitCommand(inheritIO bool) (*git, error) {
p, err := exec.LookPath("git")
if err != nil {
diff --git a/main.go b/main.go
index e0c22a0..f9ce2e2 100644
--- a/main.go
+++ b/main.go
@@ -113,7 +113,7 @@ func main() {
concurrency: *concurrency,
localPath: path,
}
- repos, err := listRepositories(githubUser)
+ repos, err := listAllRepositories(githubUser)
if err != nil {
log.Fatal(err)
}