Skip to content

Commit

Permalink
Merge branch 'feature/process_comment' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lesstif committed Mar 9, 2015
2 parents 7935b53 + b5d2a1f commit 512bd8a
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 29 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,42 @@ try {
?>
````

## Add comment

````php
<?php
require 'vendor/autoload.php';

use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\Comment;

$issueKey = "TEST-879";

try {
$comment = new Comment();

$body = <<<COMMENT
Adds a new comment to an issue.
* Bullet 1
* Bullet 2
** sub Bullet 1
** sub Bullet 2
* Bullet 3
COMMENT;
$comment->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
Expand Down
19 changes: 19 additions & 0 deletions src/config.jira.example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

function getConfig() {
return array(
// JIRA Host config
'host' => 'https://jira.example.com',
'username' => 'username',
'password' => 'password',

// Options
'CURLOPT_SSL_VERIFYHOST' => false,
'CURLOPT_SSL_VERIFYPEER' => false,
'CURLOPT_VERBOSE' => true,
'LOG_FILE' => 'QQjira-rest-client.log',
'LOG_LEVEL' => 'DEBUG'
);
}

?>
55 changes: 55 additions & 0 deletions src/issue/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace JiraRestApi\Issue;

class Visibility {
public $type;
public $value;
}

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;

/* @var Visibility */
public $visibility;

public function setBody($body) {
$this->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));
}
}

?>
28 changes: 0 additions & 28 deletions src/issue/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions src/issue/IssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ 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);

$this->log->addDebug("add comment result=" . var_export($ret, true));
$comment = $this->json_mapper->map(
json_decode($ret), new Comment()
);

return $comment;
}
}

?>
Expand Down
36 changes: 35 additions & 1 deletion tests/IssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\IssueField;
use JiraRestApi\Issue\Comment;

class IssueTest extends PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -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")
Expand All @@ -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 = <<<COMMENT
Adds a new comment to an issue.
* Bullet 1
* Bullet 2
** sub Bullet 1
** sub Bullet 2
COMMENT;
$comment->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());
}
}

}

?>

0 comments on commit 512bd8a

Please sign in to comment.