From ab24e6e1c12b9ecbdbe83fad8fbbe22a43780b2f Mon Sep 17 00:00:00 2001 From: sg012265 Date: Mon, 30 Oct 2017 15:32:25 -0500 Subject: [PATCH 1/2] Add get for all orgs --- src/main/java/org/kohsuke/github/GitHub.java | 32 +++++++++++++++++++ .../java/org/kohsuke/github/GitHubTest.java | 17 ++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 67fc1f8fe4..1013508c01 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -424,6 +424,9 @@ protected GHUser getUser(GHUser orig) { return u; } + /** + * Gets {@link GHOrganization} specified by name. + */ public GHOrganization getOrganization(String name) throws IOException { GHOrganization o = orgs.get(name); if (o==null) { @@ -433,6 +436,35 @@ public GHOrganization getOrganization(String name) throws IOException { return o; } + /** + * Gets a list of all organizations. + */ + public PagedIterable getOrganizations() { + return getOrganizations(null); + } + + /** + * Gets a list of all organizations starting after the organization identifier specified by 'since'. + * + * @see List All Orgs - Parameters + */ + public PagedIterable getOrganizations(final String since) { + return new PagedIterable() { + @Override + public PagedIterator _iterator(int pageSize) { + System.out.println("page size: " + pageSize); + return new PagedIterator(retrieve().with("since",since) + .asIterator("/organizations", GHOrganization[].class, pageSize)) { + @Override + protected void wrapUp(GHOrganization[] page) { + for (GHOrganization c : page) + c.wrapUp(GitHub.this); + } + }; + } + }; + } + /** * Gets the repository object from 'user/reponame' string that GitHub calls as "repository name" * diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index a418db5fde..9b30d31b6e 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -3,13 +3,12 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Field; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import com.google.common.collect.Iterables; import org.junit.Test; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; @@ -155,4 +154,16 @@ public void listUsers() throws IOException { System.out.println(u.getName()); } } + + @Test + public void getOrgs() throws IOException { + GitHub hub = GitHub.connect(); + int iterations = 10; + Set orgIds = new HashSet(); + for (GHOrganization org : Iterables.limit(hub.getOrganizations().withPageSize(2), iterations)) { + orgIds.add(org.getId()); + System.out.println(org.getName()); + } + assertThat(orgIds.size(), equalTo(iterations)); + } } From 35ba2671155953278e7e491466b3a379d6cd087e Mon Sep 17 00:00:00 2001 From: sg012265 Date: Mon, 30 Oct 2017 15:38:19 -0500 Subject: [PATCH 2/2] Revert wildcard usage for imports --- src/test/java/org/kohsuke/github/GitHubTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index 9b30d31b6e..c6e1e4113a 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -3,7 +3,11 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Field; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import com.google.common.collect.Iterables; import org.junit.Test;