Skip to content

Commit 82e3b5b

Browse files
committed
Add more coverage for GHCommit methods
1 parent 2248d58 commit 82e3b5b

File tree

49 files changed

+2316
-373
lines changed

Some content is hidden

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

49 files changed

+2316
-373
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,7 @@ public PagedIterable<GHBranch> listBranchesWhereHead() throws IOException {
497497
* @return {@link PagedIterable} with all the commit comments in this repository.
498498
*/
499499
public PagedIterable<GHCommitComment> listComments() {
500-
return owner.root.createRequest()
501-
.withUrlPath(
502-
String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha))
503-
.toIterable(GHCommitComment[].class, item -> item.wrap(owner));
500+
return owner.listCommitComments(sha);
504501
}
505502

506503
/**

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/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
@@ -423,6 +427,14 @@ public void listCommitCommentsSomeComments() throws IOException {
423427
assertThat("Comment text found",
424428
commitComments.stream().map(GHCommitComment::getBody).collect(Collectors.toList()),
425429
containsInAnyOrder("comment 1", "comment 2"));
430+
431+
commitComments = getRepository().getCommit("499d91f9f846b0087b2a20cf3648b49dc9c2eeef").listComments().toList();
432+
433+
assertThat("Two comments present", commitComments.size(), equalTo(2));
434+
assertThat("Comment text found",
435+
commitComments.stream().map(GHCommitComment::getBody).collect(Collectors.toList()),
436+
containsInAnyOrder("comment 1", "comment 2"));
437+
426438
}
427439

428440
@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)