Skip to content

Commit fee02a3

Browse files
committed
Support paging when fetching organization members
Organization members are a paged list in the V3 GitHub API. Previously the code would fetch only the first page of ~30 members and return that. This change switches the return to a PagedIterable<GHUser> so clients can fetch the entire organization's member list.
1 parent ce5ae13 commit fee02a3

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

src/main/java/org/kohsuke/github/GHOrganization.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,14 @@ public void publicize(GHUser u) throws IOException {
8080
/**
8181
* All the members of this organization.
8282
*/
83-
public List<GHUser> getMembers() throws IOException {
84-
return new AbstractList<GHUser>() {
85-
// these are shallow objects with only some limited values filled out
86-
// TODO: it's better to allow objects to fill themselves in later when missing values are requested
87-
final GHUser[] shallow = root.retrieve().to("/orgs/" + login + "/members", GHUser[].class);
88-
89-
@Override
90-
public GHUser get(int index) {
91-
try {
92-
return root.getUser(shallow[index].getLogin());
93-
} catch (IOException e) {
94-
throw new RuntimeException(e);
95-
}
96-
}
97-
98-
@Override
99-
public int size() {
100-
return shallow.length;
83+
public PagedIterable<GHUser> getMembers() throws IOException {
84+
return new PagedIterable<GHUser>() {
85+
public PagedIterator<GHUser> iterator() {
86+
return new PagedIterator<GHUser>(root.retrieve().asIterator(String.format("/orgs/%s/members", login), GHUser[].class)) {
87+
@Override
88+
protected void wrapUp(GHUser[] page) {
89+
}
90+
};
10191
}
10292
};
10393
}

0 commit comments

Comments
 (0)