Skip to content

Commit

Permalink
Fixes #183: added a method listForks() to GHRepository
Browse files Browse the repository at this point in the history
listForks() will list all forks of a repository.
An optional sort argument is also supported.
  • Loading branch information
marc-guenther committed May 1, 2015
1 parent b976e0e commit 9b750be
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,35 @@ public void delete() throws IOException {
}
}

/**
* Sort orders for listing forks
*/
public static enum Sort { NEWEST, OLDEST, STARGAZERS }

/**
* Lists all the forks of this repository.
*/
public PagedIterable<GHRepository> listForks() {
return listForks(null);
}

/**
* Lists up all the forks of this repository, sorted by the given sort order.
*/
public PagedIterable<GHRepository> listForks(final Sort sort) {
return new PagedIterable<GHRepository>() {
public PagedIterator<GHRepository> iterator() {
return new PagedIterator<GHRepository>(root.retrieve().asIterator(getApiTailUrl("forks" + ((sort == null)?"":("?sort="+sort.toString().toLowerCase(Locale.ENGLISH)))), GHRepository[].class)) {
@Override
protected void wrapUp(GHRepository[] page) {
for (GHRepository c : page)
c.wrap(root);
}
};
}
};
}

/**
* Forks this repository as your repository.
*
Expand Down

0 comments on commit 9b750be

Please sign in to comment.