1
|
|
|
<?php |
2
|
|
|
namespace FlexyProject\GitHub\Receiver\Repositories; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\HttpFoundation\Request; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* The DeployKeys API class provides access to repository's deploy keys. |
8
|
|
|
* |
9
|
|
|
* @link https://developer.github.com/v3/repos/keys/ |
10
|
|
|
* @package FlexyProject\GitHub\Receiver\Repositories |
11
|
|
|
*/ |
12
|
|
|
class DeployKeys extends AbstractRepositories |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* List deploy keys |
17
|
|
|
* |
18
|
|
|
* @link https://developer.github.com/v3/repos/keys/#list |
19
|
|
|
* @return array |
20
|
|
|
*/ |
21
|
|
|
public function listDeployKeys(): array |
22
|
|
|
{ |
23
|
|
|
return $this->getApi()->request($this->getApi() |
24
|
|
|
->sprintf('/repos/:owner/:repo/keys', $this->getRepositories()->getOwner(), |
25
|
|
|
$this->getRepositories()->getRepo())); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Get a deploy key |
30
|
|
|
* |
31
|
|
|
* @link https://developer.github.com/v3/repos/keys/#get |
32
|
|
|
* |
33
|
|
|
* @param int $id |
34
|
|
|
* |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
public function getDeployKey(int $id): array |
38
|
|
|
{ |
39
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/keys/:id', |
40
|
|
|
$this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $id)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Add a new deploy key |
45
|
|
|
* |
46
|
|
|
* @link https://developer.github.com/v3/repos/keys/#create |
47
|
|
|
* |
48
|
|
|
* @param string $title |
49
|
|
|
* @param string $key |
50
|
|
|
* |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
public function addNewDeployKey(string $title, string $key): array |
54
|
|
|
{ |
55
|
|
|
return $this->getApi()->request($this->getApi() |
56
|
|
|
->sprintf('/repos/:owner/:repo/keys', $this->getRepositories()->getOwner(), |
57
|
|
|
$this->getRepositories()->getRepo()), Request::METHOD_POST, [ |
58
|
|
|
'title' => $title, |
59
|
|
|
'key' => $key |
60
|
|
|
]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Remove a deploy key |
65
|
|
|
* |
66
|
|
|
* @link https://developer.github.com/v3/repos/keys/#delete |
67
|
|
|
* |
68
|
|
|
* @param int $id |
69
|
|
|
* |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
public function removeDeployKey(int $id): array |
73
|
|
|
{ |
74
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/keys/:id', |
75
|
|
|
$this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $id), Request::METHOD_DELETE); |
76
|
|
|
} |
77
|
|
|
} |