Skip to content

Commit

Permalink
Merge pull request #185 from marc-guenther/master
Browse files Browse the repository at this point in the history
Fixes #183: added a method listForks() to GHRepository
  • Loading branch information
kohsuke committed Jul 17, 2015
2 parents 15e4d07 + 23c56ff commit efa48ac
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ public boolean isFork() {
return fork;
}

/**
* Returns the number of all forks of this repository.
* This not only counts direct forks, but also forks of forks, and so on.
*/
public int getForks() {
return forks;
}
Expand Down Expand Up @@ -517,6 +521,43 @@ public void delete() throws IOException {
}
}

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

/**
* Lists all the direct forks of this repository, sorted by
* github api default, currently {@link ForkSort#NEWEST ForkSort.NEWEST}.
*/
public PagedIterable<GHRepository> listForks() {
return listForks(null);
}

/**
* Lists all the direct forks of this repository, sorted by the given sort order.
* @param sort the sort order. If null, defaults to github api default,
* currently {@link ForkSort#NEWEST ForkSort.NEWEST}.
*/
public PagedIterable<GHRepository> listForks(final ForkSort sort) {
return new PagedIterable<GHRepository>() {
public PagedIterator<GHRepository> iterator() {
String sortParam = "";
if (sort != null) {
sortParam = "?sort=" + sort.toString().toLowerCase(Locale.ENGLISH);
}
return new PagedIterator<GHRepository>(root.retrieve().asIterator(getApiTailUrl("forks" + sortParam), 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 efa48ac

Please sign in to comment.