Skip to content

Commit 63fda35

Browse files
authored
Merge pull request #953 from tginiotis-at-work/commentsOnCommit
Get comments on a specific commit
2 parents 6a2381c + 2f151d4 commit 63fda35

13 files changed

+1138
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,20 @@ public PagedIterable<GHCommitComment> listCommitComments() {
17881788
.toIterable(GHCommitComment[].class, item -> item.wrap(this));
17891789
}
17901790

1791+
/**
1792+
* Lists all comments on a specific commit.
1793+
*
1794+
* @param commitSha
1795+
* the hash of the commit
1796+
*
1797+
* @return the paged iterable
1798+
*/
1799+
public PagedIterable<GHCommitComment> listCommitComments(String commitSha) {
1800+
return root.createRequest()
1801+
.withUrlPath(String.format("/repos/%s/%s/commits/%s/comments", getOwnerName(), name, commitSha))
1802+
.toIterable(GHCommitComment[].class, item -> item.wrap(this));
1803+
}
1804+
17911805
/**
17921806
* Gets the basic license details for the repository.
17931807
* <p>

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,26 @@ public void listLanguages() throws IOException {
286286
assertTrue(r.listLanguages().containsKey(mainLanguage));
287287
}
288288

289+
@Test
290+
public void listCommitCommentsNoComments() throws IOException {
291+
List<GHCommitComment> commitComments = getRepository()
292+
.listCommitComments("c413fc1e3057332b93850ea48202627d29a37de5")
293+
.toList();
294+
295+
assertThat("Commit has no comments", commitComments.isEmpty());
296+
}
297+
298+
@Test
299+
public void listCommitCommentsSomeComments() throws IOException {
300+
List<GHCommitComment> commitComments = getRepository()
301+
.listCommitComments("499d91f9f846b0087b2a20cf3648b49dc9c2eeef")
302+
.toList();
303+
304+
assertThat("Two comments present", commitComments.size() == 2);
305+
assertThat("Comment text found", commitComments.stream().anyMatch(it -> it.body.equals("comment 1")));
306+
assertThat("Comment text found", commitComments.stream().anyMatch(it -> it.body.equals("comment 2")));
307+
}
308+
289309
@Test // Issue #261
290310
public void listEmptyContributors() throws IOException {
291311
for (GHRepository.Contributor c : gitHub.getRepository(GITHUB_API_TEST_ORG + "/empty").listContributors()) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"login": "hub4j-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/hub4j-test-org",
6+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
13+
"description": "Hub4j Test Org Description (this could be null or blank too)",
14+
"name": "Hub4j Test Org Name (this could be null or blank too)",
15+
"company": null,
16+
"blog": "https://hub4j.url.io/could/be/null",
17+
"location": "Hub4j Test Org Location (this could be null or blank too)",
18+
"email": "hub4jtestorgemail@could.be.null.com",
19+
"twitter_username": null,
20+
"is_verified": false,
21+
"has_organization_projects": true,
22+
"has_repository_projects": true,
23+
"public_repos": 13,
24+
"public_gists": 0,
25+
"followers": 0,
26+
"following": 0,
27+
"html_url": "https://github.com/hub4j-test-org",
28+
"created_at": "2014-05-10T19:39:11Z",
29+
"updated_at": "2020-06-04T05:56:10Z",
30+
"type": "Organization",
31+
"total_private_repos": 1,
32+
"owned_private_repos": 1,
33+
"private_gists": 0,
34+
"disk_usage": 152,
35+
"collaborators": 0,
36+
"billing_email": "kk@kohsuke.org",
37+
"default_repository_permission": "none",
38+
"members_can_create_repositories": false,
39+
"two_factor_requirement_enabled": false,
40+
"members_can_create_pages": true,
41+
"plan": {
42+
"name": "free",
43+
"space": 976562499,
44+
"private_repos": 10000,
45+
"filled_seats": 18,
46+
"seats": 3
47+
}
48+
}

src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/listCommitCommentsNoComments/__files/repos_hub4j-test-org_github-api-2.json

Lines changed: 332 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"id": "6b3332dd-61e6-44a9-9ba1-51108e0911e5",
3+
"name": "orgs_hub4j-test-org",
4+
"request": {
5+
"url": "/orgs/hub4j-test-org",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "orgs_hub4j-test-org-1.json",
16+
"headers": {
17+
"Date": "Wed, 30 Sep 2020 21:59:45 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Server": "GitHub.com",
20+
"Status": "200 OK",
21+
"Cache-Control": "private, max-age=60, s-maxage=60",
22+
"Vary": [
23+
"Accept, Authorization, Cookie, X-GitHub-OTP",
24+
"Accept-Encoding, Accept, X-Requested-With",
25+
"Accept-Encoding"
26+
],
27+
"ETag": "W/\"5c55d16bf1d59fa9c42072f73eac7e9484cb6b90e83ce9fecee1423b52bf612f\"",
28+
"Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT",
29+
"X-GitHub-Media-Type": "unknown, github.v3",
30+
"X-RateLimit-Limit": "5000",
31+
"X-RateLimit-Remaining": "4977",
32+
"X-RateLimit-Reset": "1601504639",
33+
"X-RateLimit-Used": "23",
34+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
35+
"X-Frame-Options": "deny",
36+
"X-Content-Type-Options": "nosniff",
37+
"X-XSS-Protection": "1; mode=block",
38+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
39+
"Content-Security-Policy": "default-src 'none'",
40+
"X-GitHub-Request-Id": "E5C8:F68A:39031FA:437AECB:5F74FFD1"
41+
}
42+
},
43+
"uuid": "6b3332dd-61e6-44a9-9ba1-51108e0911e5",
44+
"persistent": true,
45+
"insertionIndex": 1
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"id": "6588d869-e6c8-4252-9079-1c78bfad62ac",
3+
"name": "repos_hub4j-test-org_github-api",
4+
"request": {
5+
"url": "/repos/hub4j-test-org/github-api",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "repos_hub4j-test-org_github-api-2.json",
16+
"headers": {
17+
"Date": "Wed, 30 Sep 2020 21:59:46 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Server": "GitHub.com",
20+
"Status": "200 OK",
21+
"Cache-Control": "private, max-age=60, s-maxage=60",
22+
"Vary": [
23+
"Accept, Authorization, Cookie, X-GitHub-OTP",
24+
"Accept-Encoding, Accept, X-Requested-With",
25+
"Accept-Encoding"
26+
],
27+
"ETag": "W/\"c32c03afe688fbd2d55d3b412a9a0eabf62a16d2e6cbc36c7c65d66be5cffe96\"",
28+
"Last-Modified": "Wed, 10 Jun 2020 23:27:59 GMT",
29+
"X-GitHub-Media-Type": "unknown, github.v3",
30+
"X-RateLimit-Limit": "5000",
31+
"X-RateLimit-Remaining": "4976",
32+
"X-RateLimit-Reset": "1601504639",
33+
"X-RateLimit-Used": "24",
34+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
35+
"X-Frame-Options": "deny",
36+
"X-Content-Type-Options": "nosniff",
37+
"X-XSS-Protection": "1; mode=block",
38+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
39+
"Content-Security-Policy": "default-src 'none'",
40+
"X-GitHub-Request-Id": "E5C8:F68A:3903210:437AED4:5F74FFD1"
41+
}
42+
},
43+
"uuid": "6588d869-e6c8-4252-9079-1c78bfad62ac",
44+
"persistent": true,
45+
"insertionIndex": 2
46+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"id": "95256079-9c74-42ab-a6cb-3d8537062803",
3+
"name": "repos_hub4j-test-org_github-api_commits_c413fc1e3057332b93850ea48202627d29a37de5_comments",
4+
"request": {
5+
"url": "/repos/hub4j-test-org/github-api/commits/c413fc1e3057332b93850ea48202627d29a37de5/comments",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"body": "[]",
16+
"headers": {
17+
"Date": "Wed, 30 Sep 2020 21:59:46 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Server": "GitHub.com",
20+
"Status": "200 OK",
21+
"Cache-Control": "private, max-age=60, s-maxage=60",
22+
"Vary": [
23+
"Accept, Authorization, Cookie, X-GitHub-OTP",
24+
"Accept-Encoding, Accept, X-Requested-With",
25+
"Accept-Encoding"
26+
],
27+
"ETag": "\"c50e147b7d138def60de663ab6b95bb2ba89c474bfe67cce47ce2d74f28986ff\"",
28+
"X-GitHub-Media-Type": "unknown, github.v3",
29+
"X-RateLimit-Limit": "5000",
30+
"X-RateLimit-Remaining": "4975",
31+
"X-RateLimit-Reset": "1601504639",
32+
"X-RateLimit-Used": "25",
33+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
34+
"X-Frame-Options": "deny",
35+
"X-Content-Type-Options": "nosniff",
36+
"X-XSS-Protection": "1; mode=block",
37+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
38+
"Content-Security-Policy": "default-src 'none'",
39+
"X-GitHub-Request-Id": "E5C8:F68A:390321E:437AEF0:5F74FFD2"
40+
}
41+
},
42+
"uuid": "95256079-9c74-42ab-a6cb-3d8537062803",
43+
"persistent": true,
44+
"insertionIndex": 3
45+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"login": "hub4j-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/hub4j-test-org",
6+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
13+
"description": "Hub4j Test Org Description (this could be null or blank too)",
14+
"name": "Hub4j Test Org Name (this could be null or blank too)",
15+
"company": null,
16+
"blog": "https://hub4j.url.io/could/be/null",
17+
"location": "Hub4j Test Org Location (this could be null or blank too)",
18+
"email": "hub4jtestorgemail@could.be.null.com",
19+
"twitter_username": null,
20+
"is_verified": false,
21+
"has_organization_projects": true,
22+
"has_repository_projects": true,
23+
"public_repos": 13,
24+
"public_gists": 0,
25+
"followers": 0,
26+
"following": 0,
27+
"html_url": "https://github.com/hub4j-test-org",
28+
"created_at": "2014-05-10T19:39:11Z",
29+
"updated_at": "2020-06-04T05:56:10Z",
30+
"type": "Organization",
31+
"total_private_repos": 1,
32+
"owned_private_repos": 1,
33+
"private_gists": 0,
34+
"disk_usage": 152,
35+
"collaborators": 0,
36+
"billing_email": "kk@kohsuke.org",
37+
"default_repository_permission": "none",
38+
"members_can_create_repositories": false,
39+
"two_factor_requirement_enabled": false,
40+
"members_can_create_pages": true,
41+
"plan": {
42+
"name": "free",
43+
"space": 976562499,
44+
"private_repos": 10000,
45+
"filled_seats": 18,
46+
"seats": 3
47+
}
48+
}

0 commit comments

Comments
 (0)