|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TestMonitor\DevOps\Transforms; |
|
4
|
|
|
|
|
5
|
|
|
use TestMonitor\DevOps\Validator; |
|
6
|
|
|
use TestMonitor\DevOps\Resources\WorkItem; |
|
7
|
|
|
|
|
8
|
|
|
trait TransformsWorkItems |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @param \TestMonitor\DevOps\Resources\WorkItem $workItem |
|
12
|
|
|
* @return array |
|
13
|
|
|
*/ |
|
14
|
2 |
|
protected function toDevOpsWorkItem(WorkItem $workItem): array |
|
15
|
|
|
{ |
|
16
|
2 |
|
return [ |
|
17
|
2 |
|
[ |
|
18
|
2 |
|
'op' => 'add', |
|
19
|
2 |
|
'path' => '/fields/System.Title', |
|
20
|
2 |
|
'from' => null, |
|
21
|
2 |
|
'value' => $workItem->title, |
|
22
|
2 |
|
], |
|
23
|
2 |
|
[ |
|
24
|
2 |
|
'op' => 'add', |
|
25
|
2 |
|
'path' => '/fields/System.Description', |
|
26
|
2 |
|
'from' => null, |
|
27
|
2 |
|
'value' => $workItem->description, |
|
28
|
2 |
|
], |
|
29
|
2 |
|
[ |
|
30
|
2 |
|
'op' => 'add', |
|
31
|
2 |
|
'path' => '/fields/Microsoft.VSTS.TCM.ReproSteps', |
|
32
|
2 |
|
'from' => null, |
|
33
|
2 |
|
'value' => $workItem->stepsToReproduce, |
|
34
|
2 |
|
], |
|
35
|
2 |
|
...($workItem->path ? [ |
|
36
|
2 |
|
[ |
|
37
|
2 |
|
'op' => 'add', |
|
38
|
2 |
|
'path' => '/fields/System.AreaPath', |
|
39
|
2 |
|
'from' => null, |
|
40
|
2 |
|
'value' => $workItem->path, |
|
41
|
2 |
|
], |
|
42
|
|
|
] : []), |
|
43
|
2 |
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param array $workItem |
|
48
|
|
|
* |
|
49
|
|
|
* @throws \TestMonitor\DevOps\Exceptions\InvalidDataException |
|
50
|
|
|
* |
|
51
|
|
|
* @return \TestMonitor\DevOps\Resources\WorkItem |
|
52
|
|
|
*/ |
|
53
|
2 |
|
protected function fromDevOpsWorkItem(array $workItem): WorkItem |
|
54
|
|
|
{ |
|
55
|
2 |
|
Validator::keyExists($workItem, 'fields'); |
|
56
|
|
|
|
|
57
|
2 |
|
return new WorkItem([ |
|
58
|
2 |
|
'id' => $workItem['id'] ?? '', |
|
59
|
2 |
|
'title' => $workItem['fields']['System.Title'], |
|
60
|
2 |
|
'description' => $workItem['fields']['System.Description'] ?? '', |
|
61
|
2 |
|
'path' => $workItem['fields']['System.AreaPath'] ?? '', |
|
62
|
2 |
|
'workItemType' => $workItem['fields']['System.WorkItemType'], |
|
63
|
2 |
|
'stepsToReproduce' => $workItem['fields']['Microsoft.VSTS.TCM.ReproSteps'] ?? '', |
|
64
|
2 |
|
'url' => $workItem['_links']['html']['href'] ?? '', |
|
65
|
2 |
|
]); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|