Skip to content

Commit

Permalink
fix #145 GHTeam.getMembers() does not page properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Schoening committed Dec 28, 2014
1 parent 425ae2d commit e356675
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/main/java/org/kohsuke/github/GHTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

/**
* A team in GitHub organization.
Expand Down Expand Up @@ -48,12 +52,27 @@ public int getId() {
return id;
}

/**
* Retrieves the current members.
*/
public Set<GHUser> getMembers() throws IOException {
return new HashSet<GHUser>(Arrays.asList(GHUser.wrap(org.root.retrieve().to(api("/members"), GHUser[].class), org.root)));
}
/**
* Retrieves the current members.
*/
public Set<GHUser> getMembers() throws IOException {

Set<GHUser> members = new LinkedHashSet<GHUser>();

Iterator<GHUser[]> pageIterator = org.root.retrieve().asIterator(api("/members"),
GHUser[].class);
while (pageIterator != null && pageIterator.hasNext()) {
GHUser[] users = pageIterator.next();
if (users != null) {
GHUser.wrap(users, org.root);
for (GHUser user : users) {
members.add(user);
}
}
}

return Collections.unmodifiableSet(members);
}

/**
* Checks if this team has the specified user as a member.
Expand Down

0 comments on commit e356675

Please sign in to comment.