forked from hub4j/github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from frink182/issue/1669
Issue/1669
- Loading branch information
Showing
5 changed files
with
111 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/org/kohsuke/github/GHCommitFileIterable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package org.kohsuke.github; | ||
|
||
import org.kohsuke.github.GHCommit.File; | ||
|
||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Iterable for commit listing. | ||
* | ||
* @author Stephen Horgan | ||
*/ | ||
class GHCommitFileIterable extends PagedIterable<GHCommit.File> { | ||
|
||
/** | ||
* Number of files returned in the commit response. If there are more files than this, the response will include | ||
* pagination link headers for the remaining files. | ||
*/ | ||
private static final int GH_FILE_LIMIT_PER_COMMIT_PAGE = 300; | ||
|
||
private final GHRepository owner; | ||
private final String sha; | ||
private GHCommitFilesPage result; | ||
|
||
/** | ||
* Instantiates a new GH commit iterable. | ||
* | ||
* @param owner | ||
* the owner | ||
* @param sha | ||
* the SHA of the commit | ||
* @param files | ||
* the list of files initially populated | ||
*/ | ||
public GHCommitFileIterable(GHRepository owner, String sha, List<File> files) { | ||
this.owner = owner; | ||
this.sha = sha; | ||
this.result = new GHCommitFilesPage(files != null ? files.toArray(new File[0]) : new File[0]); | ||
} | ||
|
||
/** | ||
* Iterator. | ||
* | ||
* @param pageSize | ||
* the page size | ||
* @return the paged iterator | ||
*/ | ||
@Nonnull | ||
@Override | ||
public PagedIterator<GHCommit.File> _iterator(int pageSize) { | ||
|
||
Iterator<GHCommit.File[]> pageIterator; | ||
|
||
if (result.getFiles().length < GH_FILE_LIMIT_PER_COMMIT_PAGE) { | ||
// create a page iterator that only provides one page | ||
pageIterator = Collections.singleton(result.getFiles()).iterator(); | ||
} else { | ||
// page size is controlled by the server for this iterator, do not allow it to be set by the caller | ||
pageSize = 0; | ||
|
||
GitHubRequest request = owner.root() | ||
.createRequest() | ||
.withUrlPath(owner.getApiTailUrl("commits/" + sha)) | ||
.build(); | ||
|
||
pageIterator = adapt( | ||
GitHubPageIterator.create(owner.root().getClient(), GHCommitFilesPage.class, request, pageSize)); | ||
} | ||
|
||
return new PagedIterator<>(pageIterator, null); | ||
} | ||
|
||
/** | ||
* Adapt. | ||
* | ||
* @param base | ||
* the base commit page | ||
* @return the iterator | ||
*/ | ||
protected Iterator<GHCommit.File[]> adapt(final Iterator<GHCommitFilesPage> base) { | ||
return new Iterator<GHCommit.File[]>() { | ||
|
||
public boolean hasNext() { | ||
return base.hasNext(); | ||
} | ||
|
||
public GHCommit.File[] next() { | ||
GHCommitFilesPage v = base.next(); | ||
if (result == null) { | ||
result = v; | ||
} | ||
return v.getFiles(); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters