Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #183: added a method listForks() to GHRepository #185

Merged
merged 4 commits into from
Jul 17, 2015

Conversation

marc-guenther
Copy link
Contributor

listForks() will list all forks of a repository.

An optional sort argument is also supported.

I did not know if list* or get* is the way to go, but as getForks() is already taken (it returns the number of forks), I decided to use listForks(), with an optional sort argument.

@buildhive
Copy link

Kohsuke Kawaguchi » github-api #338 SUCCESS
This pull request looks good
(what's this?)

listForks() will list all forks of a repository.
An optional sort argument is also supported.
/**
* Lists up all the forks of this repository, sorted by the given sort order.
*/
public PagedIterable<GHRepository> listForks(final Sort sort) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add @CheckForNull and describe the behavior in Javadoc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not a single @CheckForNull in the entire codebase so far. If you want to start introducing them, go ahead, but that was not the scope of this pull request.
Regarding Javadoc, I was under the impression that both methods I added actually have Javadoc comments, but maybe I miscounted.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intention was to highlight the method accepts nulls and to describe the behavior in that case.

There is not a single @checkfornull in the entire codebase so far. If you want to start introducing them, go ahead, but that was not the scope of this pull request.

I think that new pull requests could follow better practices than the legacy code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

Just added (hopefully) better Javadoc. Unfortunately, I was not able to find out how to add the @CheckForNull annotation.

@buildhive
Copy link

Kohsuke Kawaguchi » github-api #348 SUCCESS
This pull request looks good
(what's this?)

@marc-guenther
Copy link
Contributor Author

Any chance of merging this? We are using this all the time now, and not a single problem so far...

public PagedIterable<GHRepository> listForks(final Sort 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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sort == null)?"":("?sort="+sort.toString().toLowerCase(Locale.ENGLISH))))
this line is too difficult to understand - can you use separate method for this logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it is quite easy, if a sort is given, use it, otherwise don't.

Sorry, but I don't know how to write this more clearly...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Spaces. Use them.
public PagedIterator<GHRepository> iterator() {       
               return new PagedIterator<GHRepository>(root.retrieve()
                              // statically imported org.apache.commons.lang.ObjectUtils.defaultIfNull
                               .with("sort", defaultIfNull(sort, Sort.NEWEST).name().toLowerCase())
                               .asIterator(getApiTailUrl("forks")), GHRepository[].class)) {

Actually it is quite easy, if a sort is given, use it, otherwise don't.

If one line gets more than 10s to understand code - it need to be refactored

@buildhive
Copy link

Kohsuke Kawaguchi » github-api #367 SUCCESS
This pull request looks good
(what's this?)

@@ -37,6 +37,7 @@
import java.util.*;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you dont need it if you dont use it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, lol, I put it in and then forgot to remove it again ;)

@lanwen
Copy link
Contributor

lanwen commented Jul 17, 2015

@marc-guenther, thanks for update, 👍 for me now

kohsuke added a commit that referenced this pull request Jul 17, 2015
Fixes #183: added a method listForks() to GHRepository
@kohsuke kohsuke merged commit efa48ac into hub4j:master Jul 17, 2015
@buildhive
Copy link

Kohsuke Kawaguchi » github-api #371 SUCCESS
This pull request looks good
(what's this?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants