Skip to content

Commit

Permalink
Support paging when fetching organization members
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ryankennedy committed Jan 22, 2014
1 parent ce5ae13 commit fee02a3
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/main/java/org/kohsuke/github/GHOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,14 @@ public void publicize(GHUser u) throws IOException {
/**
* All the members of this organization.
*/
public List<GHUser> getMembers() throws IOException {
return new AbstractList<GHUser>() {
// these are shallow objects with only some limited values filled out
// TODO: it's better to allow objects to fill themselves in later when missing values are requested
final GHUser[] shallow = root.retrieve().to("/orgs/" + login + "/members", GHUser[].class);

@Override
public GHUser get(int index) {
try {
return root.getUser(shallow[index].getLogin());
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
public int size() {
return shallow.length;
public PagedIterable<GHUser> getMembers() throws IOException {
return new PagedIterable<GHUser>() {
public PagedIterator<GHUser> iterator() {
return new PagedIterator<GHUser>(root.retrieve().asIterator(String.format("/orgs/%s/members", login), GHUser[].class)) {
@Override
protected void wrapUp(GHUser[] page) {
}
};
}
};
}
Expand Down

0 comments on commit fee02a3

Please sign in to comment.