|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the GithubIssueBundle 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\GithubIssueBundle\DataTransformer; |
|
12
|
|
|
|
|
13
|
|
|
use VersionControl\GithubIssueBundle\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['number']); |
|
49
|
|
|
$issueEntity->setTitle($issue['title']); |
|
50
|
|
|
$issueEntity->setStatus($issue['state']); |
|
51
|
|
|
$issueEntity->setDescription($issue['body']); |
|
52
|
|
|
$issueEntity->setCreatedAt($this->formatDate($issue['created_at'])); |
|
53
|
|
|
$issueEntity->setClosedAt($this->formatDate($issue['closed_at'])); |
|
54
|
|
|
$issueEntity->setUpdatedAt($this->formatDate($issue['updated_at'])); |
|
55
|
|
|
|
|
56
|
|
|
//Map Issue labels |
|
57
|
|
|
if (isset($issue['labels']) && is_array($issue['labels'])) { |
|
58
|
|
|
foreach ($issue['labels'] as $label) { |
|
59
|
|
|
$issueLabelEntity = $this->issueLabelTransformer->transform($label); |
|
60
|
|
|
$issueEntity->addIssueLabel($issueLabelEntity); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if (isset($issue['user']) && is_array($issue['user'])) { |
|
65
|
|
|
$user = $this->userTransformer->transform($issue['user']); |
|
66
|
|
|
$issueEntity->setUser($user); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
if (isset($issue['milestone']) && is_array($issue['milestone'])) { |
|
69
|
|
|
$issueMilestoneEntity = $this->issueMilestoneTransformer->transform($issue['milestone']); |
|
70
|
|
|
$issueEntity->setIssueMilestone($issueMilestoneEntity); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $issueEntity; |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Transforms an issue entity into a git api captiable issue array. |
|
78
|
|
|
* |
|
79
|
|
|
* @param \VersionControl\GithubIssueBundle\Entity\Issues $issueEntity |
|
80
|
|
|
* |
|
81
|
|
|
* @return array|null |
|
82
|
|
|
* |
|
83
|
|
|
* @throws TransformationFailedException if object (issue) is not found |
|
84
|
|
|
*/ |
|
85
|
|
|
public function reverseTransform($issueEntity) |
|
86
|
|
|
{ |
|
87
|
|
|
if ($issueEntity === null) { |
|
88
|
|
|
// causes a validation error |
|
89
|
|
|
throw new TransformationFailedException('IssueEntity is null'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$issue = array( |
|
93
|
|
|
'title' => $issueEntity->getTitle(), 'body' => $issueEntity->getDescription(), 'state' => $issueEntity->getStatus(), 'title' => $issueEntity->getTitle(), |
|
94
|
|
|
//,'milestone' => 0 |
|
95
|
|
|
); |
|
96
|
|
|
if ($issueEntity->getIssueMilestone()) { |
|
97
|
|
|
$issue['milestone'] = $issueEntity->getIssueMilestone()->getId(); |
|
98
|
|
|
} |
|
99
|
|
|
$labels = array(); |
|
100
|
|
|
foreach ($issueEntity->getIssueLabel() as $issueLabel) { |
|
101
|
|
|
$labels[] = $issueLabel->getId(); |
|
102
|
|
|
} |
|
103
|
|
|
$issue['labels'] = $labels; |
|
104
|
|
|
|
|
105
|
|
|
return $issue; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
protected function formatDate($date) |
|
109
|
|
|
{ |
|
110
|
|
|
try { |
|
111
|
|
|
$dateTime = new \DateTime($date); |
|
112
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
113
|
|
|
echo $e->getMessage(); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return $dateTime; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
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