Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub API have changed the semantics of /user/repos API #203

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/main/java/org/kohsuke/github/GHMyself.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down Expand Up @@ -109,16 +121,31 @@ public PagedIterable<GHRepository> 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<GHRepository> 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<GHRepository> listRepositories(final int pageSize, final RepositoryType repoType) {
return new PagedIterable<GHRepository>() {
public PagedIterator<GHRepository> iterator() {
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/user/repos?per_page=" + pageSize, GHRepository[].class)) {
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/user/repos?per_page=" + pageSize +
"&type=" + repoType.name().toLowerCase(), GHRepository[].class)) {
@Override
protected void wrapUp(GHRepository[] page) {
for (GHRepository c : page)
Expand Down