|
1
|
|
|
<?php |
|
2
|
|
|
namespace DevBoardLib\GithubApiFacade\Repo; |
|
3
|
|
|
|
|
4
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepo; |
|
5
|
|
|
use Github\Client; |
|
6
|
|
|
use Github\ResultPager; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class PaginatedKnpLabsRepoFacade. |
|
10
|
|
|
*/ |
|
11
|
|
|
class PaginatedKnpLabsRepoFacade implements RepoFacade |
|
12
|
|
|
{ |
|
13
|
|
|
private $client; |
|
14
|
|
|
private $githubRepo; |
|
15
|
|
|
|
|
16
|
|
|
private $paginator; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* PaginatedKnpLabsRepoFacade constructor. |
|
20
|
|
|
* |
|
21
|
|
|
* @param $client |
|
22
|
|
|
* @param $githubRepo |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(Client $client, GithubRepo $githubRepo) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->client = $client; |
|
27
|
|
|
$this->githubRepo = $githubRepo; |
|
28
|
|
|
|
|
29
|
|
|
$this->paginator = new ResultPager($this->client); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Fetches GithubRepo details. |
|
34
|
|
|
* |
|
35
|
|
|
* @return array |
|
36
|
|
|
*/ |
|
37
|
|
|
public function fetchDetails() |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->getRepoApi() |
|
|
|
|
|
|
40
|
|
|
->show( |
|
41
|
|
|
$this->githubRepo->getOwner(), |
|
|
|
|
|
|
42
|
|
|
$this->githubRepo->getName() |
|
|
|
|
|
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Fetches GithubBranch details. |
|
48
|
|
|
* |
|
49
|
|
|
* @param $branchName |
|
50
|
|
|
* |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
|
public function fetchBranch($branchName) |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->getRepoApi() |
|
|
|
|
|
|
56
|
|
|
->branches( |
|
57
|
|
|
$this->githubRepo->getOwner(), |
|
58
|
|
|
$this->githubRepo->getName(), |
|
59
|
|
|
$branchName |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
|
|
public function fetchAllBranches() |
|
67
|
|
|
{ |
|
68
|
|
|
$results = []; |
|
69
|
|
|
|
|
70
|
|
|
foreach ($this->fetchAllBranchNames() as $branchData) { |
|
71
|
|
|
$results[] = $this->fetchBranch($branchData['name']); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $results; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
|
View Code Duplication |
public function fetchAllBranchNames() |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
|
|
$parameters = [ |
|
83
|
|
|
$this->githubRepo->getOwner(), |
|
84
|
|
|
$this->githubRepo->getName(), |
|
85
|
|
|
]; |
|
86
|
|
|
|
|
87
|
|
|
return $this->paginator->fetchAll($this->getRepoApi(), 'branches', $parameters); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return array |
|
92
|
|
|
*/ |
|
93
|
|
|
public function fetchAllTags() |
|
94
|
|
|
{ |
|
95
|
|
|
$results = []; |
|
96
|
|
|
|
|
97
|
|
|
foreach ($this->fetchAllTagNames() as $tagData) { |
|
98
|
|
|
$tagData['commit'] = $this->fetchCommit($tagData['commit']['sha']); |
|
99
|
|
|
$results[] = $tagData; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return $results; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return array |
|
107
|
|
|
*/ |
|
108
|
|
View Code Duplication |
public function fetchAllTagNames() |
|
|
|
|
|
|
109
|
|
|
{ |
|
110
|
|
|
$parameters = [ |
|
111
|
|
|
$this->githubRepo->getOwner(), |
|
112
|
|
|
$this->githubRepo->getName(), |
|
113
|
|
|
]; |
|
114
|
|
|
|
|
115
|
|
|
return $this->paginator->fetchAll($this->getRepoApi(), 'tags', $parameters); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Fetches GithubCommit details. |
|
120
|
|
|
* |
|
121
|
|
|
* @param $commitSha |
|
122
|
|
|
* |
|
123
|
|
|
* @return array |
|
124
|
|
|
*/ |
|
125
|
|
|
public function fetchCommit($commitSha) |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->getRepoApi()->commits() |
|
|
|
|
|
|
128
|
|
|
->show( |
|
129
|
|
|
$this->githubRepo->getOwner(), |
|
130
|
|
|
$this->githubRepo->getName(), |
|
131
|
|
|
$commitSha |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Fetches GithubCommit status. |
|
137
|
|
|
* |
|
138
|
|
|
* @param $commitSha |
|
139
|
|
|
* |
|
140
|
|
|
* @return array |
|
141
|
|
|
*/ |
|
142
|
|
|
public function fetchCommitStatus($commitSha) |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->getRepoApi()->statuses() |
|
|
|
|
|
|
145
|
|
|
->combined( |
|
146
|
|
|
$this->githubRepo->getOwner(), |
|
147
|
|
|
$this->githubRepo->getName(), |
|
148
|
|
|
$commitSha |
|
149
|
|
|
); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Fetches list of GithubCommit statuses. |
|
154
|
|
|
* |
|
155
|
|
|
* @param $commitSha |
|
156
|
|
|
* |
|
157
|
|
|
* @return array |
|
158
|
|
|
*/ |
|
159
|
|
|
public function fetchCommitStatuses($commitSha) |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->getRepoApi()->statuses() |
|
|
|
|
|
|
162
|
|
|
->show( |
|
163
|
|
|
$this->githubRepo->getOwner(), |
|
164
|
|
|
$this->githubRepo->getName(), |
|
165
|
|
|
$commitSha |
|
166
|
|
|
); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @return array |
|
171
|
|
|
*/ |
|
172
|
|
View Code Duplication |
public function fetchAllPullRequests() |
|
|
|
|
|
|
173
|
|
|
{ |
|
174
|
|
|
$parameters = [ |
|
175
|
|
|
$this->githubRepo->getOwner(), |
|
176
|
|
|
$this->githubRepo->getName(), |
|
177
|
|
|
['state' => 'all'], |
|
178
|
|
|
]; |
|
179
|
|
|
|
|
180
|
|
|
return $this->paginator->fetchAll($this->getPullRequestApi(), 'all', $parameters); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @return array |
|
185
|
|
|
*/ |
|
186
|
|
View Code Duplication |
public function fetchAllMilestones() |
|
|
|
|
|
|
187
|
|
|
{ |
|
188
|
|
|
$parameters = [ |
|
189
|
|
|
$this->githubRepo->getOwner(), |
|
190
|
|
|
$this->githubRepo->getName(), |
|
191
|
|
|
['state' => 'all'], |
|
192
|
|
|
]; |
|
193
|
|
|
|
|
194
|
|
|
return $this->paginator->fetchAll($this->getMilestonesApi(), 'all', $parameters); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Returns all issues. |
|
199
|
|
|
* |
|
200
|
|
|
* IMPORTANT: |
|
201
|
|
|
* - GitHub API v3 returns both issues and pullRequests together so filtering needs to be done |
|
202
|
|
|
* - Pull requests have 'pull_request' key. |
|
203
|
|
|
* |
|
204
|
|
|
* @return array |
|
205
|
|
|
*/ |
|
206
|
|
|
public function fetchAllIssues() |
|
207
|
|
|
{ |
|
208
|
|
|
$results = []; |
|
209
|
|
|
|
|
210
|
|
|
foreach ($this->fetchAllIssuesAndPullRequests() as $result) { |
|
211
|
|
|
if (!array_key_exists('pull_request', $result)) { |
|
212
|
|
|
$results[] = $result; |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
return $results; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @return array |
|
221
|
|
|
*/ |
|
222
|
|
View Code Duplication |
public function fetchAllIssuesAndPullRequests() |
|
|
|
|
|
|
223
|
|
|
{ |
|
224
|
|
|
$parameters = [ |
|
225
|
|
|
$this->githubRepo->getOwner(), |
|
226
|
|
|
$this->githubRepo->getName(), |
|
227
|
|
|
['state' => 'all'], |
|
228
|
|
|
]; |
|
229
|
|
|
|
|
230
|
|
|
return $this->paginator->fetchAll($this->getIssueApi(), 'all', $parameters); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @return \Github\Api\ApiInterface |
|
235
|
|
|
*/ |
|
236
|
|
|
private function getRepoApi() |
|
237
|
|
|
{ |
|
238
|
|
|
return $this->client->api('repository'); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* @return \Github\Api\ApiInterface |
|
243
|
|
|
*/ |
|
244
|
|
|
private function getIssueApi() |
|
245
|
|
|
{ |
|
246
|
|
|
return $this->client->api('issues'); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* @return \Github\Api\Issue\Milestones |
|
251
|
|
|
*/ |
|
252
|
|
|
private function getMilestonesApi() |
|
253
|
|
|
{ |
|
254
|
|
|
return $this->getIssueApi()->milestones(); |
|
|
|
|
|
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* @return \Github\Api\PullRequest |
|
259
|
|
|
*/ |
|
260
|
|
|
private function getPullRequestApi() |
|
261
|
|
|
{ |
|
262
|
|
|
return $this->client->api('pull_requests'); |
|
|
|
|
|
|
263
|
|
|
} |
|
264
|
|
|
} |
|
265
|
|
|
|
This check looks for function calls that miss required arguments.