1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JiraRestApi\Project; |
4
|
|
|
|
5
|
|
|
use JiraRestApi\Issue\IssueType; |
6
|
|
|
use JiraRestApi\Issue\Reporter; |
7
|
|
|
use JiraRestApi\Issue\Version; |
8
|
|
|
use JiraRestApi\JiraException; |
9
|
|
|
|
10
|
|
|
class ProjectService extends \JiraRestApi\JiraClient |
11
|
|
|
{ |
12
|
|
|
private $uri = '/project'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* get all project list. |
16
|
|
|
* |
17
|
|
|
* @param array $paramArray |
18
|
|
|
* |
19
|
|
|
* @throws \JiraRestApi\JiraException |
20
|
|
|
* |
21
|
|
|
* @return Project[] array of Project class |
22
|
|
|
*/ |
23
|
|
|
public function getAllProjects($paramArray = []) |
24
|
|
|
{ |
25
|
|
|
$ret = $this->exec($this->uri.$this->toHttpQueryParameter($paramArray), null); |
26
|
|
|
|
27
|
|
|
$prjs = $this->json_mapper->mapArray( |
28
|
|
|
json_decode($ret, false), |
29
|
|
|
new \ArrayObject(), |
30
|
|
|
'\JiraRestApi\Project\Project' |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
return $prjs; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* get Project id By Project Key. |
38
|
|
|
* throws HTTPException if the project is not found, or the calling user does not have permission or view it. |
39
|
|
|
* |
40
|
|
|
* @param string|int $projectIdOrKey projectName or Project Key(Ex: Test, MyProj) |
41
|
|
|
* |
42
|
|
|
* @throws \JiraRestApi\JiraException |
43
|
|
|
* @throws \JsonMapper_Exception |
44
|
|
|
* |
45
|
|
|
* @return Project|object |
46
|
|
|
*/ |
47
|
|
|
public function get($projectIdOrKey) |
48
|
|
|
{ |
49
|
|
|
$ret = $this->exec($this->uri."/$projectIdOrKey", null); |
50
|
|
|
|
51
|
|
|
$this->log->info('Result='.$ret); |
52
|
|
|
|
53
|
|
|
$prj = $this->json_mapper->map( |
54
|
|
|
json_decode($ret), |
55
|
|
|
new Project() |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
return $prj; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* get assignable Users for a given project. |
63
|
|
|
* throws HTTPException if the project is not found, or the calling user does not have permission or view it. |
64
|
|
|
* |
65
|
|
|
* @param string|int projectIdOrKey Project Key |
|
|
|
|
66
|
|
|
* |
67
|
|
|
* @throws \JiraRestApi\JiraException |
68
|
|
|
* |
69
|
|
|
* @return Reporter[] |
70
|
|
|
*/ |
71
|
|
|
public function getAssignable($projectIdOrKey) |
72
|
|
|
{ |
73
|
|
|
$ret = $this->exec("/user/assignable/search?project=$projectIdOrKey", null); |
74
|
|
|
$json = json_decode($ret); |
75
|
|
|
$results = array_map(function ($elem) { |
76
|
|
|
return $this->json_mapper->map($elem, new Reporter()); |
77
|
|
|
}, $json); |
78
|
|
|
|
79
|
|
|
return $results; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string|int $projectIdOrKey |
84
|
|
|
* |
85
|
|
|
* @throws \JiraRestApi\JiraException |
86
|
|
|
* |
87
|
|
|
* @return IssueType[] |
88
|
|
|
*/ |
89
|
|
|
public function getStatuses($projectIdOrKey) |
90
|
|
|
{ |
91
|
|
|
$ret = $this->exec($this->uri."/$projectIdOrKey/statuses", null); |
92
|
|
|
$json = json_decode($ret); |
93
|
|
|
$results = array_map(function ($elem) { |
94
|
|
|
return $this->json_mapper->map($elem, new IssueType()); |
95
|
|
|
}, $json); |
96
|
|
|
|
97
|
|
|
return $results; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* make transition info array for project issue transition. |
102
|
|
|
* |
103
|
|
|
* @param $projectIdOrKey |
104
|
|
|
* @return array |
105
|
|
|
* @throws JiraException |
106
|
|
|
*/ |
107
|
|
|
public function getProjectTransitionsToArray($projectIdOrKey) |
108
|
|
|
{ |
109
|
|
|
$ret = $this->exec($this->uri."/$projectIdOrKey/statuses", null); |
110
|
|
|
$json = json_decode($ret); |
111
|
|
|
$results = array_map(function ($elem) { |
112
|
|
|
return $this->json_mapper->map($elem, new IssueType()); |
113
|
|
|
}, $json); |
114
|
|
|
|
115
|
|
|
$transitions = []; |
116
|
|
|
foreach ($results as $issueType) { |
117
|
|
|
foreach ($issueType->statuses as $status) { |
118
|
|
|
|
119
|
|
|
if (! in_array($status->id, array_column($transitions, 'id'))) { |
120
|
|
|
$transitions[] = [ |
121
|
|
|
'id' => $status->id, |
122
|
|
|
'name' => $status->name, |
123
|
|
|
'untranslatedName' => $status->untranslatedName ?? $status->name, |
124
|
|
|
]; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return $transitions; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @throws \JiraRestApi\JiraException |
134
|
|
|
* |
135
|
|
|
* @return ProjectType[] |
136
|
|
|
*/ |
137
|
|
|
public function getProjectTypes() |
138
|
|
|
{ |
139
|
|
|
$ret = $this->exec($this->uri.'/type'); |
140
|
|
|
|
141
|
|
|
$this->log->info('Result='.$ret); |
142
|
|
|
|
143
|
|
|
$json = json_decode($ret); |
144
|
|
|
$results = array_map(function ($elem) { |
145
|
|
|
return $this->json_mapper->map($elem, new ProjectType()); |
146
|
|
|
}, $json); |
147
|
|
|
|
148
|
|
|
return $results; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param string|int $key |
153
|
|
|
* |
154
|
|
|
* @throws \JiraRestApi\JiraException |
155
|
|
|
* @throws \JsonMapper_Exception |
156
|
|
|
* |
157
|
|
|
* @return ProjectType|object |
158
|
|
|
*/ |
159
|
|
|
public function getProjectType($key) |
160
|
|
|
{ |
161
|
|
|
$ret = $this->exec($this->uri."/type/$key"); |
162
|
|
|
|
163
|
|
|
$this->log->info('Result='.$ret); |
164
|
|
|
|
165
|
|
|
$type = $this->json_mapper->map( |
166
|
|
|
json_decode($ret, false), |
167
|
|
|
new ProjectType() |
168
|
|
|
); |
169
|
|
|
|
170
|
|
|
return $type; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param string|int $key |
175
|
|
|
* |
176
|
|
|
* @throws \JiraRestApi\JiraException |
177
|
|
|
* @throws \JsonMapper_Exception |
178
|
|
|
* |
179
|
|
|
* @return ProjectType|object |
180
|
|
|
*/ |
181
|
|
|
public function getAccessibleProjectType($key) |
182
|
|
|
{ |
183
|
|
|
$ret = $this->exec($this->uri."/type/$key/accessible"); |
184
|
|
|
|
185
|
|
|
$this->log->info('Result='.$ret); |
186
|
|
|
|
187
|
|
|
$type = $this->json_mapper->map( |
188
|
|
|
json_decode($ret, false), |
189
|
|
|
new ProjectType() |
190
|
|
|
); |
191
|
|
|
|
192
|
|
|
return $type; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* get pagenated Project versions. |
197
|
|
|
* |
198
|
|
|
* @param string|int $projectIdOrKey |
199
|
|
|
* @param array $queryParam |
200
|
|
|
* |
201
|
|
|
* @throws \JiraRestApi\JiraException |
202
|
|
|
* |
203
|
|
|
* @return Version[] array of version |
204
|
|
|
*/ |
205
|
|
|
public function getVersionsPagenated($projectIdOrKey, $queryParam = []) |
206
|
|
|
{ |
207
|
|
|
$default = [ |
208
|
|
|
'startAt' => 0, |
209
|
|
|
'maxResults' => 50, |
210
|
|
|
// order by following field: sequence, name, startDate, releaseDate |
211
|
|
|
//'orderBy' => null, |
212
|
|
|
//'expand' => null, |
213
|
|
|
]; |
214
|
|
|
|
215
|
|
|
$param = $this->toHttpQueryParameter( |
216
|
|
|
array_merge($default, $queryParam) |
217
|
|
|
); |
218
|
|
|
|
219
|
|
|
$ret = $this->exec($this->uri."/$projectIdOrKey/version".$param); |
220
|
|
|
|
221
|
|
|
$this->log->info('Result='.$ret); |
222
|
|
|
|
223
|
|
|
//@see https://docs.atlassian.com/jira/REST/server/#api/2/project-getProjectVersions |
224
|
|
|
$json = json_decode($ret); |
225
|
|
|
|
226
|
|
|
$versions = $this->json_mapper->mapArray( |
227
|
|
|
$json->values, |
228
|
|
|
new \ArrayObject(), |
229
|
|
|
'\JiraRestApi\Issue\Version' |
230
|
|
|
); |
231
|
|
|
|
232
|
|
|
return $versions; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* get specified's project versions. |
237
|
|
|
* |
238
|
|
|
* @param string|int $projectIdOrKey |
239
|
|
|
* |
240
|
|
|
* @throws \JiraRestApi\JiraException |
241
|
|
|
* |
242
|
|
|
* @return Version[] array of version |
243
|
|
|
*/ |
244
|
|
|
public function getVersions($projectIdOrKey) |
245
|
|
|
{ |
246
|
|
|
$ret = $this->exec($this->uri."/$projectIdOrKey/versions"); |
247
|
|
|
|
248
|
|
|
$this->log->info('Result='.$ret); |
249
|
|
|
|
250
|
|
|
$versions = $this->json_mapper->mapArray( |
251
|
|
|
json_decode($ret, false), |
252
|
|
|
new \ArrayObject(), |
253
|
|
|
'\JiraRestApi\Issue\Version' |
254
|
|
|
); |
255
|
|
|
|
256
|
|
|
return $versions; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* get specified's project version. |
261
|
|
|
* |
262
|
|
|
* @param string|int $projectIdOrKey |
263
|
|
|
* @param string $versionName |
264
|
|
|
* |
265
|
|
|
* @throws \JiraRestApi\JiraException |
266
|
|
|
* |
267
|
|
|
* @return Version version |
268
|
|
|
*/ |
269
|
|
|
public function getVersion($projectIdOrKey, $versionName) |
270
|
|
|
{ |
271
|
|
|
$ret = $this->exec($this->uri."/$projectIdOrKey/versions"); |
272
|
|
|
|
273
|
|
|
$this->log->info('Result='.$ret); |
274
|
|
|
|
275
|
|
|
$versions = $this->json_mapper->mapArray( |
276
|
|
|
json_decode($ret, false), |
277
|
|
|
new \ArrayObject(), |
278
|
|
|
'\JiraRestApi\Issue\Version' |
279
|
|
|
); |
280
|
|
|
|
281
|
|
|
foreach ($versions as $v) { |
282
|
|
|
if ($v->name === $versionName) { |
283
|
|
|
return $v; |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
throw new JiraException("Can't found version \"$versionName\" in the Project \"$projectIdOrKey\""); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Creates a new project. |
292
|
|
|
* |
293
|
|
|
* @param Project $project |
294
|
|
|
* |
295
|
|
|
* @throws JiraException |
296
|
|
|
* |
297
|
|
|
* @return Project project |
298
|
|
|
*/ |
299
|
|
|
public function createProject($project) |
300
|
|
|
{ |
301
|
|
|
$data = json_encode($project); |
302
|
|
|
|
303
|
|
|
$ret = $this->exec($this->uri, $data, 'POST'); |
304
|
|
|
|
305
|
|
|
$this->log->info('createProject Result='.$ret); |
306
|
|
|
|
307
|
|
|
return $this->json_mapper->map( |
308
|
|
|
json_decode($ret), |
309
|
|
|
new Project() |
310
|
|
|
); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* Updates a project. |
315
|
|
|
* |
316
|
|
|
* Only non null values sent in JSON will be updated in the project. |
317
|
|
|
* Values available for the assigneeType field are: "PROJECT_LEAD" and "UNASSIGNED". |
318
|
|
|
* |
319
|
|
|
* @param Project $project |
320
|
|
|
* |
321
|
|
|
* @throws JiraException |
322
|
|
|
* @throws \JsonMapper_Exception |
323
|
|
|
* |
324
|
|
|
* @return Project project |
325
|
|
|
*/ |
326
|
|
|
public function updateProject($project, $projectIdOrKey) |
327
|
|
|
{ |
328
|
|
|
$data = json_encode($project); |
329
|
|
|
|
330
|
|
|
$ret = $this->exec($this->uri.'/'.$projectIdOrKey, $data, 'PUT'); |
331
|
|
|
|
332
|
|
|
$this->log->info('updateProject Result='.$ret); |
333
|
|
|
|
334
|
|
|
return $this->json_mapper->map( |
335
|
|
|
json_decode($ret), |
336
|
|
|
new Project() |
337
|
|
|
); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @param string $projectIdOrKey |
342
|
|
|
* |
343
|
|
|
* @throws JiraException |
344
|
|
|
* |
345
|
|
|
* @return int response status |
346
|
|
|
* |
347
|
|
|
* STATUS 401 Returned if the user is not logged in. |
348
|
|
|
* STATUS 204 - application/json Returned if the project is successfully deleted. |
349
|
|
|
* STATUS 403 - Returned if the currently authenticated user does not have permission to delete the project. |
350
|
|
|
* STATUS 404 - Returned if the project does not exist. |
351
|
|
|
*/ |
352
|
|
|
public function deleteProject($projectIdOrKey) |
353
|
|
|
{ |
354
|
|
|
$ret = $this->exec($this->uri.'/'.$projectIdOrKey, null, 'DELETE'); |
355
|
|
|
|
356
|
|
|
return $ret; |
|
|
|
|
357
|
|
|
} |
358
|
|
|
} |
359
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths