Skip to content

Commit c913958

Browse files
committed
impl #110
1 parent d10eda8 commit c913958

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

src/Issue/IssueService.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,4 +721,28 @@ public function getEditMeta($idOrKey, $overrideEditableFlag = false, $overrideSc
721721

722722
return $cfs;
723723
}
724+
725+
/**
726+
* @param $issueIdOrKey Issue id Or Key
727+
* @param $notify Notify
728+
*
729+
* @throws JiraException
730+
*
731+
* @see https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/issue-notify
732+
*
733+
*/
734+
public function notify($issueIdOrKey, $notify)
735+
{
736+
$uri = $this->uri."/$issueIdOrKey/notify";
737+
738+
$data = json_encode($notify);
739+
740+
$this->log->addInfo("notify=$data\n");
741+
742+
$ret = $this->exec($uri, $data, 'POST');
743+
744+
if ($ret !== 204) {
745+
throw new JiraException("notify failed: response code=".$ret);
746+
}
747+
}
724748
}

src/Issue/Notify.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
namespace JiraRestApi\Issue;
3+
4+
class Notify implements \JsonSerializable
5+
{
6+
/** @var string */
7+
public $subject;
8+
9+
/** @var string */
10+
public $textBody;
11+
12+
/** @var */
13+
public $htmlBody;
14+
15+
/** @var array|null */
16+
public $to;
17+
18+
/** @var array|null */
19+
public $groups;
20+
21+
public function __construct()
22+
{
23+
$this->to = [];
24+
$this->to['users'] = [];
25+
$this->groups = [];
26+
27+
$this->to['reporter'] = false;
28+
$this->to['assignee'] = false;
29+
$this->to['watchers'] = true;
30+
$this->to['voters'] = true;
31+
}
32+
33+
public function setSubject($subject) {
34+
$this->subject = $subject;
35+
return $this;
36+
}
37+
38+
public function setTextBody($textBody) {
39+
$this->textBody = $textBody;
40+
return $this;
41+
}
42+
43+
public function setHtmlBody($htmlBody) {
44+
$this->htmlBody = $htmlBody;
45+
return $this;
46+
}
47+
48+
public function sendToReporter($bool)
49+
{
50+
$this->to['reporter'] = $bool;
51+
return $this;
52+
}
53+
54+
public function sendToAssignee($bool)
55+
{
56+
$this->to['assignee'] = $bool;
57+
return $this;
58+
}
59+
60+
public function sendToWatchers($bool)
61+
{
62+
$this->to['watchers'] = $bool;
63+
return $this;
64+
}
65+
66+
public function sendToVoters($bool)
67+
{
68+
$this->to['voters'] = $bool;
69+
return $this;
70+
}
71+
72+
public function sendToUser($name, $active)
73+
{
74+
$user['name'] = $name;
75+
$user['active'] = $active;
76+
77+
array_push($this->to['users'], $user);
78+
79+
return $this;
80+
}
81+
82+
public function sendToGroup($groupName)
83+
{
84+
$group['name'] = $groupName;
85+
// FIXME "self": "http://www.example.com/jira/rest/api/2/group?groupname=notification-group"
86+
//$group['self'] = $active;
87+
88+
array_push($this->groups, $group);
89+
90+
return $this;
91+
}
92+
93+
public function jsonSerialize()
94+
{
95+
return array_filter(get_object_vars($this));
96+
}
97+
}

0 commit comments

Comments
 (0)