Repository navigation
Expand file tree
/
Copy pathReferences.php
More file actions
156 lines (139 loc) · 4.05 KB
/
Copy pathReferences.php
File metadata and controls
156 lines (139 loc) · 4.05 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
<?php
namespace Github\Api\GitData;
use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/git/references/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class References extends AbstractApi
{
/**
* Get all references of a repository.
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function all($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs');
}
/**
* Get all matching references for the supplied reference name.
*
* @param string $username
* @param string $repository
* @param string $reference
*
* @return array
*/
public function matching(string $username, string $repository, string $reference): array
{
$reference = $this->encodeReference($reference);
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/matching-refs/'.$reference);
}
/**
* Get all branches of a repository.
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function branches($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/heads');
}
/**
* Get all tags of a repository.
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function tags($username, $repository)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags');
}
/**
* Show the reference of a repository.
*
* @param string $username
* @param string $repository
* @param string $reference
*
* @return array
*/
public function show($username, $repository, $reference)
{
$reference = $this->encodeReference($reference);
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference);
}
/**
* Create a reference for a repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function create($username, $repository, array $params)
{
if (!isset($params['ref'], $params['sha'])) {
throw new MissingArgumentException(['ref', 'sha']);
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs', $params);
}
/**
* Update a reference for a repository.
*
* @param string $username
* @param string $repository
* @param string $reference
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
*
* @return array
*/
public function update($username, $repository, $reference, array $params)
{
if (!isset($params['sha'])) {
throw new MissingArgumentException('sha');
}
$reference = $this->encodeReference($reference);
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference, $params);
}
/**
* Delete a reference of a repository.
*
* @param string $username
* @param string $repository
* @param string $reference
*
* @return array
*/
public function remove($username, $repository, $reference)
{
$reference = $this->encodeReference($reference);
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference);
}
/**
* Encode the raw reference.
*
* @param string $rawReference
*
* @return string
*/
private function encodeReference($rawReference)
{
return implode('/', array_map('rawurlencode', explode('/', $rawReference)));
}
}