-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return all files from a commit (#1679)
* Fix for #1669 * Doc updates * Add test data * Spotless * Javadoc changes * Test comment fixes * PR review changes * Add required default constructor * Update GHCommitFileIterable.java --------- Co-authored-by: Steve <[email protected]> Co-authored-by: Liam Newman <[email protected]>
- Loading branch information
1 parent
c494891
commit e45932d
Showing
81 changed files
with
14,618 additions
and
4 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
96 changes: 96 additions & 0 deletions
96
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,96 @@ | ||
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 final File[] files; | ||
|
||
/** | ||
* 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.files = files != null ? files.toArray(new File[0]) : null; | ||
} | ||
|
||
/** | ||
* Iterator. | ||
* | ||
* @param pageSize | ||
* the page size | ||
* @return the paged iterator | ||
*/ | ||
@Nonnull | ||
@Override | ||
public PagedIterator<GHCommit.File> _iterator(int pageSize) { | ||
|
||
Iterator<GHCommit.File[]> pageIterator; | ||
|
||
if (files != null && files.length < GH_FILE_LIMIT_PER_COMMIT_PAGE) { | ||
// create a page iterator that only provides one page | ||
pageIterator = Collections.singleton(files).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(); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.kohsuke.github; | ||
|
||
import org.kohsuke.github.GHCommit.File; | ||
|
||
/** | ||
* Represents the array of files in a commit returned by github. | ||
* | ||
* @author Stephen Horgan | ||
*/ | ||
class GHCommitFilesPage { | ||
private File[] files; | ||
|
||
public GHCommitFilesPage() { | ||
} | ||
|
||
public GHCommitFilesPage(File[] files) { | ||
this.files = files; | ||
} | ||
|
||
/** | ||
* Gets the files. | ||
* | ||
* @param owner | ||
* the owner | ||
* @return the files | ||
*/ | ||
File[] getFiles() { | ||
return files; | ||
} | ||
} |
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 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
...rces/org/kohsuke/github/CommitTest/wiremock/getMessage/__files/orgs_hub4j-test-org-2.json
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,31 @@ | ||
{ | ||
"login": "hub4j-test-org", | ||
"id": 7544739, | ||
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", | ||
"url": "https://api.github.com/orgs/hub4j-test-org", | ||
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", | ||
"events_url": "https://api.github.com/orgs/hub4j-test-org/events", | ||
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", | ||
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", | ||
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", | ||
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", | ||
"description": "Hub4j Test Org Description (this could be null or blank too)", | ||
"name": "Hub4j Test Org Name (this could be null or blank too)", | ||
"company": null, | ||
"blog": "https://hub4j.url.io/could/be/null", | ||
"location": "Hub4j Test Org Location (this could be null or blank too)", | ||
"email": "[email protected]", | ||
"twitter_username": null, | ||
"is_verified": false, | ||
"has_organization_projects": true, | ||
"has_repository_projects": true, | ||
"public_repos": 26, | ||
"public_gists": 0, | ||
"followers": 1, | ||
"following": 0, | ||
"html_url": "https://github.com/hub4j-test-org", | ||
"created_at": "2014-05-10T19:39:11Z", | ||
"updated_at": "2020-06-04T05:56:10Z", | ||
"type": "Organization" | ||
} |
Oops, something went wrong.