-
-
Notifications
You must be signed in to change notification settings - Fork 592
Expand file tree
/
Copy pathLabels.php
More file actions
193 lines (178 loc) · 5.59 KB
/
Labels.php
File metadata and controls
193 lines (178 loc) · 5.59 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
<?php
namespace Github\Api\Issue;
use Github\Api\AbstractApi;
use Github\Exception\InvalidArgumentException;
use Github\Exception\MissingArgumentException;
/**
* @link http://developer.github.com/v3/issues/labels/
*
* @author Joseph Bielawski <stloyd@gmail.com>
*/
class Labels extends AbstractApi
{
/**
* Get all labels for a repository or the labels for a specific issue.
*
* @link https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue
*
* @param string $username
* @param string $repository
* @param int|null $issue
* @param array $params
*
* @return array
*/
public function all($username, $repository, $issue = null, array $params = [])
{
if ($issue === null) {
$path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels';
} else {
$path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/labels';
}
return $this->get($path, $params);
}
/**
* Get a single label.
*
* @link https://developer.github.com/v3/issues/labels/#get-a-single-label
*
* @param string $username
* @param string $repository
* @param string $label
*
* @return array
*/
public function show($username, $repository, $label)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
}
/**
* Create a label for a repository.
*
* @link https://developer.github.com/v3/issues/labels/#create-a-label
*
* @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['name'])) {
throw new MissingArgumentException('name');
}
if (!isset($params['color'])) {
$params['color'] = 'FFFFFF';
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params);
}
/**
* Delete a label for a repository.
*
* @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
*
* @param string $username
* @param string $repository
* @param string $label
*
* @return array
*/
public function deleteLabel($username, $repository, $label)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
}
/**
* Edit a label for a repository.
*
* @link https://developer.github.com/v3/issues/labels/#update-a-label
*
* @param string $username
* @param string $repository
* @param string $label
* @param string $newName
* @param string $color
*
* @return array
*/
public function update($username, $repository, $label, $newName, $color)
{
$params = [
'name' => $newName,
'color' => $color,
];
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params);
}
/**
* Add a label to an issue.
*
* @link https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue
*
* @param string $username
* @param string $repository
* @param int $issue
* @param string|array $labels
*
* @return array
*
* @thorws \Github\Exception\InvalidArgumentException
*/
public function add($username, $repository, $issue, $labels)
{
if (is_string($labels)) {
$labels = [$labels];
} elseif (0 === count($labels)) {
throw new InvalidArgumentException('The labels parameter should be a single label or an array of labels');
}
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/labels', $labels);
}
/**
* Replace labels for an issue.
*
* @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
*
* @param string $username
* @param string $repository
* @param int $issue
* @param array $params
*
* @return array
*/
public function replace($username, $repository, $issue, array $params)
{
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/labels', $params);
}
/**
* Remove a label for an issue.
*
* @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
*
* @param string $username
* @param string $repository
* @param int $issue
* @param string $label
*
* @return array|string
*/
public function remove($username, $repository, $issue, $label)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/labels/'.rawurlencode($label));
}
/**
* Remove all labels from an issue.
*
* @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
*
* @param string $username
* @param string $repository
* @param int $issue
*
* @return array|string
*/
public function clear($username, $repository, $issue)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/labels');
}
}