From 9b750bedef39660d21f8e06165a8ee56df5cc797 Mon Sep 17 00:00:00 2001 From: Marc Guenther Date: Wed, 29 Apr 2015 18:15:04 +0200 Subject: [PATCH] Fixes #183: added a method listForks() to GHRepository listForks() will list all forks of a repository. An optional sort argument is also supported. --- .../java/org/kohsuke/github/GHRepository.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index e4459e84d6..59d0dead97 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -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 listForks() { + return listForks(null); + } + + /** + * Lists up all the forks of this repository, sorted by the given sort order. + */ + public PagedIterable listForks(final Sort sort) { + return new PagedIterable() { + public PagedIterator iterator() { + return new PagedIterator(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. *