-
Notifications
You must be signed in to change notification settings - Fork 259
/
IssueService.php
1281 lines (1061 loc) · 35.4 KB
/
IssueService.php
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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace JiraRestApi\Issue;
use ArrayObject;
use JiraRestApi\JiraException;
use JiraRestApi\Project\ProjectService;
class IssueService extends \JiraRestApi\JiraClient
{
private $uri = '/issue';
/**
* @param object $json
*
* @throws \JsonMapper_Exception
*
* @return Issue
*/
public function getIssueFromJSON($json): Issue
{
$issue = $this->json_mapper->map(
$json,
new Issue()
);
return $issue;
}
/**
* get all project list.
*
* @param string|int $issueIdOrKey
* @param array $paramArray Query Parameter key-value Array.
* @param Issue $issueObject
*
* @throws JiraException
* @throws \JsonMapper_Exception
*
* @return Issue class
*/
public function get($issueIdOrKey, $paramArray = [], $issueObject = null): Issue
{
$issueObject = ($issueObject) ? $issueObject : new Issue();
$ret = $this->exec($this->uri.'/'.$issueIdOrKey.$this->toHttpQueryParameter($paramArray), null);
$this->log->info("Result=\n".$ret);
return $issue = $this->json_mapper->map(
json_decode($ret),
$issueObject
);
}
/**
* create new issue.
*
* @param IssueField $issueField
*
* @throws JiraException
* @throws \JsonMapper_Exception
*
* @return Issue created issue key
*/
public function create($issueField): Issue
{
$issue = new Issue();
// serilize only not null field.
$issue->fields = $issueField;
$data = json_encode($issue);
$this->log->info("Create Issue=\n".$data);
$ret = $this->exec($this->uri, $data, 'POST');
return $this->getIssueFromJSON(json_decode($ret));
}
/**
* Create multiple issues using bulk insert.
*
* @param IssueField[] $issueFields Array of IssueField objects
* @param int $batchSize Maximum number of issues to send in each request
*
* @throws JiraException
* @throws \JsonMapper_Exception
*
* @return Issue[] Array of results, where each result represents one batch of insertions
*/
public function createMultiple($issueFields, $batchSize = 50): array
{
$issues = [];
foreach ($issueFields as $issueField) {
$issue = new Issue();
$issue->fields = $issueField;
$issues[] = $issue;
}
$batches = array_chunk($issues, $batchSize);
$results = [];
foreach ($batches as $batch) {
$results = array_merge($results, $this->bulkInsert($batch));
}
return $results;
}
/**
* Makes API call to bulk insert issues.
*
* @param Issue[] $issues Array of issue arrays that are sent to Jira one by one in single create
*
* @throws JiraException
* @throws \JsonMapper_Exception
*
* @return Issue[] Result of API call to insert many issues
*/
private function bulkInsert($issues): array
{
$data = json_encode(['issueUpdates' => $issues]);
$this->log->info("Create Issues=\n".$data);
$results = $this->exec($this->uri.'/bulk', $data, 'POST');
$issues = [];
foreach (json_decode($results)->issues as $result) {
$issues[] = $this->getIssueFromJSON($result);
}
return $issues;
}
/**
* Add one or more file to an issue.
*
* @param string|int $issueIdOrKey Issue id or key
* @param array|string $filePathArray attachment file path.
*
* @throws JiraException
* @throws \JsonMapper_Exception
*
* @return Attachment[]
*/
public function addAttachments($issueIdOrKey, $filePathArray): array
{
if (is_array($filePathArray) == false) {
$filePathArray = [$filePathArray];
}
$results = $this->upload($this->uri."/$issueIdOrKey/attachments", $filePathArray);
$this->log->info('addAttachments result='.var_export($results, true));
$attachArr = [];
foreach ($results as $ret) {
$ret = json_decode($ret);
if (is_array($ret)) {
$tmpArr = $this->json_mapper->mapArray(
$ret,
new \ArrayObject(),
Attachment::class
);
foreach ($tmpArr as $t) {
$attachArr[] = $t;
}
} elseif (is_object($ret)) {
$attachArr[] = $this->json_mapper->map(
$ret,
new Attachment()
);
}
}
return $attachArr;
}
/**
* update issue.
*
* @param string|int $issueIdOrKey Issue Key
* @param IssueField $issueField object of Issue class
* @param array $paramArray Query Parameter key-value Array.
*
* @throws JiraException
*
* @return string created issue key
*/
public function update($issueIdOrKey, $issueField, $paramArray = []): string
{
$issue = new Issue();
// serilize only not null field.
$issue->fields = $issueField;
//$issue = $this->filterNullVariable((array)$issue);
$data = json_encode($issue);
$this->log->info("Update Issue=\n".$data);
$queryParam = '?'.http_build_query($paramArray);
$ret = $this->exec($this->uri."/$issueIdOrKey".$queryParam, $data, 'PUT');
return $ret;
}
/**
* Adds a new comment to an issue.
*
* @param string|int $issueIdOrKey Issue id or key
* @param Comment $comment
*
* @throws JiraException
* @throws \JsonMapper_Exception
*
* @return Comment Comment class
*/
public function addComment($issueIdOrKey, $comment): Comment
{
$this->log->info("addComment=\n");
if (!($comment instanceof Comment) || empty($comment->body)) {
throw new JiraException('comment param must be instance of Comment and have body text.');
}
$data = json_encode($comment);
$ret = $this->exec($this->uri."/$issueIdOrKey/comment", $data);
$this->log->debug('add comment result='.var_export($ret, true));
$comment = $this->json_mapper->map(
json_decode($ret),
new Comment()
);
return $comment;
}
/**
* Update a comment in issue.
*
* @param string|int $issueIdOrKey Issue id or key
* @param string|int $id Comment id
* @param Comment $comment
*
* @throws JiraException
* @throws \JsonMapper_Exception
*
* @return Comment Comment class
*/
public function updateComment($issueIdOrKey, $id, $comment): Comment
{
$this->log->info("updateComment=\n");
if (!($comment instanceof Comment) || empty($comment->body)) {
throw new JiraException('comment param must instance of Comment and have to body text.!');
}
$data = json_encode($comment);
$ret = $this->exec($this->uri."/$issueIdOrKey/comment/$id", $data, 'PUT');
$this->log->debug('update comment result='.var_export($ret, true));
$comment = $this->json_mapper->map(
json_decode($ret),
new Comment()
);
return $comment;
}
/**
* Get a comment on an issue.
*
* @param string|int $issueIdOrKey Issue id or key
* @param string|int $id Comment id
* @param array $paramArray query parameter
*
* @throws JiraException
* @throws \JsonMapper_Exception
*
* @return Comment Comment class
*/
public function getComment($issueIdOrKey, $id, array $paramArray = []): Comment
{
$this->log->info("getComment=\n");
$ret = $this->exec($this->uri."/$issueIdOrKey/comment/$id".$this->toHttpQueryParameter($paramArray));
$this->log->debug('get comment result='.var_export($ret, true));
$comment = $this->json_mapper->map(
json_decode($ret),
new Comment()
);
return $comment;
}
/**
* Get all comments on an issue.
*
* @param string|int $issueIdOrKey Issue id or key
* @param array $paramArray Query Parameter key-value Array.
*
* @throws JiraException
* @throws \JsonMapper_Exception
*
* @return Comments Comments class
*/
public function getComments($issueIdOrKey, array $paramArray = []): Comments
{
$this->log->info("getComments=\n");
$ret = $this->exec($this->uri.'/'.$issueIdOrKey.'/comment'.$this->toHttpQueryParameter($paramArray), null);
$this->log->debug('get comments result='.var_export($ret, true));
$comments = $this->json_mapper->map(
json_decode($ret),
new Comments()
);
return $comments;
}
/**
* Delete a comment on an issue.
*
* @param string|int $issueIdOrKey Issue id or key
* @param string|int $id Comment id
*
* @throws JiraException
*
* @return string|bool
*/
public function deleteComment($issueIdOrKey, $id): string|bool
{
$this->log->info("deleteComment=\n");
$ret = $this->exec($this->uri."/$issueIdOrKey/comment/$id", '', 'DELETE');
$this->log->info('delete comment '.$issueIdOrKey.' '.$id.' result='.var_export($ret, true));
return $ret;
}
/**
* Change a issue assignee.
*
* @param string|int $issueIdOrKey
* @param string|null $assigneeName Assigns an issue to a user.
* If the assigneeName is "-1" automatic assignee is used.
* A null name will remove the assignee.
*
* @throws JiraException
*
* @return string|bool
*/
public function changeAssignee($issueIdOrKey, $assigneeName): string|bool
{
$this->log->info("changeAssignee=\n");
$ar = ['name' => $assigneeName];
$data = json_encode($ar);
$ret = $this->exec($this->uri."/$issueIdOrKey/assignee", $data, 'PUT');
$this->log->info('change assignee of '.$issueIdOrKey.' to '.$assigneeName.' result='.var_export($ret, true));
return $ret;
}
/**
* Change a issue assignee for REST API V3.
*
* @param string|int $issueIdOrKey
* @param string|null $accountId Assigns an issue to a user.
*
* @throws JiraException
*
* @return string
*/
public function changeAssigneeByAccountId($issueIdOrKey, $accountId): string
{
$this->log->info("changeAssigneeByAccountId=\n");
$ar = ['accountId' => $accountId];
$data = json_encode($ar);
$ret = $this->exec($this->uri."/$issueIdOrKey/assignee", $data, 'PUT');
$this->log->info('change assignee of '.$issueIdOrKey.' to '.$accountId.' result='.var_export($ret, true));
return $ret;
}
/**
* Delete a issue.
*
* @param string|int $issueIdOrKey Issue id or key
* @param array $paramArray Query Parameter key-value Array.
*
* @throws JiraException
*
* @return string|bool
*/
public function deleteIssue($issueIdOrKey, $paramArray = []): string|bool
{
$this->log->info("deleteIssue=\n");
$queryParam = '?'.http_build_query($paramArray);
$ret = $this->exec($this->uri."/$issueIdOrKey".$queryParam, '', 'DELETE');
$this->log->info('delete issue '.$issueIdOrKey.' result='.var_export($ret, true));
return $ret;
}
/**
* Get a list of the transitions possible for this issue by the current user, along with fields that are required and their types.
*
* @param string|int $issueIdOrKey Issue id or key
* @param array $paramArray Query Parameter key-value Array.
*
* @throws JiraException
*
* @return Transition[] array of Transition class
*/
public function getTransition($issueIdOrKey, $paramArray = []): ArrayObject
{
$queryParam = '?'.http_build_query($paramArray);
$ret = $this->exec($this->uri."/$issueIdOrKey/transitions".$queryParam);
$this->log->debug('getTransitions result='.var_export($ret, true));
$data = json_encode(json_decode($ret)->transitions);
$transitions = $this->json_mapper->mapArray(
json_decode($data),
new \ArrayObject(),
Transition::class
);
return $transitions;
}
/**
* find transition id by transition's to field name(aka 'Resolved').
*
* @param string|int $issueIdOrKey
* @param string $transitionToName
*
* @throws JiraException
*
* @return string
*/
public function findTransitonId($issueIdOrKey, $transitionToName): string
{
$this->log->debug('findTransitonId=');
$ret = $this->getTransition($issueIdOrKey);
foreach ($ret as $trans) {
$toName = $trans->to->name;
$this->log->debug('getTransitions result='.var_export($ret, true));
if (strcasecmp($toName, $transitionToName) === 0) {
return $trans->id;
}
}
// transition keyword not found
throw new JiraException("Transition name '$transitionToName' not found on JIRA Server.");
}
/**
* Perform a transition on an issue.
*
* @param string|int $issueIdOrKey Issue id or key
* @param Transition $transition
*
* @throws JiraException
*
* @return string|null nothing - if transition was successful return http 204(no contents)
*/
public function transition($issueIdOrKey, $transition): ?string
{
$this->log->debug('transition='.var_export($transition, true));
if (!isset($transition->transition['id'])) {
if (isset($transition->transition['untranslatedName'])) {
$transition->transition['id'] = $this->findTransitonIdByUntranslatedName($issueIdOrKey, $transition->transition['untranslatedName']);
} elseif (isset($transition->transition['name'])) {
$transition->transition['id'] = $this->findTransitonId($issueIdOrKey, $transition->transition['name']);
} else {
throw new JiraException('you must set either name or untranslatedName for performing transition.');
}
}
$data = json_encode($transition);
$this->log->debug("transition req=$data\n");
$ret = $this->exec($this->uri."/$issueIdOrKey/transitions", $data, 'POST');
$this->log->debug('getTransitions result='.var_export($ret, true));
return $ret;
}
/**
* Search issues.
*
* @param string $jql
* @param int $startAt
* @param int $maxResults
* @param array $fields
* @param array $expand
* @param bool $validateQuery
*
* @throws \JsonMapper_Exception
* @throws JiraException
*
* @return IssueSearchResult
*/
public function search(string $jql, int $startAt = 0, int $maxResults = 15, array $fields = [], array $expand = [], bool $validateQuery = true): IssueSearchResult
{
$data = json_encode([
'jql' => $jql,
'startAt' => $startAt,
'maxResults' => $maxResults,
'fields' => $fields,
'expand' => $expand,
'validateQuery' => $validateQuery,
]);
$ret = $this->exec('search', $data, 'POST');
$json = json_decode($ret);
$result = null;
$result = $this->json_mapper->map(
$json,
new IssueSearchResult()
);
return $result;
}
/**
* get TimeTracking info.
*
* @param string $issueIdOrKey
*
* @throws JiraException
* @throws \JsonMapper_Exception
*
* @return TimeTracking
*/
public function getTimeTracking(string $issueIdOrKey): TimeTracking
{
$ret = $this->exec($this->uri."/$issueIdOrKey", null);
$this->log->debug("getTimeTracking res=$ret\n");
$issue = $this->json_mapper->map(
json_decode($ret),
new Issue()
);
return $issue->fields->timeTracking;
}
/**
* TimeTracking issues.
*
* @param string $issueIdOrKey Issue id or key
* @param TimeTracking $timeTracking
*
* @throws JiraException
*
* @return string
*/
public function timeTracking(string $issueIdOrKey, TimeTracking $timeTracking): string
{
$array = [
'update' => [
'timetracking' => [
['edit' => $timeTracking],
],
],
];
$data = json_encode($array);
$this->log->debug("TimeTracking req=$data\n");
// if success, just return HTTP 201.
return $this->exec($this->uri."/$issueIdOrKey", $data, 'PUT');
}
/**
* get property.
*
* @param string $issueIdOrKey
* @param Property $property
*
* @throws \JsonMapper_Exception
* @throws JiraException
*
* @return void
*/
public function setProperty(string $issueIdOrKey, Property $property)
{
$this->log->info("setProperty=\n");
$data = json_encode($property->value);
$url = $this->uri."/$issueIdOrKey/properties/".$property->key;
$type = 'PUT';
$ret = $this->exec($url, $data, $type);
}
/**
* get property.
*
* @param string $issueIdOrKey
* @param string $property the name of the property, e.g.com.railsware.SmartChecklist.checklist
*
* @throws \JsonMapper_Exception
* @throws JiraException
*
* @return Property
*/
public function getProperty(string $issueIdOrKey, $property): Property
{
$ret = $this->exec($this->uri."/$issueIdOrKey/properties/".$property);
$this->log->debug("getProperty res=$ret\n");
return $this->json_mapper->map(
json_decode($ret),
new Property()
);
}
/**
* get getWorklog.
*
* @param string $issueIdOrKey
* @param array $paramArray Possible keys for $paramArray: 'startAt', 'maxResults', 'startedAfter', 'expand'
*
* @throws \JsonMapper_Exception
* @throws JiraException
*
* @return PaginatedWorklog
*/
public function getWorklog(string $issueIdOrKey, array $paramArray = []): PaginatedWorklog
{
$ret = $this->exec($this->uri."/$issueIdOrKey/worklog".$this->toHttpQueryParameter($paramArray));
$this->log->debug("getWorklog res=$ret\n");
return $this->json_mapper->map(
json_decode($ret),
new PaginatedWorklog()
);
}
/**
* get getWorklog by Id.
*
* @param string $issueIdOrKey
* @param int $workLogId
*
* @throws \JsonMapper_Exception
* @throws JiraException
*
* @return Worklog PaginatedWorklog object
*/
public function getWorklogById(string $issueIdOrKey, int $workLogId): Worklog
{
$ret = $this->exec($this->uri."/$issueIdOrKey/worklog/$workLogId");
$this->log->debug("getWorklogById res=$ret\n");
return $this->json_mapper->map(
json_decode($ret),
new Worklog()
);
}
/**
* add work log to issue.
*
* @param string $issueIdOrKey
* @param Worklog $worklog
*
* @throws \JsonMapper_Exception
* @throws JiraException
*
* @return Worklog Worklog Object
*/
public function addWorklog(string $issueIdOrKey, Worklog $worklog)
{
$this->log->info("addWorklog=\n");
$data = json_encode($worklog);
$url = $this->uri."/$issueIdOrKey/worklog";
$type = 'POST';
$ret = $this->exec($url, $data, $type);
return $this->json_mapper->map(
json_decode($ret),
new Worklog()
);
}
/**
* edit the worklog.
*
* @param string $issueIdOrKey
* @param Worklog $worklog
* @param int $worklogId
*
* @throws \JsonMapper_Exception
* @throws JiraException
*
* @return Worklog
*/
public function editWorklog(string $issueIdOrKey, Worklog $worklog, int $worklogId): Worklog
{
$this->log->info("editWorklog=\n");
$data = json_encode($worklog);
$url = $this->uri."/$issueIdOrKey/worklog/$worklogId";
$type = 'PUT';
$ret = $this->exec($url, $data, $type);
return $this->json_mapper->map(
json_decode($ret),
new Worklog()
);
}
/**
* delete worklog.
*
* @param string $issueIdOrKey
* @param int $worklogId
*
* @throws JiraException
*
* @return bool
*/
public function deleteWorklog(string $issueIdOrKey, int $worklogId): bool
{
$this->log->info("deleteWorklog=\n");
$url = $this->uri."/$issueIdOrKey/worklog/$worklogId";
$type = 'DELETE';
$ret = $this->exec($url, null, $type);
return (bool) $ret;
}
/**
* Get all priorities.
*
* @throws JiraException
*
* @return Priority[] array of priority class
*/
public function getAllPriorities(): ArrayObject
{
$ret = $this->exec('priority', null);
return $this->json_mapper->mapArray(
json_decode($ret, false),
new \ArrayObject(),
Priority::class
);
}
/**
* Get priority by id.
* throws HTTPException if the priority is not found, or the calling user does not have permission or view it.
*
* @param int $priorityId Id of priority.
*
* @throws \JsonMapper_Exception
* @throws JiraException
*
* @return Priority priority
*/
public function getPriority(int $priorityId): Priority
{
$ret = $this->exec("priority/$priorityId", null);
$this->log->info('Result='.$ret);
return $this->json_mapper->map(
json_decode($ret),
new Priority()
);
}
/**
* Get priority by id.
* throws HTTPException if the priority is not found, or the calling user does not have permission or view it.
*
* @param $paramArray array parameters
*
* @throws \JsonMapper_Exception
* @throws JiraException
*
* @return CustomFieldSearchResult array of CustomeFiled
*
* @see https://docs.atlassian.com/software/jira/docs/api/REST/9.14.0/#api/2/customFields-getCustomFields
*/
public function getCustomFields(array $paramArray = []): CustomFieldSearchResult
{
$ret = $this->exec('customFields'.$this->toHttpQueryParameter($paramArray), null);
$this->log->info('Result='.$ret);
//\JiraRestApi\Dumper::dd(json_decode($ret, false));
return $this->json_mapper->map(
json_decode($ret, false),
new CustomFieldSearchResult()
);
}
/**
* get watchers.
*
* @param string $issueIdOrKey
*
* @throws JiraException
* @throws \JsonMapper_Exception
*
* @return Reporter[]
*/
public function getWatchers(string $issueIdOrKey): ArrayObject
{
$this->log->info("getWatchers=\n");
$url = $this->uri."/$issueIdOrKey/watchers";
$ret = $this->exec($url, null);
return $this->json_mapper->mapArray(
json_decode($ret, false)->watchers,
new \ArrayObject(),
Reporter::class
);
}
/**
* add watcher to issue.
*
* @param string $issueIdOrKey
* @param string $watcher watcher id
*
* @throws JiraException
*
* @return bool
*/
public function addWatcher(string $issueIdOrKey, string $watcher): bool
{
$this->log->info("addWatcher=\n");
$data = json_encode($watcher);
$url = $this->uri."/$issueIdOrKey/watchers";
$type = 'POST';
$this->exec($url, $data, $type);
return $this->http_response == 204 ? true : false;
}
/**
* remove watcher from issue.
*
* @param string $issueIdOrKey
* @param string $watcher watcher id
*
* @throws JiraException
*
* @return bool
*/
public function removeWatcher(string $issueIdOrKey, string $watcher): bool
{
$this->log->debug("removeWatcher=\n");
$ret = $this->exec($this->uri."/$issueIdOrKey/watchers/?username=$watcher", '', 'DELETE');
$this->log->debug('remove watcher '.$issueIdOrKey.' result='.var_export($ret, true));
return $this->http_response == 204 ? true : false;
}
/**
* remove watcher from issue by watcher account id.
*
* @param string $issueIdOrKey
* @param string $accountId Watcher account id.
*
* @throws JiraException
*
* @return bool
*/
public function removeWatcherByAccountId(string $issueIdOrKey, string $accountId): bool
{
$this->log->debug("removeWatcher=\n");
$ret = $this->exec($this->uri."/$issueIdOrKey/watchers/?accountId=$accountId", '', 'DELETE');
$this->log->debug('remove watcher '.$issueIdOrKey.' result='.var_export($ret, true));
return $this->http_response == 204 ? true : false;
}
/**
* Get the meta data for creating issues.
*
* @param array $paramArray Possible keys for $paramArray: 'projectIds', 'projectKeys', 'issuetypeIds', 'issuetypeNames'.
* @param bool $expand Retrieve all issue fields and values
*
* @throws JiraException
*
* @return object object of meta data for creating issues.
*/
public function getCreateMeta(array $paramArray = [], bool $expand = true): object
{
$paramArray['expand'] = ($expand) ? 'projects.issuetypes.fields' : null;
$paramArray = array_filter($paramArray);
$queryParam = '?'.http_build_query($paramArray);
$ret = $this->exec($this->uri.'/createmeta'.$queryParam, null);
return json_decode($ret);
}
/**
* returns the metadata(include custom field) for an issue.
*
* @param string $idOrKey issue id or key
* @param bool $overrideEditableFlag Allows retrieving edit metadata for fields in non-editable status
* @param bool $overrideScreenSecurity Allows retrieving edit metadata for the fields hidden on Edit screen.
*
* @throws JiraException
*
* @return array of custom fields
*
* @see https://confluence.atlassian.com/jirakb/how-to-retrieve-available-options-for-a-multi-select-customfield-via-jira-rest-api-815566715.html How to retrieve available options for a multi-select customfield via JIRA REST API
* @see https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-issueIdOrKey-editmeta-get
*/
public function getEditMeta(string $idOrKey, bool $overrideEditableFlag = false, bool $overrideScreenSecurity = false): array
{
$queryParam = '?'.http_build_query([
'overrideEditableFlag' => $overrideEditableFlag,
'overrideScreenSecurity' => $overrideScreenSecurity,
]);
$uri = sprintf('%s/%s/editmeta', $this->uri, $idOrKey).$queryParam;
$ret = $this->exec($uri, null);
$metas = json_decode($ret, true);
// extract only custom field(startWith customefield_XXXXX)
$cfs = array_filter($metas['fields'], function ($key) {
$pos = strpos($key, 'customfield');
return $pos !== false;
}, ARRAY_FILTER_USE_KEY);
return $cfs;
}
/**
* Sends a notification (email) to the list or recipients defined in the request.
*
* @param string $issueIdOrKey Issue id Or Key