Skip to content

Commit

Permalink
renamed Sort enum, some cleanup, better javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-guenther committed Jul 17, 2015
1 parent a5425a3 commit a83aad2
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/main/java/org/kohsuke/github/GHRepository.java
Expand Up @@ -37,6 +37,7 @@
import java.util.*;

import static java.util.Arrays.asList;
import static org.apache.commons.lang.ObjectUtils.defaultIfNull;

/**
* A repository on GitHub.
Expand Down Expand Up @@ -512,27 +513,34 @@ public void delete() throws IOException {
/**
* Sort orders for listing forks
*/
public static enum Sort { NEWEST, OLDEST, STARGAZERS }
public static enum ForkSort { NEWEST, OLDEST, STARGAZERS }

/**
* Lists all the direct forks of this repository, sorted by {@link Sort#NEWEST Sort.NEWEST}
* 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 {@link Sort#NEWEST Sort.NEWEST}.
* @param sort the sort order. If null, defaults to github api default,
* currently {@link ForkSort#NEWEST ForkSort.NEWEST}.
*/
public PagedIterable<GHRepository> listForks(final Sort sort) {
public PagedIterable<GHRepository> listForks(final ForkSort 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)) {
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)
for (GHRepository c : page) {
c.wrap(root);
}
}
};
}
Expand Down

0 comments on commit a83aad2

Please sign in to comment.