Skip to content

Commit 30abc05

Browse files
committed
feat: Add Issue Comment Reaction functionality
1 parent c4a4e64 commit 30abc05

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

β€Žsrc/main/java/com/spotify/github/v3/clients/IssueClient.javaβ€Ž

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@
2626
import com.google.common.collect.ImmutableMap;
2727
import com.spotify.github.async.AsyncPage;
2828
import com.spotify.github.v3.comment.Comment;
29+
import com.spotify.github.v3.comment.CommentReaction;
30+
import com.spotify.github.v3.comment.CommentReactionContent;
2931
import com.spotify.github.v3.issues.Issue;
3032
import java.lang.invoke.MethodHandles;
3133
import java.util.Iterator;
3234
import java.util.concurrent.CompletableFuture;
35+
36+
import okhttp3.Response;
3337
import org.slf4j.Logger;
3438
import org.slf4j.LoggerFactory;
3539

@@ -39,6 +43,8 @@ public class IssueClient {
3943
static final String COMMENTS_URI_NUMBER_TEMPLATE = "/repos/%s/%s/issues/%s/comments";
4044
static final String COMMENTS_URI_TEMPLATE = "/repos/%s/%s/issues/comments";
4145
static final String COMMENTS_URI_ID_TEMPLATE = "/repos/%s/%s/issues/comments/%s";
46+
static final String COMMENTS_REACTION_TEMPLATE = "/repos/%s/%s/issues/comments/%s/reactions";
47+
static final String COMMENTS_REACTION_ID_TEMPLATE = "/repos/%s/%s/issues/%s/reactions/%s";
4248
static final String ISSUES_URI_ID_TEMPLATE = "/repos/%s/%s/issues/%s";
4349
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
4450

@@ -137,4 +143,23 @@ private Iterator<AsyncPage<Comment>> listComments(final String path) {
137143
public CompletableFuture<Issue> getIssue(final int id) {
138144
return github.request(String.format(ISSUES_URI_ID_TEMPLATE, owner, repo, id), Issue.class);
139145
}
146+
147+
/**
148+
* Create a reaction on a comment.
149+
*
150+
* @param commentId comment id
151+
* @param reaction reaction content
152+
* @return the Comment that was just created
153+
*/
154+
public CompletableFuture<CommentReaction> createCommentReaction(final long commentId, final CommentReactionContent reaction) {
155+
final String path = String.format(COMMENTS_REACTION_TEMPLATE, owner, repo, commentId);
156+
final String requestBody = github.json().toJsonUnchecked(ImmutableMap.of("content", reaction));
157+
return github.post(path, requestBody, CommentReaction.class);
158+
}
159+
160+
public CompletableFuture<Response> deleteCommentReaction(final long issueNumber, final long reactionId) {
161+
final String path = String.format(COMMENTS_REACTION_ID_TEMPLATE, owner, repo, issueNumber, reactionId);
162+
final String requestBody = github.json().toJsonUnchecked("");
163+
return github.delete(path, requestBody);
164+
}
140165
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*-
2+
* -\-\-
3+
* github-api
4+
* --
5+
* Copyright (C) 2016 - 2020 Spotify AB
6+
* --
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* -/-/-
19+
*/
20+
package com.spotify.github.v3.comment;
21+
22+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
23+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
24+
import com.spotify.github.GithubStyle;
25+
import com.spotify.github.UpdateTracking;
26+
import com.spotify.github.v3.User;
27+
import org.immutables.value.Value;
28+
29+
@Value.Immutable
30+
@GithubStyle
31+
@JsonSerialize(as = ImmutableComment.class)
32+
@JsonDeserialize(as = ImmutableComment.class)
33+
public interface CommentReaction extends UpdateTracking {
34+
35+
/** Reaction ID. */
36+
long id();
37+
38+
/** Reaction user. */
39+
User user();
40+
41+
/** Reaction content. */
42+
CommentReactionContent content();
43+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*-
2+
* -\-\-
3+
* github-api
4+
* --
5+
* Copyright (C) 2016 - 2020 Spotify AB
6+
* --
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* -/-/-
19+
*/
20+
package com.spotify.github.v3.comment;
21+
22+
public enum CommentReactionContent {
23+
THUMBS_UP("+1"), // πŸ‘
24+
THUMBS_DOWN("-1"), // πŸ‘Ž
25+
LAUGH("laugh"), // πŸ˜„
26+
HOORAY("hooray"), // πŸŽ‰
27+
CONFUSED("confused"), // πŸ˜•
28+
HEART("heart"), // ❀️
29+
ROCKET("rocket"), // πŸš€
30+
EYES("eyes"); // πŸ‘€
31+
32+
private final String reaction;
33+
34+
CommentReactionContent(final String reaction) {
35+
this.reaction = reaction;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return reaction;
41+
}
42+
}

0 commit comments

Comments
Β (0)