|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JiraRestApi\Version; |
|
4
|
|
|
|
|
5
|
|
|
use JiraRestApi\Issue\Version; |
|
6
|
|
|
use JiraRestApi\Issue\VersionUnresolvedCount; |
|
7
|
|
|
use JiraRestApi\Issue\VersionIssueCounts; |
|
8
|
|
|
use JiraRestApi\JiraException; |
|
9
|
|
|
use JiraRestApi\Project\ProjectService; |
|
10
|
|
|
|
|
11
|
|
|
class VersionService extends \JiraRestApi\JiraClient |
|
12
|
|
|
{ |
|
13
|
|
|
private $uri = '/version'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Function to create a new project version. |
|
17
|
|
|
* |
|
18
|
|
|
* @param Version|array $version |
|
19
|
|
|
* |
|
20
|
|
|
* @throws \JiraRestApi\JiraException |
|
21
|
|
|
* @throws \JsonMapper_Exception |
|
22
|
|
|
* |
|
23
|
|
|
* @return Version Version class |
|
24
|
|
|
*/ |
|
25
|
|
|
public function create($version) |
|
26
|
|
|
{ |
|
27
|
|
|
if ($version->releaseDate instanceof \DateTime) { |
|
28
|
|
|
$version->releaseDate = $version->releaseDate->format('Y-m-d'); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
$data = json_encode($version); |
|
31
|
|
|
|
|
32
|
|
|
$this->log->addInfo("Create Version=\n".$data); |
|
33
|
|
|
|
|
34
|
|
|
$ret = $this->exec($this->uri, $data, 'POST'); |
|
35
|
|
|
|
|
36
|
|
|
return $this->json_mapper->map( |
|
37
|
|
|
json_decode($ret), new Version() |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Modify a version's sequence within a project. |
|
43
|
|
|
* |
|
44
|
|
|
* @param $version |
|
45
|
|
|
* |
|
46
|
|
|
* @throws JiraException |
|
47
|
|
|
*/ |
|
48
|
|
|
public function move($version) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
throw new JiraException('move version not yet implemented'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* get project version. |
|
55
|
|
|
* |
|
56
|
|
|
* @param $id version id |
|
57
|
|
|
* |
|
58
|
|
|
* @return Version |
|
59
|
|
|
* |
|
60
|
|
|
* @see ProjectService::getVersions() |
|
61
|
|
|
*/ |
|
62
|
|
|
public function get($id) |
|
63
|
|
|
{ |
|
64
|
|
|
$ret = $this->exec($this->uri.'/'.$id); |
|
65
|
|
|
|
|
66
|
|
|
$this->log->addInfo('Result='.$ret); |
|
67
|
|
|
|
|
68
|
|
|
$json = json_decode($ret); |
|
69
|
|
|
$results = array_map(function ($elem) { |
|
70
|
|
|
return $this->json_mapper->map($elem, new ProjectType()); |
|
|
|
|
|
|
71
|
|
|
}, $json); |
|
72
|
|
|
|
|
73
|
|
|
return $results; |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @author Martijn Smidt <[email protected]> |
|
78
|
|
|
* |
|
79
|
|
|
* @param Version $version |
|
80
|
|
|
* |
|
81
|
|
|
* @throws JiraException |
|
82
|
|
|
* |
|
83
|
|
|
* @return Version |
|
84
|
|
|
*/ |
|
85
|
|
|
public function update(Version $version) |
|
86
|
|
|
{ |
|
87
|
|
|
if (!$version->id || !is_numeric($version->id)) { |
|
88
|
|
|
throw new JiraException($version->id.' is not a valid version id.'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if ($version->releaseDate instanceof \DateTime) { |
|
92
|
|
|
$version->releaseDate = $version->releaseDate->format('Y-m-d'); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
//Only one of 'releaseDate' and 'userReleaseDate' can be specified when editing a version." |
|
96
|
|
|
$version->userReleaseDate = null; |
|
97
|
|
|
|
|
98
|
|
|
$data = json_encode($version); |
|
99
|
|
|
$ret = $this->exec($this->uri.'/'.$version->id, $data, 'PUT'); |
|
100
|
|
|
|
|
101
|
|
|
return $this->json_mapper->map( |
|
102
|
|
|
json_decode($ret), new Version() |
|
103
|
|
|
); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @author Martijn Smidt <[email protected]> |
|
108
|
|
|
* |
|
109
|
|
|
* @param Version $version |
|
110
|
|
|
* @param Version|bool $moveAffectedIssuesTo |
|
111
|
|
|
* @param Version|bool $moveFixIssuesTo |
|
112
|
|
|
* |
|
113
|
|
|
* @throws JiraException |
|
114
|
|
|
* |
|
115
|
|
|
* @return bool |
|
116
|
|
|
*/ |
|
117
|
|
|
public function delete(Version $version, $moveAffectedIssuesTo = false, $moveFixIssuesTo = false) |
|
118
|
|
|
{ |
|
119
|
|
|
if (!$version->id || !is_numeric($version->id)) { |
|
120
|
|
|
throw new JiraException($version->id.' is not a valid version id.'); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
$data = []; |
|
124
|
|
|
|
|
125
|
|
|
if ($moveAffectedIssuesTo && $moveAffectedIssuesTo instanceof Version) { |
|
126
|
|
|
$data['moveAffectedIssuesTo'] = $moveAffectedIssuesTo->name; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
if ($moveFixIssuesTo && $moveFixIssuesTo instanceof Version) { |
|
130
|
|
|
$data['moveFixIssuesTo'] = $moveFixIssuesTo->name; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
$ret = $this->exec($this->uri.'/'.$version->id, json_encode($data), 'DELETE'); |
|
134
|
|
|
|
|
135
|
|
|
return $ret; |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function merge($ver) |
|
|
|
|
|
|
139
|
|
|
{ |
|
140
|
|
|
throw new JiraException('merge version not yet implemented'); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Returns a bean containing the number of fixed in and affected issues for the given version. |
|
145
|
|
|
* |
|
146
|
|
|
* @param Version $version |
|
147
|
|
|
* |
|
148
|
|
|
* @throws JiraException |
|
149
|
|
|
* |
|
150
|
|
|
* @see https://docs.atlassian.com/jira/REST/server/#api/2/version-getVersionRelatedIssues |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getRelatedIssues(Version $version) |
|
153
|
|
|
{ |
|
154
|
|
|
if (!$version->id || !is_numeric($version->id)) { |
|
155
|
|
|
throw new JiraException($version->id.' is not a valid version id.'); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
$ret = $this->exec($this->uri.'/'.$version->id.'/relatedIssueCounts'); |
|
159
|
|
|
|
|
160
|
|
|
return $this->json_mapper->map( |
|
161
|
|
|
json_decode($ret), |
|
162
|
|
|
new VersionIssueCounts() |
|
163
|
|
|
); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Returns a bean containing the number of unresolved issues for the given version. |
|
168
|
|
|
* |
|
169
|
|
|
* @param Version $version |
|
170
|
|
|
* |
|
171
|
|
|
* @throws JiraException |
|
172
|
|
|
* |
|
173
|
|
|
* @see https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/version-getVersionUnresolvedIssues |
|
174
|
|
|
* |
|
175
|
|
|
* @return VersionUnresolvedCount |
|
176
|
|
|
*/ |
|
177
|
|
|
public function getUnresolvedIssues(Version $version) |
|
178
|
|
|
{ |
|
179
|
|
|
if (!$version->id || !is_numeric($version->id)) { |
|
180
|
|
|
throw new JiraException($version->id.' is not a valid version id.'); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
$ret = $this->exec($this->uri.'/'.$version->id.'/unresolvedIssueCount'); |
|
184
|
|
|
|
|
185
|
|
|
return $this->json_mapper->map( |
|
186
|
|
|
json_decode($ret), |
|
187
|
|
|
new VersionUnresolvedCount() |
|
188
|
|
|
); |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..