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\Repository; |
12
|
|
|
|
13
|
|
|
use VersionControl\GitControlBundle\Repository\Issues\IssueRepositoryInterface; |
14
|
|
|
use VersionControl\GitlabIssueBundle\Entity\Issues\Issue; |
15
|
|
|
use VersionControl\GitlabIssueBundle\Entity\Issues\IssueComment; |
16
|
|
|
use VersionControl\GitlabIssueBundle\DataTransformer\IssueToEntityTransformer; |
17
|
|
|
use VersionControl\GitlabIssueBundle\DataTransformer\IssueCommentToEntityTransformer; |
18
|
|
|
|
19
|
|
|
class IssueRepository extends GitlabBase implements IssueRepositoryInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Finds issues for a state. |
23
|
|
|
* |
24
|
|
|
* @param string $keyword |
25
|
|
|
* |
26
|
|
|
* @return array of issues |
27
|
|
|
*/ |
28
|
|
|
public function findIssues($keyword = '', $state = 'opened') |
29
|
|
|
{ |
30
|
|
|
//$project = new \Gitlab\Model\Project($this->issueIntegrator->getProjectName(), $this->client); |
31
|
|
|
if ($state === 'open') { |
32
|
|
|
$state = 'opened'; |
33
|
|
|
} |
34
|
|
|
$this->authenticate(); |
35
|
|
|
$issues = $this->client->api('issues')->all($this->issueIntegrator->getProjectName(), 1, 20, array('state' => $state)); |
|
|
|
|
36
|
|
|
|
37
|
|
|
return $this->mapIssues($issues); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function countFindIssues($keyword, $state = 'open') |
41
|
|
|
{ |
42
|
|
|
$this->authenticate(); |
43
|
|
|
if ($state === 'open') { |
44
|
|
|
$state = 'opened'; |
45
|
|
|
} |
46
|
|
|
$issues = $this->client->api('issues')->all($this->issueIntegrator->getProjectName(), 1, 20, array('state' => $state)); |
47
|
|
|
|
48
|
|
|
return count($issues); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param int $id |
53
|
|
|
*/ |
54
|
|
|
public function findIssueById($id) |
55
|
|
|
{ |
56
|
|
|
$this->authenticate(); |
57
|
|
|
$issue = $this->client->api('issues')->show($this->issueIntegrator->getProjectName(), $id); |
58
|
|
|
$issueComments = $this->client->api('issues')->showComments($this->issueIntegrator->getProjectName(), $id); |
59
|
|
|
|
60
|
|
|
return $this->mapIssueToEntity($issue, $issueComments); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Gets a new Issue entity. |
65
|
|
|
* |
66
|
|
|
* @param type $issue |
|
|
|
|
67
|
|
|
* |
68
|
|
|
* @return VersionControl\GitControlBundle\Entity\Issues\Issue |
|
|
|
|
69
|
|
|
*/ |
70
|
|
|
public function newIssue() |
71
|
|
|
{ |
72
|
|
|
$issueEntity = new Issue(); |
73
|
|
|
|
74
|
|
|
return $issueEntity; |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param type $issueEntity |
79
|
|
|
*/ |
80
|
|
|
public function createIssue($issueEntity) |
81
|
|
|
{ |
82
|
|
|
$this->authenticate(); |
83
|
|
|
|
84
|
|
|
$issue = $this->client->api('issues')->create($this->issueIntegrator->getProjectName(), $this->mapEntityToIssue($issueEntity)); |
85
|
|
|
|
86
|
|
|
return $this->mapIssueToEntity($issue); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param int $id |
91
|
|
|
*/ |
92
|
|
|
public function reOpenIssue($id) |
93
|
|
|
{ |
94
|
|
|
$this->authenticate(); |
95
|
|
|
$issue = $this->client->api('issues')->update($this->issueIntegrator->getProjectName(), $id, array('state_event' => 'reopen')); |
96
|
|
|
|
97
|
|
|
return $this->mapIssueToEntity($issue); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param int $id |
102
|
|
|
*/ |
103
|
|
|
public function closeIssue($id) |
104
|
|
|
{ |
105
|
|
|
$this->authenticate(); |
106
|
|
|
$issue = $this->client->api('issues')->update($this->issueIntegrator->getProjectName(), $id, array('state_event' => 'close')); |
107
|
|
|
|
108
|
|
|
return $this->mapIssueToEntity($issue); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param int $issueEntity |
113
|
|
|
*/ |
114
|
|
|
public function updateIssue($issueEntity) |
115
|
|
|
{ |
116
|
|
|
$this->authenticate(); |
117
|
|
|
$this->client->api('issues')->update($this->issueIntegrator->getProjectName(), $issueEntity->getId(), $this->mapEntityToIssue($issueEntity)); |
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function addlabel($issueEntity, $labelEntity) |
121
|
|
|
{ |
122
|
|
|
$this->authenticate(); |
123
|
|
|
$labels = $this->client->api('issues')->labels()->add($this->issueIntegrator->getProjectName(), $issueEntity->getId(), $labelEntity->getTitle()); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Gets the number of Issues for a milestone by state. |
128
|
|
|
* |
129
|
|
|
* @param int $issueMilestoneId |
130
|
|
|
* @param string $state open|closed|blank |
131
|
|
|
*/ |
132
|
|
|
public function countIssuesInMilestones($issueMilestoneId, $state) |
133
|
|
|
{ |
134
|
|
|
$openCount = 0; |
135
|
|
|
$closedCount = 0; |
136
|
|
|
$this->authenticate(); |
137
|
|
|
$issues = $this->client->api('milestones')->issues($this->issueIntegrator->getProjectName(), $issueMilestoneId); |
138
|
|
|
foreach ($issues as $issue) { |
|
|
|
|
139
|
|
|
if ($issue['state'] === 'opened') { |
140
|
|
|
++$openCount; |
141
|
|
|
} elseif ($issue['state'] === 'closed') { |
142
|
|
|
++$closedCount; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
if ($state === 'open') { |
146
|
|
|
$count = $openCount; |
147
|
|
|
} elseif ($state === 'closed') { |
148
|
|
|
$count = $closedCount; |
149
|
|
|
} else { |
150
|
|
|
$count = count($issues); |
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
return $count; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Find issues in milestone. |
158
|
|
|
* |
159
|
|
|
* @param int $issueMilestoneId |
160
|
|
|
* @param string $state open|closed|blank |
161
|
|
|
* @param string $keyword Search string |
162
|
|
|
*/ |
163
|
|
|
public function findIssuesInMilestones($issueMilestoneId, $state, $keyword = false) |
164
|
|
|
{ |
165
|
|
|
$this->authenticate(); |
166
|
|
|
$issues = $this->filterIssuesByState($this->client->api('milestones')->issues($this->issueIntegrator->getProjectName(), $issueMilestoneId), $state); |
|
|
|
|
167
|
|
|
|
168
|
|
|
return $this->mapIssues($issues); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param array $issues |
173
|
|
|
* @param string $state open|closed |
174
|
|
|
* |
175
|
|
|
* @return array |
176
|
|
|
*/ |
177
|
|
|
protected function filterIssuesByState($issues, $state) |
178
|
|
|
{ |
179
|
|
|
$filteredIssues = array(); |
180
|
|
|
foreach ($issues as $issue) { |
181
|
|
|
if ($issue['state'] === 'opened' && $state === 'open') { |
182
|
|
|
$filteredIssues[] = $issue; |
183
|
|
|
} elseif ($issue['state'] === 'closed' && $state === 'closed') { |
184
|
|
|
$filteredIssues[] = $issue; |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
return $filteredIssues; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param array $issues |
193
|
|
|
* |
194
|
|
|
* @return array of |
195
|
|
|
*/ |
196
|
|
|
protected function mapIssues($issues) |
197
|
|
|
{ |
198
|
|
|
$issueEntities = array(); |
199
|
|
|
if (is_array($issues)) { |
|
|
|
|
200
|
|
|
foreach ($issues as $issue) { |
201
|
|
|
$issueEntities[] = $this->mapIssueToEntity($issue); |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
return $issueEntities; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
protected function mapIssueToEntity($issue, $issueComments = array()) |
209
|
|
|
{ |
210
|
|
|
$issueTransfomer = new IssueToEntityTransformer(); |
211
|
|
|
$issueCommentTransfomer = new IssueCommentToEntityTransformer(); |
212
|
|
|
$issueEntity = $issueTransfomer->transform($issue); |
213
|
|
|
|
214
|
|
|
foreach ($issueComments as $issueComment) { |
215
|
|
|
$issueCommentEntity = $issueCommentTransfomer->transform($issueComment); |
216
|
|
|
$issueEntity->addIssueComment($issueCommentEntity); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
return $issueEntity; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
protected function mapEntityToIssue($issueEntity) |
223
|
|
|
{ |
224
|
|
|
$issueTransfomer = new IssueToEntityTransformer(); |
225
|
|
|
|
226
|
|
|
return $issueTransfomer->reverseTransform($issueEntity); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
public function newIssueComment() |
230
|
|
|
{ |
231
|
|
|
$issueCommentEntity = new IssueComment(); |
232
|
|
|
|
233
|
|
|
return $issueCommentEntity; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Creates a New issue Comment on github. |
238
|
|
|
* |
239
|
|
|
* @param \VersionControl\GitlabIssueBundle\Entity\Issues\IssueComment $issueCommentEntity |
240
|
|
|
*/ |
241
|
|
|
public function createIssueComment(\VersionControl\GitlabIssueBundle\Entity\Issues\IssueComment $issueCommentEntity) |
242
|
|
|
{ |
243
|
|
|
$this->authenticate(); |
244
|
|
|
$issueId = $issueCommentEntity->getIssue()->getId(); |
245
|
|
|
$comment = $this->client->api('issues')->addComment($this->issueIntegrator->getProjectName(), $issueId, $issueCommentEntity->getComment()); |
246
|
|
|
$issueCommentTransfomer = new IssueCommentToEntityTransformer(); |
247
|
|
|
|
248
|
|
|
return $issueCommentTransfomer->transform($comment); |
|
|
|
|
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.