Skip to content

Commit

Permalink
Merge pull request #953 from tginiotis-at-work/commentsOnCommit
Browse files Browse the repository at this point in the history
Get comments on a specific commit
  • Loading branch information
bitwiseman authored Nov 3, 2020
2 parents 6a2381c + 2f151d4 commit 63fda35
Show file tree
Hide file tree
Showing 13 changed files with 1,138 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,20 @@ public PagedIterable<GHCommitComment> listCommitComments() {
.toIterable(GHCommitComment[].class, item -> item.wrap(this));
}

/**
* Lists all comments on a specific commit.
*
* @param commitSha
* the hash of the commit
*
* @return the paged iterable
*/
public PagedIterable<GHCommitComment> listCommitComments(String commitSha) {
return root.createRequest()
.withUrlPath(String.format("/repos/%s/%s/commits/%s/comments", getOwnerName(), name, commitSha))
.toIterable(GHCommitComment[].class, item -> item.wrap(this));
}

/**
* Gets the basic license details for the repository.
* <p>
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,26 @@ public void listLanguages() throws IOException {
assertTrue(r.listLanguages().containsKey(mainLanguage));
}

@Test
public void listCommitCommentsNoComments() throws IOException {
List<GHCommitComment> commitComments = getRepository()
.listCommitComments("c413fc1e3057332b93850ea48202627d29a37de5")
.toList();

assertThat("Commit has no comments", commitComments.isEmpty());
}

@Test
public void listCommitCommentsSomeComments() throws IOException {
List<GHCommitComment> commitComments = getRepository()
.listCommitComments("499d91f9f846b0087b2a20cf3648b49dc9c2eeef")
.toList();

assertThat("Two comments present", commitComments.size() == 2);
assertThat("Comment text found", commitComments.stream().anyMatch(it -> it.body.equals("comment 1")));
assertThat("Comment text found", commitComments.stream().anyMatch(it -> it.body.equals("comment 2")));
}

@Test // Issue #261
public void listEmptyContributors() throws IOException {
for (GHRepository.Contributor c : gitHub.getRepository(GITHUB_API_TEST_ORG + "/empty").listContributors()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"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://avatars3.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": 13,
"public_gists": 0,
"followers": 0,
"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",
"total_private_repos": 1,
"owned_private_repos": 1,
"private_gists": 0,
"disk_usage": 152,
"collaborators": 0,
"billing_email": "[email protected]",
"default_repository_permission": "none",
"members_can_create_repositories": false,
"two_factor_requirement_enabled": false,
"members_can_create_pages": true,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 18,
"seats": 3
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": "6b3332dd-61e6-44a9-9ba1-51108e0911e5",
"name": "orgs_hub4j-test-org",
"request": {
"url": "/orgs/hub4j-test-org",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "orgs_hub4j-test-org-1.json",
"headers": {
"Date": "Wed, 30 Sep 2020 21:59:45 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With",
"Accept-Encoding"
],
"ETag": "W/\"5c55d16bf1d59fa9c42072f73eac7e9484cb6b90e83ce9fecee1423b52bf612f\"",
"Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4977",
"X-RateLimit-Reset": "1601504639",
"X-RateLimit-Used": "23",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "E5C8:F68A:39031FA:437AECB:5F74FFD1"
}
},
"uuid": "6b3332dd-61e6-44a9-9ba1-51108e0911e5",
"persistent": true,
"insertionIndex": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": "6588d869-e6c8-4252-9079-1c78bfad62ac",
"name": "repos_hub4j-test-org_github-api",
"request": {
"url": "/repos/hub4j-test-org/github-api",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "repos_hub4j-test-org_github-api-2.json",
"headers": {
"Date": "Wed, 30 Sep 2020 21:59:46 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With",
"Accept-Encoding"
],
"ETag": "W/\"c32c03afe688fbd2d55d3b412a9a0eabf62a16d2e6cbc36c7c65d66be5cffe96\"",
"Last-Modified": "Wed, 10 Jun 2020 23:27:59 GMT",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4976",
"X-RateLimit-Reset": "1601504639",
"X-RateLimit-Used": "24",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "E5C8:F68A:3903210:437AED4:5F74FFD1"
}
},
"uuid": "6588d869-e6c8-4252-9079-1c78bfad62ac",
"persistent": true,
"insertionIndex": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"id": "95256079-9c74-42ab-a6cb-3d8537062803",
"name": "repos_hub4j-test-org_github-api_commits_c413fc1e3057332b93850ea48202627d29a37de5_comments",
"request": {
"url": "/repos/hub4j-test-org/github-api/commits/c413fc1e3057332b93850ea48202627d29a37de5/comments",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"body": "[]",
"headers": {
"Date": "Wed, 30 Sep 2020 21:59:46 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With",
"Accept-Encoding"
],
"ETag": "\"c50e147b7d138def60de663ab6b95bb2ba89c474bfe67cce47ce2d74f28986ff\"",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4975",
"X-RateLimit-Reset": "1601504639",
"X-RateLimit-Used": "25",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "E5C8:F68A:390321E:437AEF0:5F74FFD2"
}
},
"uuid": "95256079-9c74-42ab-a6cb-3d8537062803",
"persistent": true,
"insertionIndex": 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"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://avatars3.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": 13,
"public_gists": 0,
"followers": 0,
"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",
"total_private_repos": 1,
"owned_private_repos": 1,
"private_gists": 0,
"disk_usage": 152,
"collaborators": 0,
"billing_email": "[email protected]",
"default_repository_permission": "none",
"members_can_create_repositories": false,
"two_factor_requirement_enabled": false,
"members_can_create_pages": true,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 18,
"seats": 3
}
}
Loading

0 comments on commit 63fda35

Please sign in to comment.