@@ -321,6 +321,10 @@ public boolean isFork() {
321321 return fork ;
322322 }
323323
324+ /**
325+ * Returns the number of all forks of this repository.
326+ * This not only counts direct forks, but also forks of forks, and so on.
327+ */
324328 public int getForks () {
325329 return forks ;
326330 }
@@ -517,6 +521,43 @@ public void delete() throws IOException {
517521 }
518522 }
519523
524+ /**
525+ * Sort orders for listing forks
526+ */
527+ public static enum ForkSort { NEWEST , OLDEST , STARGAZERS }
528+
529+ /**
530+ * Lists all the direct forks of this repository, sorted by
531+ * github api default, currently {@link ForkSort#NEWEST ForkSort.NEWEST}.
532+ */
533+ public PagedIterable <GHRepository > listForks () {
534+ return listForks (null );
535+ }
536+
537+ /**
538+ * Lists all the direct forks of this repository, sorted by the given sort order.
539+ * @param sort the sort order. If null, defaults to github api default,
540+ * currently {@link ForkSort#NEWEST ForkSort.NEWEST}.
541+ */
542+ public PagedIterable <GHRepository > listForks (final ForkSort sort ) {
543+ return new PagedIterable <GHRepository >() {
544+ public PagedIterator <GHRepository > iterator () {
545+ String sortParam = "" ;
546+ if (sort != null ) {
547+ sortParam = "?sort=" + sort .toString ().toLowerCase (Locale .ENGLISH );
548+ }
549+ return new PagedIterator <GHRepository >(root .retrieve ().asIterator (getApiTailUrl ("forks" + sortParam ), GHRepository [].class )) {
550+ @ Override
551+ protected void wrapUp (GHRepository [] page ) {
552+ for (GHRepository c : page ) {
553+ c .wrap (root );
554+ }
555+ }
556+ };
557+ }
558+ };
559+ }
560+
520561 /**
521562 * Forks this repository as your repository.
522563 *
0 commit comments