File tree Expand file tree Collapse file tree 2 files changed +46
-3
lines changed
main/java/org/kohsuke/github
test/java/org/kohsuke/github Expand file tree Collapse file tree 2 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -424,6 +424,9 @@ protected GHUser getUser(GHUser orig) {
424424 return u ;
425425 }
426426
427+ /**
428+ * Gets {@link GHOrganization} specified by name.
429+ */
427430 public GHOrganization getOrganization (String name ) throws IOException {
428431 GHOrganization o = orgs .get (name );
429432 if (o ==null ) {
@@ -433,6 +436,35 @@ public GHOrganization getOrganization(String name) throws IOException {
433436 return o ;
434437 }
435438
439+ /**
440+ * Gets a list of all organizations.
441+ */
442+ public PagedIterable <GHOrganization > getOrganizations () {
443+ return getOrganizations (null );
444+ }
445+
446+ /**
447+ * Gets a list of all organizations starting after the organization identifier specified by 'since'.
448+ *
449+ * @see <a href="https://developer.github.com/v3/orgs/#parameters">List All Orgs - Parameters</a>
450+ */
451+ public PagedIterable <GHOrganization > getOrganizations (final String since ) {
452+ return new PagedIterable <GHOrganization >() {
453+ @ Override
454+ public PagedIterator <GHOrganization > _iterator (int pageSize ) {
455+ System .out .println ("page size: " + pageSize );
456+ return new PagedIterator <GHOrganization >(retrieve ().with ("since" ,since )
457+ .asIterator ("/organizations" , GHOrganization [].class , pageSize )) {
458+ @ Override
459+ protected void wrapUp (GHOrganization [] page ) {
460+ for (GHOrganization c : page )
461+ c .wrapUp (GitHub .this );
462+ }
463+ };
464+ }
465+ };
466+ }
467+
436468 /**
437469 * Gets the repository object from 'user/reponame' string that GitHub calls as "repository name"
438470 *
Original file line number Diff line number Diff line change 33import java .io .FileNotFoundException ;
44import java .io .IOException ;
55import java .lang .reflect .Field ;
6- import java .util .Collections ;
7- import java .util .HashMap ;
8- import java .util .Map ;
6+ import java .util .*;
97
108import com .google .common .collect .Iterables ;
119import org .junit .Test ;
1210
11+ import static org .hamcrest .CoreMatchers .equalTo ;
1312import static org .hamcrest .CoreMatchers .notNullValue ;
1413import static org .hamcrest .MatcherAssert .assertThat ;
1514import static org .junit .Assert .assertEquals ;
@@ -155,4 +154,16 @@ public void listUsers() throws IOException {
155154 System .out .println (u .getName ());
156155 }
157156 }
157+
158+ @ Test
159+ public void getOrgs () throws IOException {
160+ GitHub hub = GitHub .connect ();
161+ int iterations = 10 ;
162+ Set <Long > orgIds = new HashSet <Long >();
163+ for (GHOrganization org : Iterables .limit (hub .getOrganizations ().withPageSize (2 ), iterations )) {
164+ orgIds .add (org .getId ());
165+ System .out .println (org .getName ());
166+ }
167+ assertThat (orgIds .size (), equalTo (iterations ));
168+ }
158169}
You can’t perform that action at this time.
0 commit comments