Skip to content

Commit cbcbbad

Browse files
authored
fix: Fix the int vs long issue in IssueClient methods (#222)
1 parent 07a7513 commit cbcbbad

File tree

1 file changed

+141
-44
lines changed

1 file changed

+141
-44
lines changed

src/main/java/com/spotify/github/v3/clients/IssueClient.java

Lines changed: 141 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
/** Issue API client */
3939
public class IssueClient {
4040

41+
// URI templates for various API endpoints
4142
static final String COMMENTS_URI_NUMBER_TEMPLATE = "/repos/%s/%s/issues/%s/comments";
4243
static final String COMMENTS_URI_TEMPLATE = "/repos/%s/%s/issues/comments";
4344
static final String COMMENTS_URI_ID_TEMPLATE = "/repos/%s/%s/issues/comments/%s";
@@ -50,106 +51,201 @@ public class IssueClient {
5051
private final String owner;
5152
private final String repo;
5253

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+
*/
5361
IssueClient(final GitHubClient github, final String owner, final String repo) {
5462
this.github = github;
5563
this.owner = owner;
5664
this.repo = repo;
5765
}
5866

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+
*/
5975
static IssueClient create(final GitHubClient github, final String owner, final String repo) {
6076
return new IssueClient(github, owner, repo);
6177
}
6278

6379
/**
64-
* List repository comments.
80+
* Lists repository comments.
6581
*
66-
* @return comments
82+
* @return an iterator of asynchronous pages of comments
6783
*/
6884
public Iterator<AsyncPage<Comment>> listComments() {
6985
return listComments(String.format(COMMENTS_URI_TEMPLATE, owner, repo));
7086
}
7187

7288
/**
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.
74100
*
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
77104
*/
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);
80108
}
81109

82110
/**
83-
* Get a specific comment.
111+
* Gets a specific comment.
84112
*
85-
* @param id comment id
86-
* @return a comment
113+
* @param commentId the comment id
114+
* @return a CompletableFuture containing the comment
87115
*/
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);
90118
log.info("Fetching issue comments from " + path);
91119
return github.request(path, Comment.class);
92120
}
93121

94122
/**
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.
96136
*
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
100140
*/
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);
103143
final String requestBody = github.json().toJsonUnchecked(ImmutableMap.of("body", body));
104144
return github.post(path, requestBody, Comment.class);
105145
}
106146

107147
/**
108-
* Edit a specific comment.
148+
* Creates a comment for a given issue number.
109149
*
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
112154
*/
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);
115169
return github
116170
.patch(path, github.json().toJsonUnchecked(ImmutableMap.of("body", body)))
117171
.thenAccept(IGNORE_RESPONSE_CONSUMER);
118172
}
119173

120174
/**
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.
122189
*
123-
* @param id comment id
190+
* @param commentId the comment id
191+
* @return a CompletableFuture representing the completion of the operation
124192
*/
125-
public CompletableFuture<Void> deleteComment(final int id) {
193+
public CompletableFuture<Void> deleteComment(final long commentId) {
126194
return github
127-
.delete(String.format(COMMENTS_URI_ID_TEMPLATE, owner, repo, id))
195+
.delete(String.format(COMMENTS_URI_ID_TEMPLATE, owner, repo, commentId))
128196
.thenAccept(IGNORE_RESPONSE_CONSUMER);
129197
}
130198

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+
*/
131217
private Iterator<AsyncPage<Comment>> listComments(final String path) {
132218
return new GithubPageIterator<>(new GithubPage<>(github, path, LIST_COMMENT_TYPE_REFERENCE));
133219
}
134220

135221
/**
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.
137233
*
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
140237
*/
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);
143241
}
144242

145243
/**
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.
149245
*
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
153249
*/
154250
public CompletableFuture<CommentReaction> createCommentReaction(
155251
final long commentId, final CommentReactionContent reaction) {
@@ -160,12 +256,13 @@ public CompletableFuture<CommentReaction> createCommentReaction(
160256
}
161257

162258
/**
163-
* Delete a reaction on a comment. See <a
259+
* Deletes a reaction on a comment. See <a
164260
* href="https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#delete-an-issue-comment-reaction">List
165261
* reactions for an issue comment</a>
166262
*
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
169266
*/
170267
public CompletableFuture<HttpResponse> deleteCommentReaction(
171268
final long issueNumber, final long reactionId) {
@@ -175,12 +272,12 @@ public CompletableFuture<HttpResponse> deleteCommentReaction(
175272
}
176273

177274
/**
178-
* List reactions on a comment. See <a
275+
* Lists reactions on a comment. See <a
179276
* href="https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28#list-reactions-for-an-issue-comment">List
180277
* reactions for an issue comment</a>
181278
*
182-
* @param commentId comment id
183-
* @return reactions
279+
* @param commentId the comment id
280+
* @return an iterator of asynchronous pages of comment reactions
184281
*/
185282
public GithubPageIterator<CommentReaction> listCommentReaction(final long commentId) {
186283
final String path = String.format(COMMENTS_REACTION_TEMPLATE, owner, repo, commentId);

0 commit comments

Comments
 (0)