This repository was archived by the owner on May 3, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed
Filter options
main/java/org/kohsuke/github
test/java/org/kohsuke/github Expand file tree Collapse file tree 2 files changed +47
-1
lines changed
Original file line number Diff line number Diff line change 48
48
import java .util .Date ;
49
49
import java .util .HashMap ;
50
50
import java .util .HashSet ;
51
- import java .util .Hashtable ;
52
51
import java .util .List ;
53
52
import java .util .Map ;
54
53
import java .util .Set ;
@@ -424,6 +423,9 @@ protected GHUser getUser(GHUser orig) {
424
423
return u ;
425
424
}
426
425
426
+ /**
427
+ * Gets {@link GHOrganization} specified by name.
428
+ */
427
429
public GHOrganization getOrganization (String name ) throws IOException {
428
430
GHOrganization o = orgs .get (name );
429
431
if (o ==null ) {
@@ -433,6 +435,35 @@ public GHOrganization getOrganization(String name) throws IOException {
433
435
return o ;
434
436
}
435
437
438
+ /**
439
+ * Gets a list of all organizations.
440
+ */
441
+ public PagedIterable <GHOrganization > listOrganizations () {
442
+ return listOrganizations (null );
443
+ }
444
+
445
+ /**
446
+ * Gets a list of all organizations starting after the organization identifier specified by 'since'.
447
+ *
448
+ * @see <a href="https://developer.github.com/v3/orgs/#parameters">List All Orgs - Parameters</a>
449
+ */
450
+ public PagedIterable <GHOrganization > listOrganizations (final String since ) {
451
+ return new PagedIterable <GHOrganization >() {
452
+ @ Override
453
+ public PagedIterator <GHOrganization > _iterator (int pageSize ) {
454
+ System .out .println ("page size: " + pageSize );
455
+ return new PagedIterator <GHOrganization >(retrieve ().with ("since" ,since )
456
+ .asIterator ("/organizations" , GHOrganization [].class , pageSize )) {
457
+ @ Override
458
+ protected void wrapUp (GHOrganization [] page ) {
459
+ for (GHOrganization c : page )
460
+ c .wrapUp (GitHub .this );
461
+ }
462
+ };
463
+ }
464
+ };
465
+ }
466
+
436
467
/**
437
468
* Gets the repository object from 'user/reponame' string that GitHub calls as "repository name"
438
469
*
Original file line number Diff line number Diff line change 5
5
import java .lang .reflect .Field ;
6
6
import java .util .Collections ;
7
7
import java .util .HashMap ;
8
+ import java .util .HashSet ;
8
9
import java .util .Map ;
10
+ import java .util .Set ;
9
11
10
12
import com .google .common .collect .Iterables ;
11
13
import org .junit .Test ;
12
14
15
+ import static org .hamcrest .CoreMatchers .equalTo ;
13
16
import static org .hamcrest .CoreMatchers .notNullValue ;
14
17
import static org .hamcrest .MatcherAssert .assertThat ;
15
18
import static org .junit .Assert .assertEquals ;
@@ -155,4 +158,16 @@ public void listUsers() throws IOException {
155
158
System .out .println (u .getName ());
156
159
}
157
160
}
161
+
162
+ @ Test
163
+ public void getOrgs () throws IOException {
164
+ GitHub hub = GitHub .connect ();
165
+ int iterations = 10 ;
166
+ Set <Long > orgIds = new HashSet <Long >();
167
+ for (GHOrganization org : Iterables .limit (hub .listOrganizations ().withPageSize (2 ), iterations )) {
168
+ orgIds .add (org .getId ());
169
+ System .out .println (org .getName ());
170
+ }
171
+ assertThat (orgIds .size (), equalTo (iterations ));
172
+ }
158
173
}
You can’t perform that action at this time.
0 commit comments