Skip to content

Commit dec5cd1

Browse files
committed
add comment
1 parent a8b6a6d commit dec5cd1

File tree

4 files changed

+113
-33
lines changed

4 files changed

+113
-33
lines changed

src/issue/Comment.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace JiraRestApi\Issue;
4+
5+
class Visibility {
6+
public $type;
7+
public $value;
8+
}
9+
10+
class Comment implements \JsonSerializable {
11+
/* @var string */
12+
public $self;
13+
14+
/* @var string */
15+
public $id;
16+
17+
/* @var Reporter */
18+
public $author;
19+
20+
/* @var string */
21+
public $body;
22+
23+
/* @var Reporter */
24+
public $updateAuthor;
25+
26+
/* @var DateTime */
27+
public $created;
28+
29+
/* @var DateTime */
30+
public $updated;
31+
32+
/* @var Visibility */
33+
public $visibility;
34+
35+
public function setBody($body) {
36+
$this->body = $body;
37+
return $this;
38+
}
39+
40+
public function setVisibility($type, $value) {
41+
if (is_null($this->visibility))
42+
$this->visibility = array();
43+
44+
$this->visibility['type'] = $type;
45+
$this->visibility['value'] = $value;
46+
return $this;
47+
}
48+
49+
public function jsonSerialize()
50+
{
51+
return array_filter(get_object_vars($this));
52+
}
53+
}
54+
55+
?>

src/issue/Comments.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,6 @@
22

33
namespace JiraRestApi\Issue;
44

5-
class Comment implements \JsonSerializable {
6-
/* @var string */
7-
public $self;
8-
9-
/* @var string */
10-
public $id;
11-
12-
/* @var Reporter */
13-
public $author;
14-
15-
/* @var string */
16-
public $body;
17-
18-
/* @var Reporter */
19-
public $updateAuthor;
20-
21-
/* @var DateTime */
22-
public $created;
23-
24-
/* @var DateTime */
25-
public $updated;
26-
27-
public function jsonSerialize()
28-
{
29-
return array_filter(get_object_vars($this));
30-
}
31-
}
32-
335
class Comments implements \JsonSerializable {
346
/* @var int */
357
public $startAt;

src/issue/IssueService.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,29 @@ public function update($issueIdOrKey, $issueField) {
9797

9898
return $ret;
9999
}
100+
101+
/**
102+
* Adds a new comment to an issue.
103+
*
104+
* @param issueIdOrKey Issue id or key
105+
* @param comment .
106+
*
107+
* @return Comment class
108+
*/
109+
public function addComment($issueIdOrKey, $comment) {
110+
111+
$this->log->addInfo("addComment=\n");
112+
113+
$data = json_encode($comment);
114+
115+
$ret = $this->exec($this->uri . "/$issueIdOrKey/comment", $data);
116+
117+
$comment = $this->json_mapper->mapArray(
118+
json_decode($ret), new \ArrayObject(), '\JiraRestApi\Issue\Comment'
119+
);
120+
121+
return $comment;
122+
}
100123
}
101124

102125
?>

tests/IssueTest.php

Lines changed: 35 additions & 5 deletions
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
{
@@ -79,14 +80,12 @@ public function testAddAttachment($issueKey)
7980
}
8081

8182
/**
82-
* depends testAddAttachment
83+
* @depends testAddAttachment
8384
*
8485
*/
85-
public function testUpdateIssue()
86+
public function testUpdateIssue($issueKey)
8687
{
87-
$issueKey = "TEST-920";
88-
89-
//$this->markTestIncomplete();
88+
$this->markTestIncomplete();
9089
try {
9190
$issueField = new IssueField(true);
9291

@@ -103,11 +102,42 @@ public function testUpdateIssue()
103102
$issueService = new IssueService();
104103

105104
$issueService->update($issueKey, $issueField);
105+
106+
return $issueKey;
106107
} catch (JIRAException $e) {
107108
$this->assertTrue(FALSE, "update Failed : " . $e->getMessage());
108109
}
109110
}
110111

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

113143
?>

0 commit comments

Comments
 (0)