forked from Chavaillaz/jira-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIssueApi.java
546 lines (490 loc) · 19.9 KB
/
IssueApi.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
package com.chavaillaz.client.jira.api;
import static com.chavaillaz.client.jira.api.expand.IssueExpand.CHANGELOG;
import static com.chavaillaz.client.jira.api.expand.IssueExpand.TRANSITIONS;
import static java.util.Collections.emptySet;
import static java.util.Optional.empty;
import java.io.File;
import java.io.InputStream;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import com.chavaillaz.client.jira.api.expand.CommentExpand;
import com.chavaillaz.client.jira.api.expand.IssueExpand;
import com.chavaillaz.client.jira.domain.Attachment;
import com.chavaillaz.client.jira.domain.Attachments;
import com.chavaillaz.client.jira.domain.Comment;
import com.chavaillaz.client.jira.domain.Comments;
import com.chavaillaz.client.jira.domain.Identity;
import com.chavaillaz.client.jira.domain.Issue;
import com.chavaillaz.client.jira.domain.IssueTransition;
import com.chavaillaz.client.jira.domain.Link;
import com.chavaillaz.client.jira.domain.RemoteLink;
import com.chavaillaz.client.jira.domain.RemoteLinks;
import com.chavaillaz.client.jira.domain.Transitions;
import com.chavaillaz.client.jira.domain.User;
import com.chavaillaz.client.jira.domain.Votes;
import com.chavaillaz.client.jira.domain.Watchers;
import com.chavaillaz.client.jira.domain.WorkLog;
import com.chavaillaz.client.jira.domain.WorkLogs;
public interface IssueApi<T extends Issue> extends AutoCloseable {
String URL_ISSUE_CREATION = "issue/";
String URL_ISSUE_ACTION = "issue/{0}";
String URL_ISSUE_SELECTION = "issue/{0}?expand={1}&fields={2}";
String URL_ISSUE_ASSIGNEE = "issue/{0}/assignee";
String URL_ISSUE_TRANSITIONS = "issue/{0}/transitions";
String URL_ISSUE_COMMENTS_SELECTION = "issue/{0}/comment?startAt={1}&maxResults={2}&expand={3}";
String URL_ISSUE_COMMENT_CREATION = "issue/{0}/comment";
String URL_ISSUE_COMMENT_ACTION = "issue/{0}/comment/{1}";
String URL_ISSUE_COMMENT_SELECTION = "issue/{0}/comment/{1}?expand={2}";
String URL_ISSUE_VOTES = "issue/{0}/votes";
String URL_ISSUE_WATCHERS = "issue/{0}/watchers";
String URL_ISSUE_WATCHER = "issue/{0}/watchers?username={1}";
String URL_ISSUE_WORK_LOGS = "issue/{0}/worklog";
String URL_ISSUE_WORK_LOG = "issue/{0}/worklog/{1}";
String URL_ISSUE_REMOTE_LINKS = "issue/{0}/remotelink";
String URL_ISSUE_REMOTE_LINK = "issue/{0}/remotelink/{1}";
String URL_ISSUE_ATTACHMENTS = "issue/{0}/attachments";
String URL_ATTACHMENT = "attachment/{0}";
String URL_ISSUE_LINKS = "issueLink/";
String URL_ISSUE_LINK = "issueLink/{0}";
Set<String> ALL_FIELDS = Set.of("*all");
/**
* Creates an issue.
*
* @param issue The issue to create
* @return A {@link CompletableFuture} with issue identifiers
*/
CompletableFuture<Identity> addIssue(T issue);
/**
* Returns a full representation of the issue identified by the given key.
* By default, the issue will be expanded with its changelog and possible transitions.
* Note that if the issue does not exist, the {@link CompletableFuture} will complete exceptionally.
*
* @param issueKey The key identifying the issue
* @return A {@link CompletableFuture} with the corresponding issue
*/
default CompletableFuture<T> getIssue(String issueKey) {
return getIssue(issueKey, Set.of(CHANGELOG, TRANSITIONS));
}
/**
* Returns a full representation of the issue identified by the given key.
* Note that if the issue does not exist, the {@link CompletableFuture} will complete exceptionally.
*
* @param issueKey The key identifying the issue
* @param expandFlags The optional flags to expand values returned
* @return A {@link CompletableFuture} with the corresponding issue
*/
default CompletableFuture<T> getIssue(String issueKey, Set<IssueExpand> expandFlags) {
return getIssue(issueKey, expandFlags, ALL_FIELDS);
}
/**
* Returns a representation with the given fields of the issue identified by the given key.
* Note that if the issue does not exist, the {@link CompletableFuture} will complete exceptionally.
*
* @param issueKey The key identifying the issue
* @param expandFlags The optional flags to expand values returned
* @param fields The list of fields to be present in the issue retrieved
* @return A {@link CompletableFuture} with the corresponding issue
*/
CompletableFuture<T> getIssue(String issueKey, Set<IssueExpand> expandFlags, Set<String> fields);
/**
* Returns a full representation of the issue identified by the given key.
* By default, the issue will be expanded with its changelog and possible transitions.
* Note that if the issue does not exist, an {@link Optional#empty()} will be returned.
*
* @param issueKey The key identifying the issue
* @return A {@link CompletableFuture} with the corresponding optional issue
*/
default CompletableFuture<Optional<T>> getIssueOptional(String issueKey) {
return getIssue(issueKey)
.thenApply(Optional::of)
.exceptionally(exception -> empty());
}
/**
* Returns a full representation of the issue identified by the given key.
* Note that if the issue does not exist, an {@link Optional#empty()} will be returned.
*
* @param issueKey The key identifying the issue
* @param expandFlags The optional flags to expand values returned
* @return A {@link CompletableFuture} with the corresponding optional issue
*/
default CompletableFuture<Optional<T>> getIssueOptional(String issueKey, Set<IssueExpand> expandFlags) {
return getIssue(issueKey, expandFlags)
.thenApply(Optional::of)
.exceptionally(exception -> empty());
}
/**
* Returns a representation with the given fields of the issue identified by the given key.
* Note that if the issue does not exist, an {@link Optional#empty()} will be returned.
*
* @param issueKey The key identifying the issue
* @param expandFlags The optional flags to expand values returned
* @param fields The list of fields to be present in the issue retrieved
* @return A {@link CompletableFuture} with the corresponding issue
*/
default CompletableFuture<Optional<T>> getIssueOptional(String issueKey, Set<IssueExpand> expandFlags, Set<String> fields) {
return getIssue(issueKey, expandFlags, fields)
.thenApply(Optional::of)
.exceptionally(exception -> empty());
}
/**
* Updates fields of an issue.
*
* @param issue The issue containing only the fields to update
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> updateIssue(T issue);
/**
* Deletes an issue.
*
* @param issueKey The key identifying the issue
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> deleteIssue(String issueKey);
/**
* Assigns an issue to someone.
*
* @param issueKey The key identifying the issue
* @param user The user to assign the issue to
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> assignIssue(String issueKey, User user);
/**
* Removes the current user assigned to the issue.
*
* @param issueKey The key identifying the issue
* @return A {@link CompletableFuture} without content
*/
default CompletableFuture<Void> unassignIssue(String issueKey) {
return assignIssue(issueKey, null);
}
/**
* Gets the possible transitions of an issue.
*
* @param issueKey The key identifying the issue
* @return A {@link CompletableFuture} with the possible transitions
*/
CompletableFuture<Transitions> getTransitions(String issueKey);
/**
* Performs a transition for an issue.
*
* @param issueKey The key identifying the issue
* @param transition The transition to perform
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> doTransition(String issueKey, IssueTransition<?> transition);
/**
* Gets the comments of an issue.
* This uses a page offset of 0 and a number of results par page of 50.
*
* @param issueKey The key identifying the issue
* @return A {@link CompletableFuture} with the comments
*/
default CompletableFuture<Comments> getComments(String issueKey) {
return getComments(issueKey, 0, 50);
}
/**
* Gets the comments of an issue.
*
* @param issueKey The key identifying the issue
* @return A {@link CompletableFuture} with the comments
*/
default CompletableFuture<Comments> getComments(String issueKey, Integer startAt, Integer maxResults) {
return getComments(issueKey, startAt, maxResults, emptySet());
}
/**
* Gets the comments of an issue.
*
* @param issueKey The key identifying the issue
* @param startAt The page offset
* @param maxResults The number of results per page
* @param expandFlags The optional flags to expand values returned
* @return A {@link CompletableFuture} with the comments
*/
CompletableFuture<Comments> getComments(String issueKey, Integer startAt, Integer maxResults, Set<CommentExpand> expandFlags);
/**
* Gets a comment.
*
* @param issueKey The key identifying the issue
* @param id The comment identifier
* @return A {@link CompletableFuture} with the comment
*/
default CompletableFuture<Comment> getComment(String issueKey, String id) {
return getComment(issueKey, id, emptySet());
}
/**
* Gets a comment.
*
* @param issueKey The key identifying the issue
* @param id The comment identifier
* @param expandFlags The optional flags to expand values returned
* @return A {@link CompletableFuture} with the comment
*/
CompletableFuture<Comment> getComment(String issueKey, String id, Set<CommentExpand> expandFlags);
/**
* Gets a comment.
* Note that if the comment does not exist, an {@link Optional#empty()} will be returned.
*
* @param issueKey The key identifying the issue
* @param id The comment identifier
* @return A {@link CompletableFuture} with the corresponding optional comment
*/
default CompletableFuture<Optional<Comment>> getCommentOptional(String issueKey, String id) {
return getComment(issueKey, id)
.thenApply(Optional::of)
.exceptionally(exception -> empty());
}
/**
* Gets a comment.
* Note that if the comment does not exist, an {@link Optional#empty()} will be returned.
*
* @param issueKey The key identifying the issue
* @param id The comment identifier
* @param expandFlags The optional flags to expand values returned
* @return A {@link CompletableFuture} with the corresponding optional comment
*/
default CompletableFuture<Optional<Comment>> getCommentOptional(String issueKey, String id, Set<CommentExpand> expandFlags) {
return getComment(issueKey, id, expandFlags)
.thenApply(Optional::of)
.exceptionally(exception -> empty());
}
/**
* Adds a comment in an issue.
*
* @param issueKey The key identifying the issue
* @param comment The comment to add
* @return A {@link CompletableFuture} with the comment
*/
CompletableFuture<Comment> addComment(String issueKey, Comment comment);
/**
* Updates a comment.
*
* @param issueKey The key identifying the issue
* @param comment The comment to update
* @return A {@link CompletableFuture} with the comment
*/
CompletableFuture<Comment> updateComment(String issueKey, Comment comment);
/**
* Deletes a comment.
*
* @param issueKey The key identifying the issue
* @param id The comment identifier
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> deleteComment(String issueKey, String id);
/**
* Adds the vote of the current user to an issue.
*
* @param issueKey The key identifying the issue
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> addVote(String issueKey);
/**
* Gets the votes of an issue.
*
* @param issueKey The key identifying the issue
* @return A {@link CompletableFuture} with the issue votes
*/
CompletableFuture<Votes> getVotes(String issueKey);
/**
* Gets the watchers of an issue.
*
* @param issueKey The key identifying the issue
* @return A {@link CompletableFuture} with the issue watchers
*/
CompletableFuture<Watchers> getWatchers(String issueKey);
/**
* Adds a user to the watchers of an issue.
*
* @param issueKey The key identifying the issue
* @param username The username
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> addWatcher(String issueKey, String username);
/**
* Deletes a user from the watchers of an issue.
*
* @param issueKey The key identifying the issue
* @param username The username
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> deleteWatcher(String issueKey, String username);
/**
* Adds a work log to an issue.
*
* @param issueKey The key identifying the issue
* @param workLog The work log to add
* @return A {@link CompletableFuture} with the work log
*/
CompletableFuture<WorkLog> addWorkLog(String issueKey, WorkLog workLog);
/**
* Gets all work logs from an issue.
*
* @param issueKey The key identifying the issue
* @return A {@link CompletableFuture} with the work logs
*/
CompletableFuture<WorkLogs> getWorkLogs(String issueKey);
/**
* Gets a work log.
*
* @param issueKey The key identifying the issue
* @param id The work log identifier
* @return A {@link CompletableFuture} with the work log
*/
CompletableFuture<WorkLog> getWorkLog(String issueKey, String id);
/**
* Gets a work log.
* Note that if the work log does not exist, an {@link Optional#empty()} will be returned.
*
* @param issueKey The key identifying the issue
* @param id The work log identifier
* @return A {@link CompletableFuture} with the corresponding optional work log
*/
default CompletableFuture<Optional<WorkLog>> getWorkLogOptional(String issueKey, String id) {
return getWorkLog(issueKey, id)
.thenApply(Optional::of)
.exceptionally(exception -> empty());
}
/**
* Updates a work log.
*
* @param issueKey The key identifying the issue
* @param workLog The work log containing only the fields to update
* @return A {@link CompletableFuture} with the work log
*/
CompletableFuture<WorkLog> updateWorkLog(String issueKey, WorkLog workLog);
/**
* Deletes a work log.
*
* @param issueKey The key identifying the issue
* @param id The work log identifier
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> deleteWorkLog(String issueKey, String id);
/**
* Gets an attachment.
*
* @param id The attachment identifier
* @return A {@link CompletableFuture} with the attachment
*/
CompletableFuture<Attachment> getAttachment(String id);
/**
* Gets an attachment.
* Note that if the attachment does not exist, an {@link Optional#empty()} will be returned.
*
* @param id The attachment identifier
* @return A {@link CompletableFuture} with the corresponding optional attachment
*/
default CompletableFuture<Optional<Attachment>> getAttachmentOptional(String id) {
return getAttachment(id)
.thenApply(Optional::of)
.exceptionally(exception -> empty());
}
/**
* Gets an attachment content.
*
* @param url The complete URI locating the attachment content
* @return A {@link CompletableFuture} with the attachment content as input stream
*/
CompletableFuture<InputStream> getAttachmentContent(String url);
/**
* Adds an attachment to an issue.
*
* @param issueKey The key identifying the issue
* @param files The attachments to add
* @return A {@link CompletableFuture} with the attachment
*/
CompletableFuture<Attachments> addAttachment(String issueKey, File... files);
/**
* Deletes an attachment.
*
* @param id The attachment identifier
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> deleteAttachment(String id);
/**
* Gets the remote links of an issue.
*
* @param issueKey The key identifying the issue
* @return A {@link CompletableFuture} with the remote links
*/
CompletableFuture<RemoteLinks> getRemoteLinks(String issueKey);
/**
* Gets a remote link.
*
* @param issueKey The key identifying the issue
* @param id The remote link identifier
* @return A {@link CompletableFuture} with the remote link
*/
CompletableFuture<RemoteLink> getRemoteLink(String issueKey, String id);
/**
* Gets a remote link.
* Note that if the remote link does not exist, an {@link Optional#empty()} will be returned.
*
* @param issueKey The key identifying the issue
* @param id The remote link identifier
* @return A {@link CompletableFuture} with the corresponding optional remote link
*/
default CompletableFuture<Optional<RemoteLink>> getRemoteLinkOptional(String issueKey, String id) {
return getRemoteLink(issueKey, id)
.thenApply(Optional::of)
.exceptionally(exception -> empty());
}
/**
* Adds a remote link to an issue.
*
* @param issueKey The key identifying the issue
* @param remoteLink The remote link
* @return A {@link CompletableFuture} with the remote link identifiers
*/
CompletableFuture<Identity> addRemoteLink(String issueKey, RemoteLink remoteLink);
/**
* Updates a remote link.
*
* @param issueKey The key identifying the issue
* @param remoteLink The remote link to update
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> updateRemoteLink(String issueKey, RemoteLink remoteLink);
/**
* Deletes a remote link.
*
* @param issueKey The key identifying the issue
* @param id The remote link identifier
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> deleteRemoteLink(String issueKey, String id);
/**
* Gets an issue link.
*
* @param id The issue link identifier
* @return A {@link CompletableFuture} with the issue link
*/
CompletableFuture<Link> getIssueLink(String id);
/**
* Gets an issue link.
* Note that if the issue link does not exist, an {@link Optional#empty()} will be returned.
*
* @param id The issue link identifier
* @return A {@link CompletableFuture} with the corresponding optional issue link
*/
default CompletableFuture<Optional<Link>> getIssueLinkOptional(String id) {
return getIssueLink(id)
.thenApply(Optional::of)
.exceptionally(exception -> empty());
}
/**
* Adds an issue link.
*
* @param link The issue link
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> addIssueLink(Link link);
/**
* Deletes an issue link.
*
* @param id The issue link identifier
* @return A {@link CompletableFuture} without content
*/
CompletableFuture<Void> deleteIssueLink(String id);
}