Skip to content

endpoint to list pr review comments #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/java/com/spotify/github/v3/clients/GitHubClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public class GitHubClient {
new TypeReference<>() {};
static final TypeReference<List<PullRequestItem>> LIST_PR_TYPE_REFERENCE =
new TypeReference<>() {};
static final TypeReference<List<com.spotify.github.v3.prs.Comment>>
LIST_PR_COMMENT_TYPE_REFERENCE = new TypeReference<>() {};
static final TypeReference<List<Branch>> LIST_BRANCHES = new TypeReference<>() {};
static final TypeReference<List<Reference>> LIST_REFERENCES = new TypeReference<>() {};
static final TypeReference<List<RepositoryInvitation>> LIST_REPOSITORY_INVITATION =
Expand All @@ -109,8 +111,7 @@ public class GitHubClient {
static final TypeReference<List<TeamInvitation>> LIST_PENDING_TEAM_INVITATIONS =
new TypeReference<>() {};

static final TypeReference<List<FileItem>> LIST_FILE_ITEMS =
new TypeReference<>() {};
static final TypeReference<List<FileItem>> LIST_FILE_ITEMS = new TypeReference<>() {};

private static final String GET_ACCESS_TOKEN_URL = "app/installations/%s/access_tokens";

Expand Down Expand Up @@ -1090,7 +1091,8 @@ private CompletableFuture<AccessToken> generateInstallationToken(
if (response.bodyString() == null) {
throw new RuntimeException(
String.format(
"Got empty response body when getting an access token from GitHub, HTTP status was: %s",
"Got empty response body when getting an access token from GitHub, HTTP"
+ " status was: %s",
response.statusMessage()));
}
final String text = response.bodyString();
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/spotify/github/v3/clients/PullRequestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static com.spotify.github.v3.clients.GitHubClient.IGNORE_RESPONSE_CONSUMER;
import static com.spotify.github.v3.clients.GitHubClient.LIST_COMMIT_TYPE_REFERENCE;
import static com.spotify.github.v3.clients.GitHubClient.LIST_FILE_ITEMS;
import static com.spotify.github.v3.clients.GitHubClient.LIST_PR_COMMENT_TYPE_REFERENCE;
import static com.spotify.github.v3.clients.GitHubClient.LIST_PR_TYPE_REFERENCE;
import static com.spotify.github.v3.clients.GitHubClient.LIST_REVIEW_REQUEST_TYPE_REFERENCE;
import static com.spotify.github.v3.clients.GitHubClient.LIST_REVIEW_TYPE_REFERENCE;
Expand Down Expand Up @@ -63,6 +64,7 @@ public class PullRequestClient {
private static final String PR_NUMBER_TEMPLATE = "/repos/%s/%s/pulls/%s";
private static final String PR_COMMITS_TEMPLATE = "/repos/%s/%s/pulls/%s/commits";
private static final String PR_REVIEWS_TEMPLATE = "/repos/%s/%s/pulls/%s/reviews";
private static final String PR_COMMENTS_TEMPLATE = "/repos/%s/%s/pulls/%s/comments";
private static final String PR_CHANGED_FILES_TEMPLATE = "/repos/%s/%s/pulls/%s/files";
private static final String PR_REVIEW_REQUESTS_TEMPLATE =
"/repos/%s/%s/pulls/%s/requested_reviewers";
Expand Down Expand Up @@ -467,6 +469,17 @@ private CompletableFuture<List<PullRequestItem>> list(final String parameterPath
return github.request(path, LIST_PR_TYPE_REFERENCE);
}

/**
* List pull request review comments.
*
* @param prNumber pull request number
* @return iterator of comments
*/
public Iterator<AsyncPage<Comment>> listComments(final long prNumber) {
final String path = String.format(PR_COMMENTS_TEMPLATE, owner, repo, prNumber);
return new GithubPageIterator<>(new GithubPage<>(github, path, LIST_PR_COMMENT_TYPE_REFERENCE));
}

/**
* Creates a reply to a pull request review comment.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,30 @@ void testChangedFiles() throws IOException {
assertEquals(actualFiles.get(0).filename(), expectedFiles.get(0).filename());
assertEquals(actualFiles.get(1).filename(), expectedFiles.get(1).filename());
}

@Test
public void testListComments() throws Throwable {
final String expectedBody = "[" + getFixture("pull_request_review_comment_reply.json") + "]";

final String pageLink =
"<https://github.com/api/v3/repos/owner/repo/pulls/1/comments>; rel=\"first\"";

final HttpResponse firstPageResponse = createMockResponse(pageLink, expectedBody);

when(mockGithub.request("/repos/owner/repo/pulls/1/comments"))
.thenReturn(completedFuture(firstPageResponse));

when(mockGithub.json()).thenReturn(github.json());

final PullRequestClient pullRequestClient =
PullRequestClient.create(mockGithub, "owner", "repo");

final Iterable<AsyncPage<Comment>> pageIterator = () -> pullRequestClient.listComments(1L);
List<Comment> comments = Async.streamFromPaginatingIterable(pageIterator).collect(toList());

assertEquals(1, comments.size());
assertThat(comments.get(0).body(), is("Great stuff!"));
assertThat(comments.get(0).id(), is(10L));
assertThat(comments.get(0).user().login(), is("octocat"));
}
}