From bcb8b17c32b51228f69ff4d9067c52a8c51887c7 Mon Sep 17 00:00:00 2001 From: Uchio KONDO Date: Mon, 26 Jan 2015 14:56:30 +0900 Subject: [PATCH 1/2] Get github orgs over 30 --- plugin/remote/github/helper.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugin/remote/github/helper.go b/plugin/remote/github/helper.go index 16dd1f02d..c72aade61 100644 --- a/plugin/remote/github/helper.go +++ b/plugin/remote/github/helper.go @@ -140,8 +140,21 @@ func GetOrgRepos(client *github.Client, org string) ([]github.Repository, error) // GetOrgs is a helper function that returns a list of // all orgs that a user belongs to. func GetOrgs(client *github.Client) ([]github.Organization, error) { - orgs, _, err := client.Organizations.List("", nil) - return orgs, err + var allOrgs []github.Organization + var err error + page := 1 + for { + options := &github.ListOptions{Page: page} + orgs, _, err := client.Organizations.List("", options) + if len(orgs) == 0 || err != nil { + break + } + for _, v := range orgs { + allOrgs = append(allOrgs, v) + } + page++ + } + return allOrgs, err } // GetHook is a heper function that retrieves a hook by From 6699770e7626b2573fcba2fe5ec16bc191df7c03 Mon Sep 17 00:00:00 2001 From: Uchio KONDO Date: Mon, 26 Jan 2015 16:20:53 +0900 Subject: [PATCH 2/2] Fix loop to be consistent with the others --- plugin/remote/github/helper.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/plugin/remote/github/helper.go b/plugin/remote/github/helper.go index c72aade61..4d23180ee 100644 --- a/plugin/remote/github/helper.go +++ b/plugin/remote/github/helper.go @@ -140,21 +140,21 @@ func GetOrgRepos(client *github.Client, org string) ([]github.Repository, error) // GetOrgs is a helper function that returns a list of // all orgs that a user belongs to. func GetOrgs(client *github.Client) ([]github.Organization, error) { - var allOrgs []github.Organization - var err error - page := 1 - for { - options := &github.ListOptions{Page: page} - orgs, _, err := client.Organizations.List("", options) - if len(orgs) == 0 || err != nil { - break + var orgs []github.Organization + var opts = github.ListOptions{} + opts.Page = 1 + + for opts.Page > 0 { + list, resp, err := client.Organizations.List("", &opts) + if err != nil { + return nil, err } - for _, v := range orgs { - allOrgs = append(allOrgs, v) - } - page++ + orgs = append(orgs, list...) + + // increment the next page to retrieve + opts.Page = resp.NextPage } - return allOrgs, err + return orgs, nil } // GetHook is a heper function that retrieves a hook by