Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on May 3, 2021. It is now read-only.

Commit 5430f3d

Browse filesBrowse files
committed
Merge pull request hub4j#391
2 parents 41c028d + 43075fa commit 5430f3d
Copy full SHA for 5430f3d

File tree

Expand file treeCollapse file tree

2 files changed

+47
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+47
-1
lines changed

‎src/main/java/org/kohsuke/github/GitHub.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GitHub.java
+32-1Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import java.util.Date;
4949
import java.util.HashMap;
5050
import java.util.HashSet;
51-
import java.util.Hashtable;
5251
import java.util.List;
5352
import java.util.Map;
5453
import java.util.Set;
@@ -424,6 +423,9 @@ protected GHUser getUser(GHUser orig) {
424423
return u;
425424
}
426425

426+
/**
427+
* Gets {@link GHOrganization} specified by name.
428+
*/
427429
public GHOrganization getOrganization(String name) throws IOException {
428430
GHOrganization o = orgs.get(name);
429431
if (o==null) {
@@ -433,6 +435,35 @@ public GHOrganization getOrganization(String name) throws IOException {
433435
return o;
434436
}
435437

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+
436467
/**
437468
* Gets the repository object from 'user/reponame' string that GitHub calls as "repository name"
438469
*

‎src/test/java/org/kohsuke/github/GitHubTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GitHubTest.java
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
import java.lang.reflect.Field;
66
import java.util.Collections;
77
import java.util.HashMap;
8+
import java.util.HashSet;
89
import java.util.Map;
10+
import java.util.Set;
911

1012
import com.google.common.collect.Iterables;
1113
import org.junit.Test;
1214

15+
import static org.hamcrest.CoreMatchers.equalTo;
1316
import static org.hamcrest.CoreMatchers.notNullValue;
1417
import static org.hamcrest.MatcherAssert.assertThat;
1518
import static org.junit.Assert.assertEquals;
@@ -155,4 +158,16 @@ public void listUsers() throws IOException {
155158
System.out.println(u.getName());
156159
}
157160
}
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+
}
158173
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.