forked from KnpLabs/php-github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepo.php
More file actions
395 lines (364 loc) · 12.1 KB
/
Repo.php
File metadata and controls
395 lines (364 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<?php
namespace Github\Api;
use Github\Api\Repository\Collaborators;
use Github\Api\Repository\Comments;
use Github\Api\Repository\Commits;
use Github\Api\Repository\Contents;
use Github\Api\Repository\DeployKeys;
use Github\Api\Repository\Downloads;
use Github\Api\Repository\Releases;
use Github\Api\Repository\Forks;
use Github\Api\Repository\Hooks;
use Github\Api\Repository\Labels;
use Github\Api\Repository\Statuses;
/**
* Searching repositories, getting repository information
* and managing repository information for authenticated users.
*
* @link http://developer.github.com/v3/repos/
* @author Joseph Bielawski <[email protected]>
* @author Thibault Duplessis <thibault.duplessis at gmail dot com>
*/
class Repo extends AbstractApi
{
/**
* Search repositories by keyword:
* @link http://developer.github.com/v3/search/#search-repositories
*
* @param string $keyword the search query
* @param array $params
*
* @return array list of found repositories
*/
public function find($keyword, array $params)
{
return $this->get('legacy/repos/search/'.rawurlencode($keyword), array_merge(array('start_page' => 1), $params));
}
/**
* List all repositories for an organization
* @link http://developer.github.com/v3/repos/#list-organization-repositories
*
* @param string $organization the name of the organization
* @param array $params
*
* @return array list of organization repositories
*/
public function org($organization, array $params = array())
{
return $this->get('orgs/'.$organization.'/repos', array_merge(array('start_page' => 1), $params));
}
/**
* Get extended information about a repository by its username and repository name
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return array informations about the repository
*/
public function show($username, $repository)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository));
}
/**
* Create repository
* @link http://developer.github.com/v3/repos/
*
* @param string $name name of the repository
* @param string $description repository description
* @param string $homepage homepage url
* @param boolean $public `true` for public, `false` for private
* @param null|string $organization username of organization if applicable
* @param boolean $hasIssues `true` to enable issues for this repository, `false` to disable them
* @param boolean $hasWiki `true` to enable the wiki for this repository, `false` to disable it
* @param boolean $hadDownloads `true` to enable downloads for this repository, `false` to disable them
* @param integer $teamId The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization.
* @param boolean $autoInit `true` to create an initial commit with empty README, `false` for no initial commit
*
* @return array returns repository data
*/
public function create(
$name,
$description = '',
$homepage = '',
$public = true,
$organization = null,
$hasIssues = false,
$hasWiki = false,
$hasDownloads = false,
$teamId = null,
$autoInit = false
) {
$path = null !== $organization ? 'orgs/'.$organization.'/repos' : 'user/repos';
$parameters = array(
'name' => $name,
'description' => $description,
'homepage' => $homepage,
'private' => !$public,
'has_issues' => $hasIssues,
'has_wiki' => $hasWiki,
'has_downloads' => $hasDownloads,
'auto_init' => $autoInit
);
if ($organization && $teamId) {
$parameters['team_id'] = $teamId;
}
return $this->post($path, $parameters);
}
/**
* Set information of a repository
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param array $values the key => value pairs to post
*
* @return array informations about the repository
*/
public function update($username, $repository, array $values)
{
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository), $values);
}
/**
* Delete a repository
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return mixed null on success, array on error with 'message'
*/
public function remove($username, $repository)
{
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository));
}
/**
* Get the readme content for a repository by its username and repository name
* @link http://developer.github.com/v3/repos/contents/#get-the-readme
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return array the readme content
*/
public function readme($username, $repository)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme');
}
/**
* Manage the collaborators of a repository
* @link http://developer.github.com/v3/repos/collaborators/
*
* @return Collaborators
*/
public function collaborators()
{
return new Collaborators($this->client);
}
/**
* Manage the comments of a repository
* @link http://developer.github.com/v3/repos/comments/
*
* @return Comments
*/
public function comments()
{
return new Comments($this->client);
}
/**
* Manage the commits of a repository
* @link http://developer.github.com/v3/repos/commits/
*
* @return Commits
*/
public function commits()
{
return new Commits($this->client);
}
/**
* Manage the content of a repository
* @link http://developer.github.com/v3/repos/contents/
*
* @return Contents
*/
public function contents()
{
return new Contents($this->client);
}
/**
* Manage the content of a repository
* @link http://developer.github.com/v3/repos/downloads/
*
* @return Downloads
*/
public function downloads()
{
return new Downloads($this->client);
}
/**
* Manage the releases of a repository (Currently Undocumented)
* @link http://developer.github.com/v3/repos/
*
* @return Releases
*/
public function releases()
{
return new Releases($this->client);
}
/**
* Manage the deploy keys of a repository
* @link http://developer.github.com/v3/repos/keys/
*
* @return DeployKeys
*/
public function keys()
{
return new DeployKeys($this->client);
}
/**
* Manage the forks of a repository
* @link http://developer.github.com/v3/repos/forks/
*
* @return Forks
*/
public function forks()
{
return new Forks($this->client);
}
/**
* Manage the hooks of a repository
* @link http://developer.github.com/v3/issues/jooks/
*
* @return Hooks
*/
public function hooks()
{
return new Hooks($this->client);
}
/**
* Manage the labels of a repository
* @link http://developer.github.com/v3/issues/labels/
*
* @return Labels
*/
public function labels()
{
return new Labels($this->client);
}
/**
* Manage the statuses of a repository
* @link http://developer.github.com/v3/repos/statuses/
*
* @return Statuses
*/
public function statuses()
{
return new Statuses($this->client);
}
/**
* Get the branch(es) of a repository
* @link http://developer.github.com/v3/repos/
*
* @param string $username the username
* @param string $repository the name of the repository
* @param string $branch the name of the branch
*
* @return array list of the repository branches
*/
public function branches($username, $repository, $branch = null)
{
$url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches';
if (null !== $branch) {
$url .= '/'.rawurlencode($branch);
}
return $this->get($url);
}
/**
* Get the contributors of a repository
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
* @param boolean $includingAnonymous by default, the list only shows GitHub users.
* You can include non-users too by setting this to true
* @return array list of the repo contributors
*/
public function contributors($username, $repository, $includingAnonymous = false)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contributors', array(
'anon' => $includingAnonymous ?: null
));
}
/**
* Get the language breakdown of a repository
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return array list of the languages
*/
public function languages($username, $repository)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/languages');
}
/**
* Get the tags of a repository
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return array list of the repository tags
*/
public function tags($username, $repository)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/tags');
}
/**
* Get the teams of a repository
* @link http://developer.github.com/v3/repos/
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
*
* @return array list of the languages
*/
public function teams($username, $repository)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/teams');
}
/**
* @param string $username
* @param string $repository
* @param integer $page
*
* @return array
*/
public function watchers($username, $repository, $page = 1)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/watchers', array(
'page' => $page
));
}
/**
* Perform a merge
* @link http://developer.github.com/v3/repos/merging/
*
* @param string $username
* @param string $repository
* @param string $base The name of the base branch that the head will be merged into.
* @param string $head The head to merge. This can be a branch name or a commit SHA1.
* @param string $message Commit message to use for the merge commit. If omitted, a default message will be used.
*
* @return array|null
*/
public function merge($username, $repository, $base, $head, $message = null)
{
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/merges', array(
'base' => $base,
'head' => $head,
'commit_message' => $message
));
}
}