12
12
*/
13
13
class Labels extends AbstractApi
14
14
{
15
+ /**
16
+ * Get all labels for a repository or the labels for a specific issue.
17
+ *
18
+ * @link https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue
19
+ * @param string $username
20
+ * @param string $repository
21
+ * @param int|null $issue
22
+ *
23
+ * @return array
24
+ */
15
25
public function all ($ username , $ repository , $ issue = null )
16
26
{
17
27
if ($ issue === null ) {
18
- return $ this ->get ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/labels ' );
28
+ $ path = 'repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/labels ' ;
29
+ } else {
30
+ $ path = 'repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/issues/ ' .rawurlencode ($ issue ).'/labels ' ;
19
31
}
20
32
21
- return $ this ->get (' repos/ ' . rawurlencode ( $ username ). ' / ' . rawurlencode ( $ repository ). ' /issues/ ' . rawurlencode ( $ issue ). ' /labels ' );
33
+ return $ this ->get ($ path );
22
34
}
23
35
36
+ /**
37
+ * Create a label for a repository.
38
+ *
39
+ * @param string $username
40
+ * @param string $repository
41
+ * @param array $params
42
+ *
43
+ * @return array
44
+ *
45
+ * @throws \Github\Exception\MissingArgumentException
46
+ */
24
47
public function create ($ username , $ repository , array $ params )
25
48
{
26
49
if (!isset ($ params ['name ' ])) {
@@ -33,21 +56,55 @@ public function create($username, $repository, array $params)
33
56
return $ this ->post ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/labels ' , $ params );
34
57
}
35
58
59
+ /**
60
+ * Delete a label for a repository.
61
+ *
62
+ * @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
63
+ * @param string $username
64
+ * @param string $repository
65
+ * @param string $label
66
+ *
67
+ * @return array
68
+ */
36
69
public function deleteLabel ($ username , $ repository , $ label )
37
70
{
38
71
return $ this ->delete ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/labels/ ' .rawurlencode ($ label ));
39
72
}
40
73
74
+ /**
75
+ * Edit a label for a repository
76
+ *
77
+ * @param string $username
78
+ * @param string $repository
79
+ * @param string $label
80
+ * @param string $newName
81
+ * @param string $color
82
+ *
83
+ * @return array
84
+ */
41
85
public function update ($ username , $ repository , $ label , $ newName , $ color )
42
86
{
43
87
$ params = array (
44
- 'name ' => $ newName ,
88
+ 'name ' => $ newName ,
45
89
'color ' => $ color ,
46
90
);
47
91
48
92
return $ this ->patch ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/labels/ ' .rawurlencode ($ label ), $ params );
49
93
}
50
94
95
+ /**
96
+ * Add a label to an issue.
97
+ *
98
+ * @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
99
+ * @param string $username
100
+ * @param string $repository
101
+ * @param int $issue
102
+ * @param string $labels
103
+ *
104
+ * @return array
105
+ *
106
+ * @thorws \Github\Exception\InvalidArgumentException
107
+ */
51
108
public function add ($ username , $ repository , $ issue , $ labels )
52
109
{
53
110
if (is_string ($ labels )) {
@@ -59,16 +116,48 @@ public function add($username, $repository, $issue, $labels)
59
116
return $ this ->post ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/issues/ ' .rawurlencode ($ issue ).'/labels ' , $ labels );
60
117
}
61
118
119
+ /**
120
+ * Replace labels for an issue.
121
+ *
122
+ * @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
123
+ * @param string $username
124
+ * @param string $repository
125
+ * @param int $issue
126
+ * @param array $params
127
+ *
128
+ * @return array
129
+ */
62
130
public function replace ($ username , $ repository , $ issue , array $ params )
63
131
{
64
132
return $ this ->put ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/issues/ ' .rawurlencode ($ issue ).'/labels ' , $ params );
65
133
}
66
134
135
+ /**
136
+ * Remove a label for an issue
137
+ *
138
+ * @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
139
+ * @param string $username
140
+ * @param string $repository
141
+ * @param string $issue
142
+ * @param string $label
143
+ *
144
+ * @return null
145
+ */
67
146
public function remove ($ username , $ repository , $ issue , $ label )
68
147
{
69
148
return $ this ->delete ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/issues/ ' .rawurlencode ($ issue ).'/labels/ ' .rawurlencode ($ label ));
70
149
}
71
150
151
+ /**
152
+ * Remove all labels from an issue.
153
+ *
154
+ * @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
155
+ * @param string $username
156
+ * @param string $repository
157
+ * @param string $issue
158
+ *
159
+ * @return null
160
+ */
72
161
public function clear ($ username , $ repository , $ issue )
73
162
{
74
163
return $ this ->delete ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/issues/ ' .rawurlencode ($ issue ).'/labels ' );
0 commit comments