File tree Expand file tree Collapse file tree 4 files changed +111
-0
lines changed Expand file tree Collapse file tree 4 files changed +111
-0
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,7 @@ $iss = new IssueService(new ArrayConfiguration(
113
113
- [ Add worklog in Issue] ( #add-worklog-in-issue )
114
114
- [ Edit worklog in Issue] ( #edit-worklog-in-issue )
115
115
- [ Get Issue worklog] ( #get-issue-worklog )
116
+ - [ Add watcher in Issue] ( #add-issue-watcher )
116
117
117
118
### User
118
119
- [ Get User Info] ( #get-user-info )
@@ -819,6 +820,34 @@ try {
819
820
820
821
```
821
822
823
+ #### Add watcher in Issue
824
+
825
+ ``` php
826
+ <?php
827
+ require 'vendor/autoload.php';
828
+
829
+ use JiraRestApi\Issue\IssueService;
830
+ use JiraRestApi\Issue\Watcher;
831
+ use JiraRestApi\JiraException;
832
+
833
+ $issueKey = 'TEST-961';
834
+
835
+ try {
836
+ $issueService = new IssueService();
837
+
838
+ // get issue's all worklog
839
+ $watcher = new Watcher('lesstif');
840
+ var_dump($watcher);
841
+
842
+ $wch = $issueService->addWatcher($issueKey, $watcher);
843
+ var_dump($wch);
844
+
845
+ } catch (JiraException $e) {
846
+ $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
847
+ }
848
+
849
+ ```
850
+
822
851
#### Get User Info
823
852
824
853
Returns a user.
Original file line number Diff line number Diff line change @@ -545,4 +545,27 @@ public function getCustomFields($priorityId)
545
545
546
546
return $ prio ;
547
547
}
548
+
549
+ /**
550
+ * add watcher to issue.
551
+ *
552
+ * @param mixed $issueIdOrKey
553
+ * @param object $watcher
554
+ * @param int $worklogId
555
+ *
556
+ * @return bool
557
+ */
558
+ public function addWatcher ($ issueIdOrKey , $ watcher )
559
+ {
560
+ $ this ->log ->addInfo ("addWatcher= \n" );
561
+
562
+ $ data = json_encode ($ watcher );
563
+ $ url = $ this ->uri . "/ $ issueIdOrKey/watchers " ;
564
+ $ type = 'POST ' ;
565
+
566
+ $ this ->exec ($ url , $ data , $ type );
567
+
568
+ return $ this ->http_response == 204 ? true : false ;
569
+ }
570
+
548
571
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace JiraRestApi \Issue ;
4
+
5
+ use JiraRestApi \ClassSerialize ;
6
+ use JiraRestApi \JiraException ;
7
+
8
+ /**
9
+ * Class Watcher.
10
+ */
11
+ class Watcher implements \JsonSerializable
12
+ {
13
+ use ClassSerialize;
14
+
15
+ /** @var string */
16
+ public $ name ;
17
+
18
+ public function __construct ($ name )
19
+ {
20
+ $ this ->name = $ name ;
21
+ }
22
+
23
+ /**
24
+ * Function to serialize obj vars.
25
+ *
26
+ * @return array
27
+ */
28
+ public function jsonSerialize ()
29
+ {
30
+ return $ this ->name ;
31
+ }
32
+
33
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use JiraRestApi \Dumper ;
4
+ use JiraRestApi \Issue \IssueService ;
5
+ use JiraRestApi \Issue \Watcher ;
6
+ use JiraRestApi \JiraException ;
7
+
8
+ class WatcherLogTest extends PHPUnit_Framework_TestCase
9
+ {
10
+ public $ issueKey = 'TEST-165 ' ;
11
+
12
+ public function testAddWatcherLog ()
13
+ {
14
+ try {
15
+ $ issueService = new IssueService ();
16
+
17
+ $ watcher = new Watcher ('lesstif ' );
18
+ // add issue watcher
19
+ $ ret = $ issueService ->addWatcher ($ this ->issueKey , $ watcher );
20
+
21
+ Dumper::dump ($ ret );
22
+ } catch (JiraException $ e ) {
23
+ $ this ->assertTrue (false , 'testAddWatcherLog Failed : ' .$ e ->getMessage ());
24
+ }
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments