Skip to content

Commit 512bd8a

Browse files
committed
Merge branch 'feature/process_comment' into develop
2 parents 7935b53 + b5d2a1f commit 512bd8a

File tree

6 files changed

+169
-29
lines changed

6 files changed

+169
-29
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/config.jira.example.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
function getConfig() {
4+
return array(
5+
// JIRA Host config
6+
'host' => 'https://jira.example.com',
7+
'username' => 'username',
8+
'password' => 'password',
9+
10+
// Options
11+
'CURLOPT_SSL_VERIFYHOST' => false,
12+
'CURLOPT_SSL_VERIFYPEER' => false,
13+
'CURLOPT_VERBOSE' => true,
14+
'LOG_FILE' => 'QQjira-rest-client.log',
15+
'LOG_LEVEL' => 'DEBUG'
16+
);
17+
}
18+
19+
?>

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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,30 @@ 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+
$this->log->addDebug("add comment result=" . var_export($ret, true));
118+
$comment = $this->json_mapper->map(
119+
json_decode($ret), new Comment()
120+
);
121+
122+
return $comment;
123+
}
100124
}
101125

102126
?>

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)