Skip to content

Commit 5ea8638

Browse files
authored
Merge branch 'main' into repo_search_by_fork_and_visibility
2 parents 18625d7 + b3f4c6b commit 5ea8638

File tree

91 files changed

+3532
-641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+3532
-641
lines changed

src/main/java/org/kohsuke/github/GHCommit.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,15 @@ public String getSHA1() {
351351
return sha;
352352
}
353353

354+
/**
355+
* Gets url.
356+
*
357+
* @return API URL of this object.
358+
*/
359+
public URL getUrl() {
360+
return GitHubClient.parseURL(url);
361+
}
362+
354363
/**
355364
* List of files changed/added/removed in this commit.
356365
*
@@ -392,6 +401,7 @@ public int size() {
392401
* on error
393402
*/
394403
public List<GHCommit> getParents() throws IOException {
404+
populate();
395405
List<GHCommit> r = new ArrayList<GHCommit>();
396406
for (String sha1 : getParentSHA1s())
397407
r.add(owner.getCommit(sha1));
@@ -406,6 +416,7 @@ public List<GHCommit> getParents() throws IOException {
406416
* the io exception
407417
*/
408418
public GHUser getAuthor() throws IOException {
419+
populate();
409420
return resolveUser(author);
410421
}
411422

@@ -428,6 +439,7 @@ public Date getAuthoredDate() throws IOException {
428439
* the io exception
429440
*/
430441
public GHUser getCommitter() throws IOException {
442+
populate();
431443
return resolveUser(committer);
432444
}
433445

@@ -485,10 +497,7 @@ public PagedIterable<GHBranch> listBranchesWhereHead() throws IOException {
485497
* @return {@link PagedIterable} with all the commit comments in this repository.
486498
*/
487499
public PagedIterable<GHCommitComment> listComments() {
488-
return owner.root.createRequest()
489-
.withUrlPath(
490-
String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha))
491-
.toIterable(GHCommitComment[].class, item -> item.wrap(owner));
500+
return owner.listCommitComments(sha);
492501
}
493502

494503
/**

src/main/java/org/kohsuke/github/GHPullRequest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,13 @@ public void refresh() throws IOException {
388388
}
389389

390390
/**
391-
* Retrieves all the files associated to this pull request.
391+
* Retrieves all the files associated to this pull request. The paginated response returns 30 files per page by
392+
* default.
392393
*
393394
* @return the paged iterable
395+
*
396+
* @see <a href="https://docs.github.com/en/rest/reference/pulls#list-pull-requests-files">List pull requests
397+
* files</a>
394398
*/
395399
public PagedIterable<GHPullRequestFileDetail> listFiles() {
396400
return root.createRequest()

src/main/java/org/kohsuke/github/GHPullRequestFileDetail.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*
3131
* @author Julien Henry
3232
* @see GHPullRequest#listFiles() GHPullRequest#listFiles()
33+
* @see <a href="https://docs.github.com/en/rest/reference/pulls#list-pull-requests-files">List pull requests files</a>
3334
*/
3435
public class GHPullRequestFileDetail {
3536

@@ -46,7 +47,10 @@ public class GHPullRequestFileDetail {
4647
String previous_filename;
4748

4849
/**
49-
* Gets sha.
50+
* Gets sha of the file (not commit sha).
51+
*
52+
* @see <a href="https://docs.github.com/en/rest/reference/pulls#list-pull-requests-files">List pull requests
53+
* files</a>
5054
*
5155
* @return the sha
5256
*/
@@ -64,7 +68,7 @@ public String getFilename() {
6468
}
6569

6670
/**
67-
* Gets status.
71+
* Gets status (added/modified/deleted)
6872
*
6973
* @return the status
7074
*/

src/test/java/org/kohsuke/github/AppTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,16 @@ public void testCommit() throws Exception {
488488
assertThat(commit.getFiles().size(), equalTo(1));
489489
assertThat(commit.getHtmlUrl().toString(),
490490
equalTo("https://github.com/jenkinsci/jenkins/commit/08c1c9970af4d609ae754fbe803e06186e3206f7"));
491+
assertThat(commit.getLinesAdded(), equalTo(40));
492+
assertThat(commit.getLinesChanged(), equalTo(48));
493+
assertThat(commit.getLinesDeleted(), equalTo(8));
494+
assertThat(commit.getParentSHA1s().size(), equalTo(1));
495+
assertThat(commit.getAuthoredDate(), equalTo(GitHubClient.parseDate("2012-04-24T00:16:52Z")));
496+
assertThat(commit.getCommitDate(), equalTo(GitHubClient.parseDate("2012-04-24T00:16:52Z")));
497+
assertThat(commit.getCommitShortInfo().getCommentCount(), equalTo(0));
498+
assertThat(commit.getCommitShortInfo().getAuthoredDate(), equalTo(commit.getAuthoredDate()));
499+
assertThat(commit.getCommitShortInfo().getCommitDate(), equalTo(commit.getCommitDate()));
500+
assertThat(commit.getCommitShortInfo().getMessage(), equalTo("creating an RC branch"));
491501

492502
File f = commit.getFiles().get(0);
493503
assertThat(f.getLinesChanged(), equalTo(48));
@@ -543,6 +553,8 @@ public void testCreateCommitComment() throws Exception {
543553
GHCommit commit = gitHub.getUser("kohsuke")
544554
.getRepository("sandbox-ant")
545555
.getCommit("8ae38db0ea5837313ab5f39d43a6f73de3bd9000");
556+
557+
assertThat(commit.getCommitShortInfo().getCommentCount(), equalTo(30));
546558
GHCommitComment c = commit.createComment("[testing](http://kohsuse.org/)");
547559
try {
548560
assertThat(c.getPath(), nullValue());
@@ -554,6 +566,13 @@ public void testCreateCommitComment() throws Exception {
554566

555567
c.update("updated text");
556568
assertThat(c.getBody(), equalTo("updated text"));
569+
570+
commit = gitHub.getUser("kohsuke")
571+
.getRepository("sandbox-ant")
572+
.getCommit("8ae38db0ea5837313ab5f39d43a6f73de3bd9000");
573+
574+
assertThat(commit.getCommitShortInfo().getCommentCount(), equalTo(31));
575+
557576
} finally {
558577
c.delete();
559578
}

src/test/java/org/kohsuke/github/CommitTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ public void testQueryCommits() throws Exception {
4444
.list()
4545
.toList();
4646

47-
assertThat(commits.get(0).getSHA1(), equalTo("1cccddb22e305397151b2b7b87b4b47d74ca337b"));
4847
assertThat(commits.size(), equalTo(29));
4948

49+
GHCommit commit = commits.get(0);
50+
assertThat(commit.getSHA1(), equalTo("1cccddb22e305397151b2b7b87b4b47d74ca337b"));
51+
5052
commits = gitHub.getUser("jenkinsci")
5153
.getRepository("jenkins")
5254
.queryCommits()

src/test/java/org/kohsuke/github/GHContentIntegrationTest.java

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.List;
1313

1414
import static org.hamcrest.Matchers.*;
15+
import static org.hamcrest.Matchers.equalTo;
1516

1617
/**
1718
* Integration test for {@link GHContent}.
@@ -89,14 +90,52 @@ public void testCRUDContent() throws Exception {
8990
GHContentUpdateResponse created = repo.createContent("this is an awesome file I created\n",
9091
"Creating a file for integration tests.",
9192
createdFilename);
93+
int expectedRequestCount = mockGitHub.getRequestCount();
9294
GHContent createdContent = created.getContent();
9395

96+
assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
9497
assertThat(created.getCommit(), notNullValue());
9598
assertThat(created.getContent(), notNullValue());
96-
assertThat(createdContent.getContent(), notNullValue());
99+
97100
assertThat(createdContent.getPath(), equalTo(createdFilename));
101+
assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
102+
103+
assertThat(createdContent.getContent(), notNullValue());
98104
assertThat(createdContent.getContent(), equalTo("this is an awesome file I created\n"));
99105

106+
;
107+
assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
108+
109+
assertThat(created.getCommit().getSHA1(), notNullValue());
110+
assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
111+
assertThat(created.getCommit().getUrl().toString(),
112+
endsWith(
113+
"/repos/hub4j-test-org/GHContentIntegrationTest/git/commits/" + created.getCommit().getSHA1()));
114+
115+
assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
116+
117+
assertThat(created.getCommit().getCommitShortInfo().getMessage(),
118+
equalTo("Creating a file for integration tests."));
119+
120+
assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
121+
122+
assertThat(created.getCommit().getAuthor().getName(), equalTo("Liam Newman"));
123+
assertThat(created.getCommit().getAuthor().getEmail(), equalTo("[email protected]"));
124+
assertThat(created.getCommit().getCommitter().getName(), equalTo("Liam Newman"));
125+
assertThat(created.getCommit().getCommitter().getEmail(), equalTo("[email protected]"));
126+
127+
assertThat("Resolving GHUser", mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
128+
129+
assertThat(created.getCommit().getTree().getSha(), notNullValue());
130+
131+
assertThat("Resolving GHTree", mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
132+
133+
assertThat(created.getCommit().getTree().getUrl().toString(),
134+
endsWith("/repos/hub4j-test-org/GHContentIntegrationTest/git/trees/"
135+
+ created.getCommit().getTree().getSha()));
136+
137+
assertThat("Resolving GHTree is not cached", mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 2));
138+
100139
GHContent content = repo.getFileContent(createdFilename);
101140
assertThat(content, is(notNullValue()));
102141
assertThat(content.getSha(), equalTo(createdContent.getSha()));
@@ -113,15 +152,56 @@ public void testCRUDContent() throws Exception {
113152

114153
GHContentUpdateResponse updatedContentResponse = createdContent.update("this is some new content\n",
115154
"Updated file for integration tests.");
155+
156+
expectedRequestCount = mockGitHub.getRequestCount();
157+
116158
GHContent updatedContent = updatedContentResponse.getContent();
117159

160+
assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
161+
118162
assertThat(updatedContentResponse.getCommit(), notNullValue());
119163
assertThat(updatedContentResponse.getContent(), notNullValue());
164+
165+
assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
166+
120167
// due to what appears to be a cache propagation delay, this test is too flaky
121168
assertThat(new BufferedReader(new InputStreamReader(updatedContent.read())).readLine(),
122169
equalTo("this is some new content"));
123170
assertThat(updatedContent.getContent(), equalTo("this is some new content\n"));
124171

172+
assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
173+
174+
assertThat(updatedContentResponse.getCommit().getSHA1(), notNullValue());
175+
assertThat(updatedContentResponse.getCommit().getUrl().toString(),
176+
endsWith("/repos/hub4j-test-org/GHContentIntegrationTest/git/commits/"
177+
+ updatedContentResponse.getCommit().getSHA1()));
178+
179+
assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount));
180+
181+
assertThat(updatedContentResponse.getCommit().getCommitShortInfo().getMessage(),
182+
equalTo("Updated file for integration tests."));
183+
184+
assertThat(mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
185+
186+
assertThat(updatedContentResponse.getCommit().getAuthor().getName(), equalTo("Liam Newman"));
187+
assertThat(updatedContentResponse.getCommit().getAuthor().getEmail(), equalTo("[email protected]"));
188+
assertThat(updatedContentResponse.getCommit().getCommitter().getName(), equalTo("Liam Newman"));
189+
assertThat(updatedContentResponse.getCommit().getCommitter().getEmail(), equalTo("[email protected]"));
190+
191+
assertThat("Resolving GHUser - was already resolved",
192+
mockGitHub.getRequestCount(),
193+
equalTo(expectedRequestCount));
194+
195+
assertThat(updatedContentResponse.getCommit().getTree().getSha(), notNullValue());
196+
197+
assertThat("Resolving GHTree", mockGitHub.getRequestCount(), equalTo(expectedRequestCount += 1));
198+
199+
assertThat(updatedContentResponse.getCommit().getTree().getUrl().toString(),
200+
endsWith("/repos/hub4j-test-org/GHContentIntegrationTest/git/trees/"
201+
+ updatedContentResponse.getCommit().getTree().getSha()));
202+
203+
assertThat("Resolving GHTree is not cached", mockGitHub.getRequestCount(), equalTo(expectedRequestCount + 2));
204+
125205
GHContentUpdateResponse deleteResponse = updatedContent.delete("Enough of this foolishness!");
126206

127207
assertThat(deleteResponse.getCommit(), notNullValue());
@@ -133,7 +213,7 @@ public void testCRUDContent() throws Exception {
133213
} catch (GHFileNotFoundException e) {
134214
assertThat(e.getMessage(),
135215
endsWith(
136-
"/repos/hub4j-test-org/GHContentIntegrationTest/contents/test+directory%20%2350/test%20file-to+create-%231.txt {\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3/repos/contents/#get-contents\"}"));
216+
"/repos/hub4j-test-org/GHContentIntegrationTest/contents/test+directory%20%2350/test%20file-to+create-%231.txt {\"message\":\"Not Found\",\"documentation_url\":\"https://docs.github.com/rest/reference/repos#get-repository-content\"}"));
137217
}
138218
}
139219

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ public void listCommitCommentsNoComments() throws IOException {
411411
.toList();
412412

413413
assertThat("Commit has no comments", commitComments.isEmpty());
414+
415+
commitComments = getRepository().getCommit("c413fc1e3057332b93850ea48202627d29a37de5").listComments().toList();
416+
417+
assertThat("Commit has no comments", commitComments.isEmpty());
414418
}
415419

416420
@Test
@@ -480,6 +484,14 @@ public void listCommitCommentsSomeComments() throws IOException {
480484
assertThat("Comment text found",
481485
commitComments.stream().map(GHCommitComment::getBody).collect(Collectors.toList()),
482486
containsInAnyOrder("comment 1", "comment 2"));
487+
488+
commitComments = getRepository().getCommit("499d91f9f846b0087b2a20cf3648b49dc9c2eeef").listComments().toList();
489+
490+
assertThat("Two comments present", commitComments.size(), equalTo(2));
491+
assertThat("Comment text found",
492+
commitComments.stream().map(GHCommitComment::getBody).collect(Collectors.toList()),
493+
containsInAnyOrder("comment 1", "comment 2"));
494+
483495
}
484496

485497
@Test // Issue #261

src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateCommitComment/__files/repos_kohsuke_sandbox-ant-3.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"forks": 2,
9191
"open_issues": 0,
9292
"watchers": 2,
93-
"default_branch": "main",
93+
"default_branch": "master",
9494
"permissions": {
9595
"admin": false,
9696
"push": false,
@@ -189,7 +189,7 @@
189189
"forks": 4,
190190
"open_issues": 0,
191191
"watchers": 4,
192-
"default_branch": "main"
192+
"default_branch": "master"
193193
},
194194
"source": {
195195
"id": 3231216,
@@ -283,7 +283,7 @@
283283
"forks": 4,
284284
"open_issues": 0,
285285
"watchers": 4,
286-
"default_branch": "main"
286+
"default_branch": "master"
287287
},
288288
"network_count": 4,
289289
"subscribers_count": 0

0 commit comments

Comments
 (0)