From fee02a3d16aa835c2f1e606897e4bd08e51ba7d5 Mon Sep 17 00:00:00 2001 From: Ryan Kennedy Date: Wed, 22 Jan 2014 09:56:06 -0800 Subject: [PATCH 1/4] 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 so clients can fetch the entire organization's member list. --- .../org/kohsuke/github/GHOrganization.java | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index ec899c0538..5d0eb7cd63 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -80,24 +80,14 @@ public void publicize(GHUser u) throws IOException { /** * All the members of this organization. */ - public List getMembers() throws IOException { - return new AbstractList() { - // 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 getMembers() throws IOException { + return new PagedIterable() { + public PagedIterator iterator() { + return new PagedIterator(root.retrieve().asIterator(String.format("/orgs/%s/members", login), GHUser[].class)) { + @Override + protected void wrapUp(GHUser[] page) { + } + }; } }; } From 628034ae8cf0800a755c30080e70f217d91b2103 Mon Sep 17 00:00:00 2001 From: lindseydew Date: Tue, 11 Feb 2014 18:07:01 +0000 Subject: [PATCH 2/4] add a filter param to the get members method --- src/main/java/org/kohsuke/github/GHOrganization.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 5d0eb7cd63..0be7350711 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -81,9 +81,15 @@ public void publicize(GHUser u) throws IOException { * All the members of this organization. */ public PagedIterable getMembers() throws IOException { + return getMembersWithFilter(null); + } + + public PagedIterable getMembersWithFilter(final String filter) throws IOException { + return new PagedIterable() { public PagedIterator iterator() { - return new PagedIterator(root.retrieve().asIterator(String.format("/orgs/%s/members", login), GHUser[].class)) { + String filterParams = (filter == null) ? "" : ("?filter=" + filter); + return new PagedIterator(root.retrieve().asIterator(String.format("/orgs/%s/members%s", login, filterParams), GHUser[].class)) { @Override protected void wrapUp(GHUser[] page) { } @@ -91,7 +97,6 @@ protected void wrapUp(GHUser[] page) { } }; } - /** * Conceals the membership. */ From 9930e7bb93b46532fb19a6ed79ea36944c1858d6 Mon Sep 17 00:00:00 2001 From: Roberto Tyley Date: Thu, 13 Mar 2014 22:04:45 +0000 Subject: [PATCH 3/4] Add org public-members call, to complement the full members list http://developer.github.com/v3/orgs/members/#public-members-list --- .../org/kohsuke/github/GHOrganization.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 0be7350711..dedc9e2748 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -81,15 +81,29 @@ public void publicize(GHUser u) throws IOException { * All the members of this organization. */ public PagedIterable getMembers() throws IOException { - return getMembersWithFilter(null); + return getMembers("members"); } - public PagedIterable getMembersWithFilter(final String filter) throws IOException { + /** + * All the public members of this organization. + */ + public PagedIterable getPublicMembers() throws IOException { + return getMembers("public_members"); + } + + private PagedIterable getMembers(String suffix) throws IOException { + return getMembers(suffix, null); + } + + public PagedIterable getMembersWithFilter(String filter) throws IOException { + return getMembers("members", filter); + } + private PagedIterable getMembers(final String suffix, final String filter) throws IOException { return new PagedIterable() { public PagedIterator iterator() { String filterParams = (filter == null) ? "" : ("?filter=" + filter); - return new PagedIterator(root.retrieve().asIterator(String.format("/orgs/%s/members%s", login, filterParams), GHUser[].class)) { + return new PagedIterator(root.retrieve().asIterator(String.format("/orgs/%s/%s%s", login, suffix, filterParams), GHUser[].class)) { @Override protected void wrapUp(GHUser[] page) { } @@ -97,6 +111,7 @@ protected void wrapUp(GHUser[] page) { } }; } + /** * Conceals the membership. */ From d29ea97948f56025e05b766e8b64382447c804e0 Mon Sep 17 00:00:00 2001 From: Roberto Tyley Date: Fri, 14 Mar 2014 09:22:15 +0000 Subject: [PATCH 4/4] Fix org.getMembers() to 'wrap' returned users for post-populating This fixes an issue introduced with PR #66 in commit fee02a3d16 - the `getMembers()` method switched to using paging, but lost the code that populated the users with a full set of values. This commit just applies 'wrapping' to all users returned, so that methods like `user.getCreatedAt()` can be called on returned users without throwing a NullPointerException - the reference to 'root' allows the user objects to populate themselves. --- src/main/java/org/kohsuke/github/GHOrganization.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index dedc9e2748..f040518466 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -105,7 +105,8 @@ public PagedIterator iterator() { String filterParams = (filter == null) ? "" : ("?filter=" + filter); return new PagedIterator(root.retrieve().asIterator(String.format("/orgs/%s/%s%s", login, suffix, filterParams), GHUser[].class)) { @Override - protected void wrapUp(GHUser[] page) { + protected void wrapUp(GHUser[] users) { + GHUser.wrap(users, root); } }; }