26
26
import com .google .common .collect .ImmutableMap ;
27
27
import com .spotify .github .async .AsyncPage ;
28
28
import com .spotify .github .v3 .comment .Comment ;
29
+ import com .spotify .github .v3 .comment .CommentReaction ;
30
+ import com .spotify .github .v3 .comment .CommentReactionContent ;
29
31
import com .spotify .github .v3 .issues .Issue ;
30
32
import java .lang .invoke .MethodHandles ;
31
33
import java .util .Iterator ;
32
34
import java .util .concurrent .CompletableFuture ;
35
+
36
+ import okhttp3 .Response ;
33
37
import org .slf4j .Logger ;
34
38
import org .slf4j .LoggerFactory ;
35
39
@@ -39,6 +43,8 @@ public class IssueClient {
39
43
static final String COMMENTS_URI_NUMBER_TEMPLATE = "/repos/%s/%s/issues/%s/comments" ;
40
44
static final String COMMENTS_URI_TEMPLATE = "/repos/%s/%s/issues/comments" ;
41
45
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" ;
42
48
static final String ISSUES_URI_ID_TEMPLATE = "/repos/%s/%s/issues/%s" ;
43
49
private static final Logger log = LoggerFactory .getLogger (MethodHandles .lookup ().lookupClass ());
44
50
@@ -137,4 +143,23 @@ private Iterator<AsyncPage<Comment>> listComments(final String path) {
137
143
public CompletableFuture <Issue > getIssue (final int id ) {
138
144
return github .request (String .format (ISSUES_URI_ID_TEMPLATE , owner , repo , id ), Issue .class );
139
145
}
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
+ }
140
165
}
0 commit comments