From b0d1eac477425d730e0919ed6aac2fb3d87852e5 Mon Sep 17 00:00:00 2001 From: Luca Milanesio Date: Fri, 26 Jun 2015 09:34:45 +0100 Subject: [PATCH 1/3] GitHub API have changed the semantics of /user/repos API It seems that since a couple of days (or weeks?) the /user/repos is returning ALL the repositories that the user has access or collaborates to whilst previously were only the ones that belong to him. JavaDoc updated in order to avoid getting unwanted results and introduced as well the possibility to filter a specific type of repository to be returned: - All (the GitHub's default) - Owner (the user's repos) - Public / Private (public or private repos) - Member (the user collaborates to) --- .../java/org/kohsuke/github/GHMyself.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index 7b588e88fa..b43ddc1126 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -17,6 +17,18 @@ * @author Kohsuke Kawaguchi */ public class GHMyself extends GHUser { + + /** + * Type of repositories returned during listing. + */ + public enum RepositoryType { + ALL, // All public and private repositories that current user has access or collaborates to + OWNER, // Public and private repositories owned by current user + PUBLIC, // Public repositories that current user has access or collaborates to + PRIVATE, // Private repositories that current user has access or collaborates to + MEMBER; // Public and private repositories that current user is a member + } + /** * @deprecated * Use {@link #getEmails2()} @@ -109,16 +121,31 @@ public PagedIterable listRepositories() { } /** - * Lists up all the repositories this user owns (public and private) using the specified page size. + * List repositories that are accessible to the authenticated user (public and private) using the specified page size. + * + * This includes repositories owned by the authenticated user, repositories that belong to other users + * where the authenticated user is a collaborator, and other organizations' repositories that the authenticated + * user has access to through an organization membership. * * @param pageSize size for each page of items returned by GitHub. Maximum page size is 100. * * Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned. */ public PagedIterable listRepositories(final int pageSize) { + return listRepositories(pageSize, RepositoryType.ALL); + } + + /** + * List repositories of a certain type that are accessible by current authenticated user using the specified page size. + * + * @param pageSize size for each page of items returned by GitHub. Maximum page size is 100. + * @param repoType type of repository returned in the listing + */ + public PagedIterable listRepositories(final int pageSize, final RepositoryType repoType) { return new PagedIterable() { public PagedIterator iterator() { - return new PagedIterator(root.retrieve().asIterator("/user/repos?per_page=" + pageSize, GHRepository[].class)) { + return new PagedIterator(root.retrieve().asIterator("/user/repos?per_page=" + pageSize + + "&type=" + repoType.name().toLowerCase(), GHRepository[].class)) { @Override protected void wrapUp(GHRepository[] page) { for (GHRepository c : page) From dd21bcb34ce1994b96a388f36fe564edd2d03c18 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 17 Jul 2015 13:51:31 +0300 Subject: [PATCH 2/3] I think this is a better name --- src/main/java/org/kohsuke/github/GHMyself.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index b43ddc1126..b0eee7b8e3 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -5,7 +5,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -21,7 +20,7 @@ public class GHMyself extends GHUser { /** * Type of repositories returned during listing. */ - public enum RepositoryType { + public enum RepositoryListFilter { ALL, // All public and private repositories that current user has access or collaborates to OWNER, // Public and private repositories owned by current user PUBLIC, // Public repositories that current user has access or collaborates to @@ -132,7 +131,7 @@ public PagedIterable listRepositories() { * Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned. */ public PagedIterable listRepositories(final int pageSize) { - return listRepositories(pageSize, RepositoryType.ALL); + return listRepositories(pageSize, RepositoryListFilter.ALL); } /** @@ -141,7 +140,7 @@ public PagedIterable listRepositories(final int pageSize) { * @param pageSize size for each page of items returned by GitHub. Maximum page size is 100. * @param repoType type of repository returned in the listing */ - public PagedIterable listRepositories(final int pageSize, final RepositoryType repoType) { + public PagedIterable listRepositories(final int pageSize, final RepositoryListFilter repoType) { return new PagedIterable() { public PagedIterator iterator() { return new PagedIterator(root.retrieve().asIterator("/user/repos?per_page=" + pageSize + From 90daf8087e8648cd403e3e26b5f01878701fc874 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 17 Jul 2015 13:52:16 +0300 Subject: [PATCH 3/3] Turning this into javadoc so that users can see them in IDE. --- .../java/org/kohsuke/github/GHMyself.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index b0eee7b8e3..2041336367 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -21,11 +21,26 @@ public class GHMyself extends GHUser { * Type of repositories returned during listing. */ public enum RepositoryListFilter { - ALL, // All public and private repositories that current user has access or collaborates to - OWNER, // Public and private repositories owned by current user - PUBLIC, // Public repositories that current user has access or collaborates to - PRIVATE, // Private repositories that current user has access or collaborates to - MEMBER; // Public and private repositories that current user is a member + /** + * All public and private repositories that current user has access or collaborates to + */ + ALL, + /** + * Public and private repositories owned by current user + */ + OWNER, + /** + * Public repositories that current user has access or collaborates to + */ + PUBLIC, + /** + * Private repositories that current user has access or collaborates to + */ + PRIVATE, + /** + * Public and private repositories that current user is a member + */ + MEMBER; } /**