Skip to content

Commit b5d2a1f

Browse files
committed
impl add comment.
1 parent 5b4384e commit b5d2a1f

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,42 @@ try {
175175
?>
176176
````
177177

178+
## Add comment
179+
180+
````php
181+
<?php
182+
require 'vendor/autoload.php';
183+
184+
use JiraRestApi\Issue\IssueService;
185+
use JiraRestApi\Issue\Comment;
186+
187+
$issueKey = "TEST-879";
188+
189+
try {
190+
$comment = new Comment();
191+
192+
$body = <<<COMMENT
193+
Adds a new comment to an issue.
194+
* Bullet 1
195+
* Bullet 2
196+
** sub Bullet 1
197+
** sub Bullet 2
198+
* Bullet 3
199+
COMMENT;
200+
$comment->setBody($body)
201+
->setVisibility('role', 'Users');
202+
;
203+
204+
$issueService = new IssueService();
205+
$ret = $issueService->addComment($issueKey, $comment);
206+
print_r($ret);
207+
} catch (JIRAException $e) {
208+
$this->assertTrue(FALSE, "add Comment Failed : " . $e->getMessage());
209+
}
210+
211+
?>
212+
````
213+
178214
# License
179215

180216
Apache V2 License

src/issue/IssueService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ public function addComment($issueIdOrKey, $comment) {
114114

115115
$ret = $this->exec($this->uri . "/$issueIdOrKey/comment", $data);
116116

117-
$comment = $this->json_mapper->mapArray(
118-
json_decode($ret), new \ArrayObject(), '\JiraRestApi\Issue\Comment'
117+
$this->log->addDebug("add comment result=" . var_export($ret, true));
118+
$comment = $this->json_mapper->map(
119+
json_decode($ret), new Comment()
119120
);
120121

121122
return $comment;

tests/IssueTest.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use JiraRestApi\Issue\IssueService;
44
use JiraRestApi\Issue\IssueField;
5+
use JiraRestApi\Issue\Comment;
56

67
class IssueTest extends PHPUnit_Framework_TestCase
78
{
@@ -86,7 +87,7 @@ public function testUpdateIssue($issueKey)
8687
try {
8788
$issueField = new IssueField(true);
8889

89-
$issueField->setAssigneeName("admin")
90+
$issueField->setAssigneeName("lesstif")
9091
->setPriorityName("Major")
9192
->setIssueType("Task")
9293
->addLabel("test-label-first")
@@ -99,11 +100,44 @@ public function testUpdateIssue($issueKey)
99100
$issueService = new IssueService();
100101

101102
$issueService->update($issueKey, $issueField);
103+
104+
return $issueKey;
102105
} catch (JIRAException $e) {
103106
$this->assertTrue(FALSE, "update Failed : " . $e->getMessage());
104107
}
105108
}
106109

110+
/**
111+
* @depends testUpdateIssue
112+
*
113+
*/
114+
public function testAddcommnet($issueKey)
115+
{
116+
//$this->markTestIncomplete();
117+
try {
118+
$comment = new Comment();
119+
120+
$body = <<<COMMENT
121+
Adds a new comment to an issue.
122+
* Bullet 1
123+
* Bullet 2
124+
** sub Bullet 1
125+
** sub Bullet 2
126+
COMMENT;
127+
$comment->setBody($body)
128+
->setVisibility('role', 'Users');
129+
;
130+
131+
$issueService = new IssueService();
132+
$ret = $issueService->addComment($issueKey, $comment);
133+
print_r($ret);
134+
135+
return $issueKey;
136+
} catch (JIRAException $e) {
137+
$this->assertTrue(FALSE, "add Comment Failed : " . $e->getMessage());
138+
}
139+
}
140+
107141
}
108142

109143
?>

0 commit comments

Comments
 (0)