Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a1b691f

Browse files
committed
refactor: Add overloads for long params for PRClient
1 parent 2d35bc2 commit a1b691f

File tree

1 file changed

+221
-0
lines changed

1 file changed

+221
-0
lines changed

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

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,29 @@ public CompletableFuture<List<PullRequestItem>> list(final PullRequestParameters
9797
/**
9898
* Get a specific pull request.
9999
*
100+
* @deprecated Use {@link #get(long)} instead
100101
* @param number pull request number
101102
* @return pull request
102103
*/
104+
@Deprecated
103105
public CompletableFuture<PullRequest> get(final int number) {
104106
final String path = String.format(PR_NUMBER_TEMPLATE, owner, repo, number);
105107
log.debug("Fetching pull request from " + path);
106108
return github.request(path, PullRequest.class);
107109
}
108110

111+
/**
112+
* Get a specific pull request.
113+
*
114+
* @param number pull request number
115+
* @return pull request
116+
*/
117+
public CompletableFuture<PullRequest> get(final long number) {
118+
final String path = String.format(PR_NUMBER_TEMPLATE, owner, repo, number);
119+
log.debug("Fetching pull request from " + path);
120+
return github.request(path, PullRequest.class);
121+
}
122+
109123
/**
110124
* Create a pull request.
111125
*
@@ -120,60 +134,120 @@ public CompletableFuture<PullRequest> create(final PullRequestCreate request) {
120134
/**
121135
* Update given pull request.
122136
*
137+
* @deprecated Use {@link #update(long, PullRequestUpdate)} instead
123138
* @param number pull request number
124139
* @param request update request
125140
* @return pull request
126141
*/
142+
@Deprecated
127143
public CompletableFuture<PullRequest> update(final int number, final PullRequestUpdate request) {
128144
final String path = String.format(PR_NUMBER_TEMPLATE, owner, repo, number);
129145
return github.patch(path, github.json().toJsonUnchecked(request), PullRequest.class);
130146
}
131147

148+
/**
149+
* Update given pull request.
150+
*
151+
* @param number pull request number
152+
* @param request update request
153+
* @return pull request
154+
*/
155+
public CompletableFuture<PullRequest> update(final long number, final PullRequestUpdate request) {
156+
final String path = String.format(PR_NUMBER_TEMPLATE, owner, repo, number);
157+
return github.patch(path, github.json().toJsonUnchecked(request), PullRequest.class);
158+
}
159+
132160
/**
133161
* List pull request commits.
134162
*
163+
* @deprecated Use {@link #listCommits(long)} instead
135164
* @param number pull request number
136165
* @return commits
137166
*/
167+
@Deprecated
138168
public CompletableFuture<List<CommitItem>> listCommits(final int number) {
139169
final String path = String.format(PR_COMMITS_TEMPLATE, owner, repo, number);
140170
log.debug("Fetching pull request commits from " + path);
141171
return github.request(path, LIST_COMMIT_TYPE_REFERENCE);
142172
}
143173

174+
/**
175+
* List pull request commits.
176+
*
177+
* @param number pull request number
178+
* @return commits
179+
*/
180+
public CompletableFuture<List<CommitItem>> listCommits(final long number) {
181+
final String path = String.format(PR_COMMITS_TEMPLATE, owner, repo, number);
182+
log.debug("Fetching pull request commits from " + path);
183+
return github.request(path, LIST_COMMIT_TYPE_REFERENCE);
184+
}
185+
144186
/**
145187
* List pull request reviews. Reviews are returned in chronological order.
146188
*
189+
* @deprecated Use {@link #listReviews(long)} instead
147190
* @param number pull request number
148191
* @return list of reviews
149192
*/
193+
@Deprecated
150194
public CompletableFuture<List<Review>> listReviews(final int number) {
151195
final String path = String.format(PR_REVIEWS_TEMPLATE, owner, repo, number);
152196
log.debug("Fetching pull request reviews from " + path);
153197
return github.request(path, LIST_REVIEW_TYPE_REFERENCE);
154198
}
155199

200+
/**
201+
* List pull request reviews. Reviews are returned in chronological order.
202+
*
203+
* @param number pull request number
204+
* @return list of reviews
205+
*/
206+
public CompletableFuture<List<Review>> listReviews(final long number) {
207+
final String path = String.format(PR_REVIEWS_TEMPLATE, owner, repo, number);
208+
log.debug("Fetching pull request reviews from " + path);
209+
return github.request(path, LIST_REVIEW_TYPE_REFERENCE);
210+
}
211+
156212
/**
157213
* List pull request reviews paginated. Reviews are returned in chronological order.
158214
*
215+
* @deprecated Use {@link #listReviews(long,long)} instead
159216
* @param number pull request number
160217
* @param itemsPerPage number of items per page
161218
* @return iterator of reviews
162219
*/
220+
@Deprecated
163221
public Iterator<AsyncPage<Review>> listReviews(final int number, final int itemsPerPage) {
164222
// FIXME Use itemsPerPage property
165223
final String path = String.format(PR_REVIEWS_TEMPLATE, owner, repo, number);
166224
log.debug("Fetching pull request reviews from " + path);
167225
return new GithubPageIterator<>(new GithubPage<>(github, path, LIST_REVIEW_TYPE_REFERENCE));
168226
}
169227

228+
/**
229+
* List pull request reviews paginated. Reviews are returned in chronological order.
230+
*
231+
* @param number pull request number
232+
* @param itemsPerPage number of items per page
233+
* @return iterator of reviews
234+
*/
235+
public Iterator<AsyncPage<Review>> listReviews(final long number, final long itemsPerPage) {
236+
// FIXME Use itemsPerPage property
237+
final String path = String.format(PR_REVIEWS_TEMPLATE, owner, repo, number);
238+
log.debug("Fetching pull request reviews from " + path);
239+
return new GithubPageIterator<>(new GithubPage<>(github, path, LIST_REVIEW_TYPE_REFERENCE));
240+
}
241+
170242
/**
171243
* Creates a review for a pull request.
172244
*
245+
* @deprecated Use {@link #createReview(long,ReviewParameters)} instead
173246
* @param number pull request number
174247
* @param properties properties for reviewing the PR, such as sha, body and event
175248
* @see "https://developer.github.com/v3/pulls/reviews/#create-a-review-for-a-pull-request"
176249
*/
250+
@Deprecated
177251
public CompletableFuture<Review> createReview(
178252
final int number, final ReviewParameters properties) {
179253
final String path = String.format(PR_REVIEWS_TEMPLATE, owner, repo, number);
@@ -182,25 +256,56 @@ public CompletableFuture<Review> createReview(
182256
return github.post(path, jsonPayload, Review.class);
183257
}
184258

259+
/**
260+
* Creates a review for a pull request.
261+
*
262+
* @param number pull request number
263+
* @param properties properties for reviewing the PR, such as sha, body and event
264+
* @see "https://developer.github.com/v3/pulls/reviews/#create-a-review-for-a-pull-request"
265+
*/
266+
public CompletableFuture<Review> createReview(
267+
final long number, final ReviewParameters properties) {
268+
final String path = String.format(PR_REVIEWS_TEMPLATE, owner, repo, number);
269+
final String jsonPayload = github.json().toJsonUnchecked(properties);
270+
log.debug("Creating review for PR: " + path);
271+
return github.post(path, jsonPayload, Review.class);
272+
}
273+
185274
/**
186275
* List pull request requested reviews.
187276
*
277+
* @deprecated Use {@link #listReviewRequests(long)} instead
188278
* @param number pull request number
189279
* @return list of reviews
190280
*/
281+
@Deprecated
191282
public CompletableFuture<ReviewRequests> listReviewRequests(final int number) {
192283
final String path = String.format(PR_REVIEW_REQUESTS_TEMPLATE, owner, repo, number);
193284
log.debug("Fetching pull request requested reviews from " + path);
194285
return github.request(path, LIST_REVIEW_REQUEST_TYPE_REFERENCE);
195286
}
196287

288+
/**
289+
* List pull request requested reviews.
290+
*
291+
* @param number pull request number
292+
* @return list of reviews
293+
*/
294+
public CompletableFuture<ReviewRequests> listReviewRequests(final long number) {
295+
final String path = String.format(PR_REVIEW_REQUESTS_TEMPLATE, owner, repo, number);
296+
log.debug("Fetching pull request requested reviews from " + path);
297+
return github.request(path, LIST_REVIEW_REQUEST_TYPE_REFERENCE);
298+
}
299+
197300
/**
198301
* Requests a review for a pull request.
199302
*
303+
* @deprecated Use {@link #requestReview(long,RequestReviewParameters)} instead
200304
* @param number pull request number
201305
* @param properties properties for reviewing the PR, such as reviewers and team_reviewers.
202306
* @see "https://docs.github.com/en/rest/reference/pulls#request-reviewers-for-a-pull-request"
203307
*/
308+
@Deprecated
204309
public CompletableFuture<PullRequest> requestReview(
205310
final int number, final RequestReviewParameters properties) {
206311
final String path = String.format(PR_REVIEW_REQUESTS_TEMPLATE, owner, repo, number);
@@ -209,13 +314,30 @@ public CompletableFuture<PullRequest> requestReview(
209314
return github.post(path, jsonPayload, PullRequest.class);
210315
}
211316

317+
/**
318+
* Requests a review for a pull request.
319+
*
320+
* @param number pull request number
321+
* @param properties properties for reviewing the PR, such as reviewers and team_reviewers.
322+
* @see "https://docs.github.com/en/rest/reference/pulls#request-reviewers-for-a-pull-request"
323+
*/
324+
public CompletableFuture<PullRequest> requestReview(
325+
final long number, final RequestReviewParameters properties) {
326+
final String path = String.format(PR_REVIEW_REQUESTS_TEMPLATE, owner, repo, number);
327+
final String jsonPayload = github.json().toJsonUnchecked(properties);
328+
log.debug("Requesting reviews for PR: " + path);
329+
return github.post(path, jsonPayload, PullRequest.class);
330+
}
331+
212332
/**
213333
* Remove a request for review for a pull request.
214334
*
335+
* @deprecated Use {@link #removeRequestedReview(long,RequestReviewParameters)} instead
215336
* @param number pull request number
216337
* @param properties properties for reviewing the PR, such as reviewers and team_reviewers.
217338
* @see "https://docs.github.com/en/rest/reference/pulls#request-reviewers-for-a-pull-request"
218339
*/
340+
@Deprecated
219341
public CompletableFuture<Void> removeRequestedReview(
220342
final int number, final RequestReviewParameters properties) {
221343
final String path = String.format(PR_REVIEW_REQUESTS_TEMPLATE, owner, repo, number);
@@ -224,20 +346,59 @@ public CompletableFuture<Void> removeRequestedReview(
224346
return github.delete(path, jsonPayload).thenAccept(IGNORE_RESPONSE_CONSUMER);
225347
}
226348

349+
/**
350+
* Remove a request for review for a pull request.
351+
*
352+
* @param number pull request number
353+
* @param properties properties for reviewing the PR, such as reviewers and team_reviewers.
354+
* @see "https://docs.github.com/en/rest/reference/pulls#request-reviewers-for-a-pull-request"
355+
*/
356+
public CompletableFuture<Void> removeRequestedReview(
357+
final long number, final RequestReviewParameters properties) {
358+
final String path = String.format(PR_REVIEW_REQUESTS_TEMPLATE, owner, repo, number);
359+
final String jsonPayload = github.json().toJsonUnchecked(properties);
360+
log.debug("Removing requested reviews for PR: " + path);
361+
return github.delete(path, jsonPayload).thenAccept(IGNORE_RESPONSE_CONSUMER);
362+
}
363+
227364
/**
228365
* Merges a pull request.
229366
*
367+
* @deprecated Use {@link #merge(long,MergeParameters)} instead
230368
* @param number pull request number
231369
* @param properties the properties on merging the PR, such as title, message and sha
232370
* @see "https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button"
233371
*/
372+
@Deprecated
234373
public CompletableFuture<Void> merge(final int number, final MergeParameters properties) {
235374
final String path = String.format(PR_NUMBER_TEMPLATE + "/merge", owner, repo, number);
236375
final String jsonPayload = github.json().toJsonUnchecked(properties);
237376
log.debug("Merging pr, running: {}", path);
238377
return github.put(path, jsonPayload).thenAccept(IGNORE_RESPONSE_CONSUMER);
239378
}
240379

380+
/**
381+
* Merges a pull request.
382+
*
383+
* @param number pull request number
384+
* @param properties the properties on merging the PR, such as title, message and sha
385+
* @see "https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button"
386+
*/
387+
public CompletableFuture<Void> merge(final long number, final MergeParameters properties) {
388+
final String path = String.format(PR_NUMBER_TEMPLATE + "/merge", owner, repo, number);
389+
final String jsonPayload = github.json().toJsonUnchecked(properties);
390+
log.debug("Merging pr, running: {}", path);
391+
return github.put(path, jsonPayload).thenAccept(IGNORE_RESPONSE_CONSUMER);
392+
}
393+
394+
/**
395+
* Fetches a pull request patch.
396+
*
397+
* @deprecated Use {@link #patch(long)} instead
398+
* @param number pull request number
399+
* @return reader for the patch
400+
*/
401+
@Deprecated
241402
public CompletableFuture<Reader> patch(final int number) {
242403
final String path = String.format(PR_NUMBER_TEMPLATE, owner, repo, number);
243404
final Map<String, String> extraHeaders =
@@ -255,6 +416,37 @@ public CompletableFuture<Reader> patch(final int number) {
255416
});
256417
}
257418

419+
/**
420+
* Fetches a pull request patch.
421+
*
422+
* @param number pull request number
423+
* @return reader for the patch
424+
*/
425+
public CompletableFuture<Reader> patch(final long number) {
426+
final String path = String.format(PR_NUMBER_TEMPLATE, owner, repo, number);
427+
final Map<String, String> extraHeaders =
428+
ImmutableMap.of(HttpHeaders.ACCEPT, "application/vnd.github.patch");
429+
log.debug("Fetching pull request patch from " + path);
430+
return github
431+
.request(path, extraHeaders)
432+
.thenApply(
433+
response -> {
434+
final var body = response.body();
435+
if (isNull(body)) {
436+
return Reader.nullReader();
437+
}
438+
return new InputStreamReader(body);
439+
});
440+
}
441+
442+
/**
443+
* Fetches a pull request diff.
444+
*
445+
* @deprecated Use {@link #diff(long)} instead
446+
* @param number pull request number
447+
* @return reader for the diff
448+
*/
449+
@Deprecated
258450
public CompletableFuture<Reader> diff(final int number) {
259451
final String path = String.format(PR_NUMBER_TEMPLATE, owner, repo, number);
260452
final Map<String, String> extraHeaders =
@@ -272,6 +464,35 @@ public CompletableFuture<Reader> diff(final int number) {
272464
});
273465
}
274466

467+
/**
468+
* Fetches a pull request diff.
469+
*
470+
* @param number pull request number
471+
* @return reader for the diff
472+
*/
473+
public CompletableFuture<Reader> diff(final long number) {
474+
final String path = String.format(PR_NUMBER_TEMPLATE, owner, repo, number);
475+
final Map<String, String> extraHeaders =
476+
ImmutableMap.of(HttpHeaders.ACCEPT, "application/vnd.github.diff");
477+
log.debug("Fetching pull diff from " + path);
478+
return github
479+
.request(path, extraHeaders)
480+
.thenApply(
481+
response -> {
482+
final var body = response.body();
483+
if (isNull(body)) {
484+
return Reader.nullReader();
485+
}
486+
return new InputStreamReader(body);
487+
});
488+
}
489+
490+
/**
491+
* List pull requests using given parameters.
492+
*
493+
* @param parameterPath request parameters
494+
* @return pull requests
495+
*/
275496
private CompletableFuture<List<PullRequestItem>> list(final String parameterPath) {
276497
final String path = String.format(PR_TEMPLATE + parameterPath, owner, repo);
277498
log.debug("Fetching pull requests from " + path);

0 commit comments

Comments
 (0)