|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JiraRestApi\Request; |
|
4
|
|
|
|
|
5
|
|
|
use JiraRestApi\Configuration\ConfigurationInterface; |
|
6
|
|
|
use JiraRestApi\JiraException; |
|
7
|
|
|
use JiraRestApi\ServiceDeskTrait; |
|
8
|
|
|
use Psr\Log\LoggerInterface; |
|
9
|
|
|
|
|
10
|
|
|
class RequestService extends \JiraRestApi\JiraClient |
|
11
|
|
|
{ |
|
12
|
|
|
use ServiceDeskTrait; |
|
13
|
|
|
|
|
14
|
|
|
private $uri = '/request'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Constructor. |
|
18
|
|
|
* |
|
19
|
|
|
* @param ConfigurationInterface $configuration |
|
20
|
|
|
* @param LoggerInterface $logger |
|
21
|
|
|
* @param string $path |
|
22
|
|
|
* |
|
23
|
|
|
* @throws JiraException |
|
24
|
|
|
* @throws \Exception |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(ConfigurationInterface $configuration = null, LoggerInterface $logger = null, $path = './') |
|
27
|
|
|
{ |
|
28
|
|
|
parent::__construct($configuration, $logger, $path); |
|
29
|
|
|
$this->setupAPIUri(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Add the given comment to the specified request based on the provided $issueIdOrKey value. Returns a new |
|
34
|
|
|
* RequestComment with the response. |
|
35
|
|
|
* |
|
36
|
|
|
* @param string|int $issueIdOrKey |
|
37
|
|
|
* @param RequestComment $requestComment |
|
38
|
|
|
* @return RequestComment |
|
39
|
|
|
* @throws JiraException |
|
40
|
|
|
* @throws \JsonMapper_Exception |
|
41
|
|
|
*/ |
|
42
|
|
|
public function addComment($issueIdOrKey, RequestComment $requestComment): RequestComment |
|
43
|
|
|
{ |
|
44
|
|
|
$this->log->info("addComment=\n"); |
|
45
|
|
|
|
|
46
|
|
|
if (empty($requestComment->body)) { |
|
47
|
|
|
throw new JiraException('comment param must be an instance of RequestComment and have body text.'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$data = json_encode($requestComment); |
|
51
|
|
|
|
|
52
|
|
|
$ret = $this->exec($this->uri . "/$issueIdOrKey/comment", $data); |
|
53
|
|
|
|
|
54
|
|
|
$this->log->debug('add comment result=' . var_export($ret, true)); |
|
55
|
|
|
$requestComment = $this->json_mapper->map( |
|
56
|
|
|
json_decode($ret), |
|
|
|
|
|
|
57
|
|
|
new RequestComment() |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
return $requestComment; |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|