38
38
/** Issue API client */
39
39
public class IssueClient {
40
40
41
+ // URI templates for various API endpoints
41
42
static final String COMMENTS_URI_NUMBER_TEMPLATE = "/repos/%s/%s/issues/%s/comments" ;
42
43
static final String COMMENTS_URI_TEMPLATE = "/repos/%s/%s/issues/comments" ;
43
44
static final String COMMENTS_URI_ID_TEMPLATE = "/repos/%s/%s/issues/comments/%s" ;
@@ -50,106 +51,201 @@ public class IssueClient {
50
51
private final String owner ;
51
52
private final String repo ;
52
53
54
+ /**
55
+ * Constructs an IssueClient.
56
+ *
57
+ * @param github the GitHub client
58
+ * @param owner the repository owner
59
+ * @param repo the repository name
60
+ */
53
61
IssueClient (final GitHubClient github , final String owner , final String repo ) {
54
62
this .github = github ;
55
63
this .owner = owner ;
56
64
this .repo = repo ;
57
65
}
58
66
67
+ /**
68
+ * Creates an IssueClient.
69
+ *
70
+ * @param github the GitHub client
71
+ * @param owner the repository owner
72
+ * @param repo the repository name
73
+ * @return a new IssueClient instance
74
+ */
59
75
static IssueClient create (final GitHubClient github , final String owner , final String repo ) {
60
76
return new IssueClient (github , owner , repo );
61
77
}
62
78
63
79
/**
64
- * List repository comments.
80
+ * Lists repository comments.
65
81
*
66
- * @return comments
82
+ * @return an iterator of asynchronous pages of comments
67
83
*/
68
84
public Iterator <AsyncPage <Comment >> listComments () {
69
85
return listComments (String .format (COMMENTS_URI_TEMPLATE , owner , repo ));
70
86
}
71
87
72
88
/**
73
- * List given issue number comments.
89
+ * Lists comments for a given issue number.
90
+ *
91
+ * @param issueNumber the issue number
92
+ * @return an iterator of asynchronous pages of comments
93
+ */
94
+ public Iterator <AsyncPage <Comment >> listComments (final long issueNumber ) {
95
+ return listComments (String .format (COMMENTS_URI_NUMBER_TEMPLATE , owner , repo , issueNumber ));
96
+ }
97
+
98
+ /**
99
+ * Lists comments for a given issue number.
74
100
*
75
- * @param number issue number
76
- * @return comments
101
+ * @deprecated Use {@link #listComments(long)} instead
102
+ * @param issueNumber the issue number
103
+ * @return an iterator of asynchronous pages of comments
77
104
*/
78
- public Iterator <AsyncPage <Comment >> listComments (final int number ) {
79
- return listComments (String .format (COMMENTS_URI_NUMBER_TEMPLATE , owner , repo , number ));
105
+ @ Deprecated
106
+ public Iterator <AsyncPage <Comment >> listComments (final int issueNumber ) {
107
+ return listComments ((long ) issueNumber );
80
108
}
81
109
82
110
/**
83
- * Get a specific comment.
111
+ * Gets a specific comment.
84
112
*
85
- * @param id comment id
86
- * @return a comment
113
+ * @param commentId the comment id
114
+ * @return a CompletableFuture containing the comment
87
115
*/
88
- public CompletableFuture <Comment > getComment (final int id ) {
89
- final String path = String .format (COMMENTS_URI_ID_TEMPLATE , owner , repo , id );
116
+ public CompletableFuture <Comment > getComment (final long commentId ) {
117
+ final String path = String .format (COMMENTS_URI_ID_TEMPLATE , owner , repo , commentId );
90
118
log .info ("Fetching issue comments from " + path );
91
119
return github .request (path , Comment .class );
92
120
}
93
121
94
122
/**
95
- * Create a comment for a given issue number.
123
+ * Gets a specific comment.
124
+ *
125
+ * @deprecated Use {@link #getComment(long)} instead
126
+ * @param commentId the comment id
127
+ * @return a CompletableFuture containing the comment
128
+ */
129
+ @ Deprecated
130
+ public CompletableFuture <Comment > getComment (final int commentId ) {
131
+ return getComment ((long ) commentId );
132
+ }
133
+
134
+ /**
135
+ * Creates a comment for a given issue number.
96
136
*
97
- * @param number issue number
98
- * @param body comment content
99
- * @return the Comment that was just created
137
+ * @param issueNumber the issue number
138
+ * @param body the comment content
139
+ * @return a CompletableFuture containing the created comment
100
140
*/
101
- public CompletableFuture <Comment > createComment (final int number , final String body ) {
102
- final String path = String .format (COMMENTS_URI_NUMBER_TEMPLATE , owner , repo , number );
141
+ public CompletableFuture <Comment > createComment (final long issueNumber , final String body ) {
142
+ final String path = String .format (COMMENTS_URI_NUMBER_TEMPLATE , owner , repo , issueNumber );
103
143
final String requestBody = github .json ().toJsonUnchecked (ImmutableMap .of ("body" , body ));
104
144
return github .post (path , requestBody , Comment .class );
105
145
}
106
146
107
147
/**
108
- * Edit a specific comment.
148
+ * Creates a comment for a given issue number .
109
149
*
110
- * @param id comment id
111
- * @param body new comment content
150
+ * @deprecated Use {@link #createComment(long, String)} instead
151
+ * @param issueNumber the issue number
152
+ * @param body the comment content
153
+ * @return a CompletableFuture containing the created comment
112
154
*/
113
- public CompletableFuture <Void > editComment (final int id , final String body ) {
114
- final String path = String .format (COMMENTS_URI_ID_TEMPLATE , owner , repo , id );
155
+ @ Deprecated
156
+ public CompletableFuture <Comment > createComment (final int issueNumber , final String body ) {
157
+ return createComment ((long ) issueNumber , body );
158
+ }
159
+
160
+ /**
161
+ * Edits a specific comment.
162
+ *
163
+ * @param commentId the comment id
164
+ * @param body the new comment content
165
+ * @return a CompletableFuture representing the completion of the operation
166
+ */
167
+ public CompletableFuture <Void > editComment (final long commentId , final String body ) {
168
+ final String path = String .format (COMMENTS_URI_ID_TEMPLATE , owner , repo , commentId );
115
169
return github
116
170
.patch (path , github .json ().toJsonUnchecked (ImmutableMap .of ("body" , body )))
117
171
.thenAccept (IGNORE_RESPONSE_CONSUMER );
118
172
}
119
173
120
174
/**
121
- * Delete a comment.
175
+ * Edits a specific comment.
176
+ *
177
+ * @deprecated Use {@link #editComment(long, String)} instead
178
+ * @param commentId the comment id
179
+ * @param body the new comment content
180
+ * @return a CompletableFuture representing the completion of the operation
181
+ */
182
+ @ Deprecated
183
+ public CompletableFuture <Void > editComment (final int commentId , final String body ) {
184
+ return editComment ((long ) commentId , body );
185
+ }
186
+
187
+ /**
188
+ * Deletes a comment.
122
189
*
123
- * @param id comment id
190
+ * @param commentId the comment id
191
+ * @return a CompletableFuture representing the completion of the operation
124
192
*/
125
- public CompletableFuture <Void > deleteComment (final int id ) {
193
+ public CompletableFuture <Void > deleteComment (final long commentId ) {
126
194
return github
127
- .delete (String .format (COMMENTS_URI_ID_TEMPLATE , owner , repo , id ))
195
+ .delete (String .format (COMMENTS_URI_ID_TEMPLATE , owner , repo , commentId ))
128
196
.thenAccept (IGNORE_RESPONSE_CONSUMER );
129
197
}
130
198
199
+ /**
200
+ * Deletes a comment.
201
+ *
202
+ * @deprecated Use {@link #deleteComment(long)} instead
203
+ * @param commentId the comment id
204
+ * @return a CompletableFuture representing the completion of the operation
205
+ */
206
+ @ Deprecated
207
+ public CompletableFuture <Void > deleteComment (final int commentId ) {
208
+ return deleteComment ((long ) commentId );
209
+ }
210
+
211
+ /**
212
+ * Lists comments for a given path.
213
+ *
214
+ * @param path the API endpoint path
215
+ * @return an iterator of asynchronous pages of comments
216
+ */
131
217
private Iterator <AsyncPage <Comment >> listComments (final String path ) {
132
218
return new GithubPageIterator <>(new GithubPage <>(github , path , LIST_COMMENT_TYPE_REFERENCE ));
133
219
}
134
220
135
221
/**
136
- * Get issue by id
222
+ * Gets an issue by id.
223
+ *
224
+ * @param issueId the issue id
225
+ * @return a CompletableFuture containing the issue
226
+ */
227
+ public CompletableFuture <Issue > getIssue (final long issueId ) {
228
+ return github .request (String .format (ISSUES_URI_ID_TEMPLATE , owner , repo , issueId ), Issue .class );
229
+ }
230
+
231
+ /**
232
+ * Gets an issue by id.
137
233
*
138
- * @param id issue id
139
- * @return the Issue for the given id if exists.
234
+ * @deprecated Use {@link #getIssue(long)} instead
235
+ * @param issueId the issue id
236
+ * @return a CompletableFuture containing the issue
140
237
*/
141
- public CompletableFuture <Issue > getIssue (final int id ) {
142
- return github .request (String .format (ISSUES_URI_ID_TEMPLATE , owner , repo , id ), Issue .class );
238
+ @ Deprecated
239
+ public CompletableFuture <Issue > getIssue (final int issueId ) {
240
+ return getIssue ((long ) issueId );
143
241
}
144
242
145
243
/**
146
- * Create a reaction on a comment. See <a *
147
- * href="https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#create-reaction-for-an-issue-comment">Create
148
- * reaction for an issue comment</a>
244
+ * Creates a reaction on a comment.
149
245
*
150
- * @param commentId comment id
151
- * @param reaction reaction content
152
- * @return the Comment that was just created
246
+ * @param commentId the comment id
247
+ * @param reaction the reaction content
248
+ * @return a CompletableFuture containing the created reaction
153
249
*/
154
250
public CompletableFuture <CommentReaction > createCommentReaction (
155
251
final long commentId , final CommentReactionContent reaction ) {
@@ -160,12 +256,13 @@ public CompletableFuture<CommentReaction> createCommentReaction(
160
256
}
161
257
162
258
/**
163
- * Delete a reaction on a comment. See <a
259
+ * Deletes a reaction on a comment. See <a
164
260
* href="https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#delete-an-issue-comment-reaction">List
165
261
* reactions for an issue comment</a>
166
262
*
167
- * @param issueNumber issue number
168
- * @param reactionId reaction id
263
+ * @param issueNumber the issue number
264
+ * @param reactionId the reaction id
265
+ * @return a CompletableFuture containing the HTTP response
169
266
*/
170
267
public CompletableFuture <HttpResponse > deleteCommentReaction (
171
268
final long issueNumber , final long reactionId ) {
@@ -175,12 +272,12 @@ public CompletableFuture<HttpResponse> deleteCommentReaction(
175
272
}
176
273
177
274
/**
178
- * List reactions on a comment. See <a
275
+ * Lists reactions on a comment. See <a
179
276
* href="https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#list-reactions-for-an-issue-comment">List
180
277
* reactions for an issue comment</a>
181
278
*
182
- * @param commentId comment id
183
- * @return reactions
279
+ * @param commentId the comment id
280
+ * @return an iterator of asynchronous pages of comment reactions
184
281
*/
185
282
public GithubPageIterator <CommentReaction > listCommentReaction (final long commentId ) {
186
283
final String path = String .format (COMMENTS_REACTION_TEMPLATE , owner , repo , commentId );
0 commit comments