1
|
|
|
<?php |
2
|
|
|
namespace FlexyProject\GitHub\Receiver\Repositories; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\HttpFoundation\Request; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* The Collaborators API class provides access to repository's collaborators |
8
|
|
|
* |
9
|
|
|
* @link https://developer.github.com/v3/repos/collaborators/ |
10
|
|
|
* @package FlexyProject\GitHub\Receiver\Repositories |
11
|
|
|
*/ |
12
|
|
|
class Collaborators extends AbstractRepositories |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* List collaborators |
17
|
|
|
* |
18
|
|
|
* @link https://developer.github.com/v3/repos/collaborators/#list |
19
|
|
|
* @return array |
20
|
|
|
*/ |
21
|
|
|
public function listCollaborators(): array |
22
|
|
|
{ |
23
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/collaborators', |
24
|
|
|
$this->getRepositories()->getOwner(), $this->getRepositories()->getRepo())); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Check if a user is a collaborator |
29
|
|
|
* |
30
|
|
|
* @link https://developer.github.com/v3/repos/collaborators/#get |
31
|
|
|
* |
32
|
|
|
* @param string $username |
33
|
|
|
* |
34
|
|
|
* @return bool |
35
|
|
|
*/ |
36
|
|
|
public function checkUserIsACollaborator(string $username): bool |
37
|
|
|
{ |
38
|
|
|
$this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/collaborators/:username', |
39
|
|
|
$this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $username)); |
40
|
|
|
|
41
|
|
|
if ($this->getApi()->getHeaders()['Status'] == '204 No Content') { |
42
|
|
|
return true; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return false; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Add user as a collaborator |
50
|
|
|
* |
51
|
|
|
* @link https://developer.github.com/v3/repos/collaborators/#add-collaborator |
52
|
|
|
* |
53
|
|
|
* @param string $username |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public function addUserAsCollaborator(string $username): array |
58
|
|
|
{ |
59
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/collaborators/:username', |
60
|
|
|
$this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $username), Request::METHOD_PUT); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Remove user as a collaborator |
65
|
|
|
* |
66
|
|
|
* @link https://developer.github.com/v3/repos/collaborators/#remove-collaborator |
67
|
|
|
* |
68
|
|
|
* @param string $username |
69
|
|
|
* |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
public function removeUserAsCollaborator(string $username): array |
73
|
|
|
{ |
74
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/collaborators/:username', |
75
|
|
|
$this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $username), |
76
|
|
|
Request::METHOD_DELETE); |
77
|
|
|
} |
78
|
|
|
} |