1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © 2017 Toan Nguyen. All rights reserved. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Gojira\Jira\Endpoint; |
10
|
|
|
|
11
|
|
|
use Gojira\Framework\Serializer\Serializer; |
12
|
|
|
use Gojira\Api\Endpoint\EndpointInterface; |
13
|
|
|
use Gojira\Api\Request\HttpMethod; |
14
|
|
|
use Gojira\Api\Response\ResponseInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Endpoint for JIRA REST /transitions |
18
|
|
|
* |
19
|
|
|
* @package Gojira\Jira\Endpoint |
20
|
|
|
* @author Toan Nguyen <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class TransitionEndpoint extends IssueEndpoint implements EndpointInterface |
23
|
|
|
{ |
24
|
|
|
const EP_TRANSITIONS = 'transitions'; |
25
|
|
|
|
26
|
|
|
const PARAM_EXPAND = 'expand'; |
27
|
|
|
|
28
|
|
|
const PAYLOAD_TRANSITION = 'transition'; |
29
|
|
|
const PAYLOAD_FIELDS = 'fields'; |
30
|
|
|
const PAYLOAD_RESOLUTION = 'resolution'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Returns a full representation of the transitions possible for the specified issue and the fields required to |
34
|
|
|
* perform the transition. [STATUS 200] |
35
|
|
|
* |
36
|
|
|
* @param string $issue JIRA ticket number |
37
|
|
|
* |
38
|
|
|
* @param string|null $expand [optional] Fields will only be returned if expand=transitions.fields. |
39
|
|
|
* |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
public function getTransitions( |
43
|
|
|
$issue, |
44
|
|
|
$expand = null |
45
|
|
|
) { |
46
|
|
|
$parameters = [ |
47
|
|
|
self::PARAM_EXPAND => $expand |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
return $this->apiClient->callEndpoint( |
51
|
|
|
__e('%1/%2/%3', self::ENDPOINT, $issue, self::EP_TRANSITIONS), |
52
|
|
|
$parameters |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Perform a transition on an issue [STATUS 204] |
58
|
|
|
* |
59
|
|
|
* @param string $issue JIRA ticket number |
60
|
|
|
* |
61
|
|
|
* @param string $transitionId Transition ID |
62
|
|
|
* @param string|null $resolutionId [optional] Resolution ID |
63
|
|
|
* |
64
|
|
|
* @param string|null $expand [optional] Fields will only be returned if expand=transitions.fields. |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
public function doTransition( |
69
|
|
|
$issue, |
70
|
|
|
$transitionId, |
71
|
|
|
$resolutionId = null, |
72
|
|
|
$expand = null |
73
|
|
|
) { |
74
|
|
|
$parameters = [ |
75
|
|
|
self::PARAM_EXPAND => $expand |
76
|
|
|
]; |
77
|
|
|
$payload = [ |
78
|
|
|
self::PAYLOAD_TRANSITION => [ |
79
|
|
|
ResponseInterface::ID => $transitionId |
80
|
|
|
] |
81
|
|
|
]; |
82
|
|
|
if (!empty($resolutionId)) { |
83
|
|
|
$fields = [ |
84
|
|
|
self::PAYLOAD_FIELDS => [ |
85
|
|
|
self::PAYLOAD_RESOLUTION => [ |
86
|
|
|
ResponseInterface::ID => $resolutionId |
87
|
|
|
] |
88
|
|
|
] |
89
|
|
|
]; |
90
|
|
|
$payload = array_merge($payload, $fields); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $this->apiClient->callEndpoint( |
94
|
|
|
__e('%1/%2/%3', self::ENDPOINT, $issue, self::EP_TRANSITIONS), |
95
|
|
|
$parameters, |
96
|
|
|
Serializer::encode($payload), |
97
|
|
|
HttpMethod::POST |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|