diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index e4459e84d6..234ead7621 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -505,6 +505,49 @@ 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); + } + }; + } + }; + } + +// I do not know when to use list* or get*, also getForks() is already taken (returns the count), +// so I tried this, but than the listForks implementation above also works. +// I have no idea which one is the preferred way of doing things... +// /** +// * Retrieves the forks of this repository. +// */ +// public List getForkedRepositories() throws IOException { +// List list = new ArrayList(Arrays.asList( +// root.retrieve().to(getApiTailUrl("forks"), GHRepository[].class))); +// for (GHRepository h : list) +// h.wrap(root); +// return list; +// } + /** * Forks this repository as your repository. *