From b0d1eac477425d730e0919ed6aac2fb3d87852e5 Mon Sep 17 00:00:00 2001 From: Luca Milanesio Date: Fri, 26 Jun 2015 09:34:45 +0100 Subject: [PATCH] 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)