Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6c1c832

Browse filesBrowse files
committed
Update tests and javadoc
1 parent d03edbf commit 6c1c832
Copy full SHA for 6c1c832

File tree

Expand file treeCollapse file tree

45 files changed

+56076
-88
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

45 files changed

+56076
-88
lines changed

‎src/main/java/org/kohsuke/github/GHCompare.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHCompare.java
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ public Commit getMergeBaseCommit() {
134134
/**
135135
* Gets an array of commits.
136136
*
137+
* By default, the commit list is limited to 250 results.
138+
*
139+
* Since
140+
* <a href="https://github.blog/changelog/2021-03-22-compare-rest-api-now-supports-pagination/">2021-03-22</a>,
141+
* compare supports pagination of commits. This makes the initial {@link GHCompare} response return faster and
142+
* supports comparisons with more than 250 commits. To read commits progressively using pagination, set
143+
* {@link GHRepository#setCompareUsePaginatedCommits(boolean)} to true before calling
144+
* {@link GHRepository#getCompare(String, String)}.
145+
*
137146
* @return A copy of the array being stored in the class.
138147
*/
139148
public Commit[] getCommits() {
@@ -147,6 +156,15 @@ public Commit[] getCommits() {
147156
/**
148157
* Iterable of commits for this comparison.
149158
*
159+
* By default, the commit list is limited to 250 results.
160+
*
161+
* Since
162+
* <a href="https://github.blog/changelog/2021-03-22-compare-rest-api-now-supports-pagination/">2021-03-22</a>,
163+
* compare supports pagination of commits. This makes the initial {@link GHCompare} response return faster and
164+
* supports comparisons with more than 250 commits. To read commits progressively using pagination, set
165+
* {@link GHRepository#setCompareUsePaginatedCommits(boolean)} to true before calling
166+
* {@link GHRepository#getCompare(String, String)}.
167+
*
150168
* @return iterable of commits
151169
*/
152170
public PagedIterable<Commit> listCommits() {

‎src/main/java/org/kohsuke/github/GHRepository.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,15 @@ public GHHook getHook(int id) throws IOException {
16441644
}
16451645

16461646
/**
1647+
* Sets {@link #getCompare(String, String)} to return a {@link GHCompare} that uses a paginated commit list instead
1648+
* of limiting to 250 results.
16471649
*
1650+
* By default, {@link GHCompare} returns all commits in the comparison as part of the request, limited to 250
1651+
* results. More recently GitHub added the ability to return the commits as a paginated query allowing for more than
1652+
* 250 results.
1653+
*
1654+
* @param value
1655+
* true if you want commits returned in paginated form.
16481656
*/
16491657
public void setCompareUsePaginatedCommits(boolean value) {
16501658
compareUsePaginatedCommits = value;

‎src/test/java/org/kohsuke/github/GHRepositoryTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHRepositoryTest.java
+46-8Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -868,23 +868,26 @@ public void getLastCommitStatus() throws Exception {
868868
}
869869

870870
@Test
871-
public void getCommitsBetween() throws Exception {
871+
public void listCommitsBetween() throws Exception {
872872
GHRepository repository = getRepository();
873873
int startingCount = mockGitHub.getRequestCount();
874-
compareCommitsBetween(repository);
874+
GHCompare compare = repository.getCompare("e46a9f3f2ac55db96de3c5c4706f2813b3a96465",
875+
"8051615eff597f4e49f4f47625e6fc2b49f26bfc");
876+
int actualCount = 0;
877+
for (GHCompare.Commit item : compare.listCommits().withPageSize(5)) {
878+
assertThat(item, notNullValue());
879+
actualCount++;
880+
}
881+
assertThat(compare.getTotalCommits(), is(9));
882+
assertThat(actualCount, is(9));
875883
assertThat(mockGitHub.getRequestCount(), equalTo(startingCount + 1));
876884
}
877885

878886
@Test
879-
public void getCommitsBetweenPaginated() throws Exception {
887+
public void listCommitsBetweenPaginated() throws Exception {
880888
GHRepository repository = getRepository();
881889
int startingCount = mockGitHub.getRequestCount();
882890
repository.setCompareUsePaginatedCommits(true);
883-
compareCommitsBetween(repository);
884-
assertThat(mockGitHub.getRequestCount(), equalTo(startingCount + 3));
885-
}
886-
887-
private void compareCommitsBetween(GHRepository repository) throws IOException {
888891
GHCompare compare = repository.getCompare("e46a9f3f2ac55db96de3c5c4706f2813b3a96465",
889892
"8051615eff597f4e49f4f47625e6fc2b49f26bfc");
890893
int actualCount = 0;
@@ -894,5 +897,40 @@ private void compareCommitsBetween(GHRepository repository) throws IOException {
894897
}
895898
assertThat(compare.getTotalCommits(), is(9));
896899
assertThat(actualCount, is(9));
900+
assertThat(mockGitHub.getRequestCount(), equalTo(startingCount + 3));
901+
}
902+
903+
@Test
904+
public void getCommitsBetweenOver250() throws Exception {
905+
GHRepository repository = getRepository();
906+
int startingCount = mockGitHub.getRequestCount();
907+
GHCompare compare = repository.getCompare("4261c42949915816a9f246eb14c3dfd21a637bc2",
908+
"94ff089e60064bfa43e374baeb10846f7ce82f40");
909+
int actualCount = 0;
910+
for (GHCompare.Commit item : compare.getCommits()) {
911+
assertThat(item, notNullValue());
912+
actualCount++;
913+
}
914+
assertThat(compare.getTotalCommits(), is(283));
915+
assertThat(actualCount, is(250));
916+
assertThat(mockGitHub.getRequestCount(), equalTo(startingCount + 1));
897917
}
918+
919+
@Test
920+
public void getCommitsBetweenPaginatedOver250() throws Exception {
921+
GHRepository repository = getRepository();
922+
int startingCount = mockGitHub.getRequestCount();
923+
repository.setCompareUsePaginatedCommits(true);
924+
GHCompare compare = repository.getCompare("4261c42949915816a9f246eb14c3dfd21a637bc2",
925+
"94ff089e60064bfa43e374baeb10846f7ce82f40");
926+
int actualCount = 0;
927+
for (GHCompare.Commit item : compare.getCommits()) {
928+
assertThat(item, notNullValue());
929+
actualCount++;
930+
}
931+
assertThat(compare.getTotalCommits(), is(283));
932+
assertThat(actualCount, is(283));
933+
assertThat(mockGitHub.getRequestCount(), equalTo(startingCount + 4));
934+
}
935+
898936
}
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
"deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments",
199199
"created_at": "2010-04-19T04:13:03Z",
200200
"updated_at": "2021-09-06T01:04:31Z",
201-
"pushed_at": "2021-09-06T01:11:49Z",
201+
"pushed_at": "2021-09-06T06:50:01Z",
202202
"git_url": "git://github.com/hub4j/github-api.git",
203203
"ssh_url": "git@github.com:hub4j/github-api.git",
204204
"clone_url": "https://github.com/hub4j/github-api.git",
@@ -298,7 +298,7 @@
298298
"deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments",
299299
"created_at": "2010-04-19T04:13:03Z",
300300
"updated_at": "2021-09-06T01:04:31Z",
301-
"pushed_at": "2021-09-06T01:11:49Z",
301+
"pushed_at": "2021-09-06T06:50:01Z",
302302
"git_url": "git://github.com/hub4j/github-api.git",
303303
"ssh_url": "git@github.com:hub4j/github-api.git",
304304
"clone_url": "https://github.com/hub4j/github-api.git",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.