testmonitor /
devops-client
| 1 | <?php |
||
| 2 | |||
| 3 | namespace TestMonitor\DevOps\Actions; |
||
| 4 | |||
| 5 | use TestMonitor\DevOps\Support\Arrays; |
||
| 6 | use TestMonitor\DevOps\Transforms\TransformsStates; |
||
| 7 | |||
| 8 | trait ManagesStates |
||
| 9 | { |
||
| 10 | use TransformsStates; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Get a list of states for a project. |
||
| 14 | * |
||
| 15 | * @param string $projectId |
||
| 16 | * @param string $workItemType |
||
| 17 | * @return \TestMonitor\DevOps\Resources\States[] |
||
| 18 | */ |
||
| 19 | 6 | public function states($projectId) |
|
| 20 | { |
||
| 21 | 6 | $process = $this->findCurrentProjectProcess($projectId); |
|
| 22 | |||
| 23 | 1 | $response = $this->get("_apis/work/processes/{$process}/workitemtypes", [ |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 24 | 1 | 'query' => ['$expand' => 'states'], |
|
| 25 | 1 | ]); |
|
| 26 | |||
| 27 | 1 | $states = Arrays::unique( |
|
| 28 | 1 | Arrays::flatten( |
|
| 29 | 1 | array_column($response['value'], 'states') |
|
| 30 | 1 | ), |
|
| 31 | 1 | 'id' |
|
| 32 | 1 | ); |
|
| 33 | |||
| 34 | 1 | return $this->fromDevOpsStates($states); |
|
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Determine the process ID for the provided project. |
||
| 39 | * |
||
| 40 | * @param string $projectId |
||
| 41 | * @return string |
||
| 42 | */ |
||
| 43 | 6 | protected function findCurrentProjectProcess($projectId) |
|
| 44 | { |
||
| 45 | 6 | $response = $this->get("_apis/projects/{$projectId}/properties", [ |
|
| 46 | 6 | 'query' => ['api-version' => $this->previewApiVersion], |
|
| 47 | 6 | ]); |
|
| 48 | |||
| 49 | 1 | $property = current( |
|
| 50 | 1 | array_filter($response['value'], fn ($property) => $property['name'] === 'System.CurrentProcessTemplateId'), |
|
| 51 | 1 | ); |
|
| 52 | |||
| 53 | 1 | return $property['value']; |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Get a list of states for a project and work item type. |
||
| 58 | * |
||
| 59 | * @param string $projectId |
||
| 60 | * @param string $workItemType |
||
| 61 | * @return \TestMonitor\DevOps\Resources\States[] |
||
| 62 | */ |
||
| 63 | 6 | public function statesForWorkItem($projectId, $workItemType) |
|
| 64 | { |
||
| 65 | 6 | $response = $this->get("{$projectId}/_apis/wit/workitemtypes/{$workItemType}/states"); |
|
| 66 | |||
| 67 | 1 | return $this->fromDevOpsStates($response['value']); |
|
| 68 | } |
||
| 69 | } |
||
| 70 |