From dec5cd1120150e5090cb3e07de565de9629c93f2 Mon Sep 17 00:00:00 2001 From: KwangSeob Jeong Date: Thu, 5 Mar 2015 20:30:27 +0900 Subject: [PATCH 1/2] add comment --- src/issue/Comment.php | 55 ++++++++++++++++++++++++++++++++++++++ src/issue/Comments.php | 28 ------------------- src/issue/IssueService.php | 23 ++++++++++++++++ tests/IssueTest.php | 40 +++++++++++++++++++++++---- 4 files changed, 113 insertions(+), 33 deletions(-) create mode 100644 src/issue/Comment.php diff --git a/src/issue/Comment.php b/src/issue/Comment.php new file mode 100644 index 00000000..ed5b0e20 --- /dev/null +++ b/src/issue/Comment.php @@ -0,0 +1,55 @@ +body = $body; + return $this; + } + + public function setVisibility($type, $value) { + if (is_null($this->visibility)) + $this->visibility = array(); + + $this->visibility['type'] = $type; + $this->visibility['value'] = $value; + return $this; + } + + public function jsonSerialize() + { + return array_filter(get_object_vars($this)); + } +} + +?> \ No newline at end of file diff --git a/src/issue/Comments.php b/src/issue/Comments.php index fa01cc88..2b3106ab 100644 --- a/src/issue/Comments.php +++ b/src/issue/Comments.php @@ -2,34 +2,6 @@ namespace JiraRestApi\Issue; -class Comment implements \JsonSerializable { - /* @var string */ - public $self; - - /* @var string */ - public $id; - - /* @var Reporter */ - public $author; - - /* @var string */ - public $body; - - /* @var Reporter */ - public $updateAuthor; - - /* @var DateTime */ - public $created; - - /* @var DateTime */ - public $updated; - - public function jsonSerialize() - { - return array_filter(get_object_vars($this)); - } -} - class Comments implements \JsonSerializable { /* @var int */ public $startAt; diff --git a/src/issue/IssueService.php b/src/issue/IssueService.php index 97794fde..40bb35d4 100644 --- a/src/issue/IssueService.php +++ b/src/issue/IssueService.php @@ -97,6 +97,29 @@ public function update($issueIdOrKey, $issueField) { return $ret; } + + /** + * Adds a new comment to an issue. + * + * @param issueIdOrKey Issue id or key + * @param comment . + * + * @return Comment class + */ + public function addComment($issueIdOrKey, $comment) { + + $this->log->addInfo("addComment=\n"); + + $data = json_encode($comment); + + $ret = $this->exec($this->uri . "/$issueIdOrKey/comment", $data); + + $comment = $this->json_mapper->mapArray( + json_decode($ret), new \ArrayObject(), '\JiraRestApi\Issue\Comment' + ); + + return $comment; + } } ?> diff --git a/tests/IssueTest.php b/tests/IssueTest.php index 3cfa16f9..0e190cdd 100644 --- a/tests/IssueTest.php +++ b/tests/IssueTest.php @@ -2,6 +2,7 @@ use JiraRestApi\Issue\IssueService; use JiraRestApi\Issue\IssueField; +use JiraRestApi\Issue\Comment; class IssueTest extends PHPUnit_Framework_TestCase { @@ -79,14 +80,12 @@ public function testAddAttachment($issueKey) } /** - * depends testAddAttachment + * @depends testAddAttachment * */ - public function testUpdateIssue() + public function testUpdateIssue($issueKey) { - $issueKey = "TEST-920"; - - //$this->markTestIncomplete(); + $this->markTestIncomplete(); try { $issueField = new IssueField(true); @@ -103,11 +102,42 @@ public function testUpdateIssue() $issueService = new IssueService(); $issueService->update($issueKey, $issueField); + + return $issueKey; } catch (JIRAException $e) { $this->assertTrue(FALSE, "update Failed : " . $e->getMessage()); } } + /** + * Depends testUpdateIssue + * + */ + public function testAddcommnet() + { + $issueKey = "TEST-924"; + //$this->markTestIncomplete(); + try { + $comment = new Comment(); + + $body = <<setBody($body) + ->setVisibility('role', 'Users'); + ; + + $issueService = new IssueService(); + $ret = $issueService->addComment($issueKey, $comment); + print_r($ret); + } catch (JIRAException $e) { + $this->assertTrue(FALSE, "add Comment Failed : " . $e->getMessage()); + } + } } ?> From b5d2a1fe2afa1ddd2db84167db0634db982e052e Mon Sep 17 00:00:00 2001 From: KwangSeob Jeong Date: Mon, 9 Mar 2015 09:49:09 +0900 Subject: [PATCH 2/2] impl add comment. --- README.md | 36 ++++++++++++++++++++++++++++++++++++ src/issue/IssueService.php | 5 +++-- tests/IssueTest.php | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8a17cac1..1e69648e 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,42 @@ try { ?> ```` +## Add comment + +````php +setBody($body) + ->setVisibility('role', 'Users'); + ; + + $issueService = new IssueService(); + $ret = $issueService->addComment($issueKey, $comment); + print_r($ret); +} catch (JIRAException $e) { + $this->assertTrue(FALSE, "add Comment Failed : " . $e->getMessage()); +} + +?> +```` + # License Apache V2 License diff --git a/src/issue/IssueService.php b/src/issue/IssueService.php index eebda2d5..196fa077 100644 --- a/src/issue/IssueService.php +++ b/src/issue/IssueService.php @@ -114,8 +114,9 @@ public function addComment($issueIdOrKey, $comment) { $ret = $this->exec($this->uri . "/$issueIdOrKey/comment", $data); - $comment = $this->json_mapper->mapArray( - json_decode($ret), new \ArrayObject(), '\JiraRestApi\Issue\Comment' + $this->log->addDebug("add comment result=" . var_export($ret, true)); + $comment = $this->json_mapper->map( + json_decode($ret), new Comment() ); return $comment; diff --git a/tests/IssueTest.php b/tests/IssueTest.php index 49ec1135..7809a554 100644 --- a/tests/IssueTest.php +++ b/tests/IssueTest.php @@ -2,6 +2,7 @@ use JiraRestApi\Issue\IssueService; use JiraRestApi\Issue\IssueField; +use JiraRestApi\Issue\Comment; class IssueTest extends PHPUnit_Framework_TestCase { @@ -86,7 +87,7 @@ public function testUpdateIssue($issueKey) try { $issueField = new IssueField(true); - $issueField->setAssigneeName("admin") + $issueField->setAssigneeName("lesstif") ->setPriorityName("Major") ->setIssueType("Task") ->addLabel("test-label-first") @@ -99,11 +100,44 @@ public function testUpdateIssue($issueKey) $issueService = new IssueService(); $issueService->update($issueKey, $issueField); + + return $issueKey; } catch (JIRAException $e) { $this->assertTrue(FALSE, "update Failed : " . $e->getMessage()); } } + /** + * @depends testUpdateIssue + * + */ + public function testAddcommnet($issueKey) + { + //$this->markTestIncomplete(); + try { + $comment = new Comment(); + + $body = <<setBody($body) + ->setVisibility('role', 'Users'); + ; + + $issueService = new IssueService(); + $ret = $issueService->addComment($issueKey, $comment); + print_r($ret); + + return $issueKey; + } catch (JIRAException $e) { + $this->assertTrue(FALSE, "add Comment Failed : " . $e->getMessage()); + } + } + } ?>