Skip to content
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
42 changes: 37 additions & 5 deletions src/main/java/com/spotify/github/v3/clients/IssueClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public class IssueClient {
static final String COMMENTS_URI_TEMPLATE = "/repos/%s/%s/issues/comments";
static final String COMMENTS_URI_ID_TEMPLATE = "/repos/%s/%s/issues/comments/%s";
static final String COMMENTS_REACTION_TEMPLATE = "/repos/%s/%s/issues/comments/%s/reactions";
static final String COMMENTS_REACTION_ID_TEMPLATE = "/repos/%s/%s/issues/%s/reactions/%s";
static final String COMMENTS_REACTION_ID_TEMPLATE = "/repos/%s/%s/issues/comments/%s/reactions/%s";
static final String ISSUES_REACTION_TEMPLATE = "/repos/%s/%s/issues/%s/reactions";
static final String ISSUES_REACTION_ID_TEMPLATE = "/repos/%s/%s/issues/%s/reactions/%s";
static final String ISSUES_URI_ID_TEMPLATE = "/repos/%s/%s/issues/%s";
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

Expand All @@ -53,7 +55,6 @@ public class IssueClient {

/**
* Constructs an IssueClient.
*
* @param github the GitHub client
* @param owner the repository owner
* @param repo the repository name
Expand Down Expand Up @@ -260,14 +261,14 @@ public CompletableFuture<CommentReaction> createCommentReaction(
* href="https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#delete-an-issue-comment-reaction">List
* reactions for an issue comment</a>
*
* @param issueNumber the issue number
* @param commentId the comment id
* @param reactionId the reaction id
* @return a CompletableFuture containing the HTTP response
*/
public CompletableFuture<HttpResponse> deleteCommentReaction(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one incorrectly deleted an issue reaction instead of an issue comment reaction, like the method name suggests

final long issueNumber, final long reactionId) {
final long commentId, final long reactionId) {
final String path =
String.format(COMMENTS_REACTION_ID_TEMPLATE, owner, repo, issueNumber, reactionId);
String.format(COMMENTS_REACTION_ID_TEMPLATE, owner, repo, commentId, reactionId);
return github.delete(path);
}

Expand All @@ -284,4 +285,35 @@ public GithubPageIterator<CommentReaction> listCommentReaction(final long commen
return new GithubPageIterator<>(
new GithubPage<>(github, path, LIST_COMMENT_REACTION_TYPE_REFERENCE));
}

/**
* Creates a reaction on an issue.
*
* @param issueNumber the issue number
* @param reaction the reaction content
* @return a CompletableFuture containing the created reaction
*/
public CompletableFuture<CommentReaction> createIssueReaction(
final long issueNumber, final CommentReactionContent reaction) {
final String path = String.format(ISSUES_REACTION_TEMPLATE, owner, repo, issueNumber);
final String requestBody =
github.json().toJsonUnchecked(ImmutableMap.of("content", reaction.toString()));
return github.post(path, requestBody, CommentReaction.class);
}

/**
* Deletes a reaction on an issue. See <a
* href="https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#delete-an-issue-reaction">Delete
* an issue reaction</a>
*
* @param issueNumber the issue number
* @param reactionId the reaction id
* @return a CompletableFuture containing the HTTP response
*/
public CompletableFuture<HttpResponse> deleteIssueReaction(
final long issueNumber, final long reactionId) {
final String path =
String.format(ISSUES_REACTION_ID_TEMPLATE, owner, repo, issueNumber, reactionId);
return github.delete(path);
}
}
49 changes: 46 additions & 3 deletions src/test/java/com/spotify/github/v3/clients/IssueClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ public void testCreateIssueCommentReaction(CommentReactionContent reaction) {

@Test
public void testDeleteIssueCommentReaction() {
long issueNumber = 42;
long commentId = 42;
long reactionId = 385825;
final String path =
format(COMMENTS_REACTION_ID_TEMPLATE, "someowner", "somerepo", issueNumber, reactionId);
format(COMMENTS_REACTION_ID_TEMPLATE, "someowner", "somerepo", commentId, reactionId);
HttpResponse mockResponse = mock(HttpResponse.class);
when(mockResponse.statusCode()).thenReturn(204);
when(github.delete(eq(path))).thenReturn(completedFuture(mockResponse));

final var response = issueClient.deleteCommentReaction(issueNumber, reactionId).join();
final var response = issueClient.deleteCommentReaction(commentId, reactionId).join();

assertThat(response.statusCode(), is(204));
assertThat(response, is(mockResponse));
Expand Down Expand Up @@ -271,6 +271,49 @@ public void testListIssueCommentReaction() throws IOException {
verify(github, atLeastOnce()).request(eq(path));
}

@ParameterizedTest
@EnumSource(CommentReactionContent.class)
public void testCreateIssueReaction(CommentReactionContent reaction) {
long issueNumber = 42;
final CompletableFuture<CommentReaction> reactionResponse =
completedFuture(
ImmutableCommentReaction.builder()
.id(123L)
.content(reaction)
.user(ImmutableUser.builder().login("octocat").build())
.build());
final String path = format(ISSUES_REACTION_TEMPLATE, "someowner", "somerepo", issueNumber);
final String requestBody =
github.json().toJsonUnchecked(ImmutableMap.of("content", reaction.toString()));
when(github.post(eq(path), eq(requestBody), eq(CommentReaction.class)))
.thenReturn(reactionResponse);

final var issueReaction = issueClient.createIssueReaction(issueNumber, reaction).join();

assertThat(issueReaction.id(), is(123L));
assertNotNull(issueReaction.user());
assertThat(issueReaction.user().login(), is("octocat"));
assertThat(issueReaction.content().toString(), is(reaction.toString()));
verify(github, times(1)).post(eq(path), eq(requestBody), eq(CommentReaction.class));
}

@Test
public void testDeleteIssueReaction() {
long issueNumber = 42;
long reactionId = 385825;
final String path =
format(ISSUES_REACTION_ID_TEMPLATE, "someowner", "somerepo", issueNumber, reactionId);
HttpResponse mockResponse = mock(HttpResponse.class);
when(mockResponse.statusCode()).thenReturn(204);
when(github.delete(eq(path))).thenReturn(completedFuture(mockResponse));

final var response = issueClient.deleteIssueReaction(issueNumber, reactionId).join();

assertThat(response.statusCode(), is(204));
assertThat(response, is(mockResponse));
verify(github, times(1)).delete(eq(path));
}

@Test
public void testGetIssueNoIssue() {
final String path = format(ISSUES_URI_ID_TEMPLATE, "someowner", "somerepo", 2);
Expand Down