1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the GitlabIssueBundle package. |
4
|
|
|
* |
5
|
|
|
* (c) Paul Schweppe <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace VersionControl\GitlabIssueBundle\DataTransformer; |
12
|
|
|
|
13
|
|
|
use VersionControl\GitlabIssueBundle\Entity\Issues\Issue; |
14
|
|
|
use Symfony\Component\Form\Exception\TransformationFailedException; |
|
|
|
|
15
|
|
|
|
16
|
|
|
class IssueToEntityTransformer implements DataTransformerInterface |
17
|
|
|
{ |
18
|
|
|
private $issueLabelTransformer; |
19
|
|
|
|
20
|
|
|
private $issueMilestoneTransformer; |
21
|
|
|
|
22
|
|
|
private $issueCommentTransformer; |
23
|
|
|
|
24
|
|
|
private $userTransformer; |
25
|
|
|
|
26
|
|
|
public function __construct() |
27
|
|
|
{ |
28
|
|
|
$this->issueLabelTransformer = new IssueLabelToEntityTransformer(); |
29
|
|
|
$this->issueMilestoneTransformer = new IssueMilestoneToEntityTransformer(); |
30
|
|
|
$this->issueCommentTransformer = new IssueCommentToEntityTransformer(); |
31
|
|
|
$this->userTransformer = new UserToEntityTransformer(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Transforms an issue array into an issue Entity object. |
36
|
|
|
* |
37
|
|
|
* @param Issue|null $issue |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public function transform($issue) |
42
|
|
|
{ |
43
|
|
|
if (null === $issue) { |
44
|
|
|
return null; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$issueEntity = new Issue(); |
48
|
|
|
$issueEntity->setId($issue['id']); |
49
|
|
|
$issueEntity->setTitle($issue['title']); |
50
|
|
|
$issueEntity->setStatus($this->formatState($issue['state'])); |
51
|
|
|
$issueEntity->setDescription($issue['description']); |
52
|
|
|
$issueEntity->setCreatedAt($this->formatDate($issue['created_at'])); |
53
|
|
|
if (isset($issue['closed_at'])) { |
54
|
|
|
$issueEntity->setClosedAt($this->formatDate($issue['closed_at'])); |
55
|
|
|
} |
56
|
|
|
$issueEntity->setUpdatedAt($this->formatDate($issue['updated_at'])); |
57
|
|
|
|
58
|
|
|
//Map Issue labels |
59
|
|
|
if (isset($issue['labels']) && is_array($issue['labels'])) { |
60
|
|
|
foreach ($issue['labels'] as $label) { |
61
|
|
|
$issueLabelEntity = $this->issueLabelTransformer->transform($label); |
62
|
|
|
$issueEntity->addIssueLabel($issueLabelEntity); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if (isset($issue['author']) && is_array($issue['author'])) { |
67
|
|
|
$user = $this->userTransformer->transform($issue['author']); |
68
|
|
|
$issueEntity->setUser($user); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
if (isset($issue['milestone']) && is_array($issue['milestone'])) { |
71
|
|
|
$issueMilestoneEntity = $this->issueMilestoneTransformer->transform($issue['milestone']); |
72
|
|
|
$issueEntity->setIssueMilestone($issueMilestoneEntity); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $issueEntity; |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Transforms an issue entity into a git api captiable issue array. |
80
|
|
|
* |
81
|
|
|
* @param \VersionControl\GitlabIssueBundle\Entity\Issues $issueEntity |
82
|
|
|
* |
83
|
|
|
* @return array|null |
84
|
|
|
* |
85
|
|
|
* @throws TransformationFailedException if object (issue) is not found |
86
|
|
|
*/ |
87
|
|
|
public function reverseTransform($issueEntity) |
88
|
|
|
{ |
89
|
|
|
if ($issueEntity === null) { |
90
|
|
|
// causes a validation error |
91
|
|
|
throw new TransformationFailedException('IssueEntity is null'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$issue = array( |
95
|
|
|
'title' => $issueEntity->getTitle(), 'description' => $issueEntity->getDescription(), |
96
|
|
|
//,'state' => $issueEntity->getStatus() |
97
|
|
|
//,'milestone' => 0 |
98
|
|
|
); |
99
|
|
|
if ($issueEntity->getIssueMilestone()) { |
100
|
|
|
$issue['milestone_id'] = $issueEntity->getIssueMilestone()->getId(); |
101
|
|
|
} |
102
|
|
|
$labels = array(); |
103
|
|
|
foreach ($issueEntity->getIssueLabel() as $issueLabel) { |
104
|
|
|
$labels[] = $issueLabel->getId(); |
105
|
|
|
} |
106
|
|
|
$issue['labels'] = implode(',', $labels); |
107
|
|
|
|
108
|
|
|
return $issue; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
protected function formatDate($date) |
112
|
|
|
{ |
113
|
|
|
try { |
114
|
|
|
$dateTime = new \DateTime($date); |
115
|
|
|
} catch (Exception $e) { |
|
|
|
|
116
|
|
|
echo $e->getMessage(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $dateTime; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
protected function formatState($state) |
123
|
|
|
{ |
124
|
|
|
if ($state === 'opened' || $state === 'activated') { |
125
|
|
|
return 'open'; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $state; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
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