1212 */
1313class Labels extends AbstractApi
1414{
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+ */
1525 public function all ($ username , $ repository , $ issue = null )
1626 {
1727 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 ' ;
1931 }
2032
21- return $ this ->get (' repos/ ' . rawurlencode ( $ username ). ' / ' . rawurlencode ( $ repository ). ' /issues/ ' . rawurlencode ( $ issue ). ' /labels ' );
33+ return $ this ->get ($ path );
2234 }
2335
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+ */
2447 public function create ($ username , $ repository , array $ params )
2548 {
2649 if (!isset ($ params ['name ' ])) {
@@ -33,21 +56,55 @@ public function create($username, $repository, array $params)
3356 return $ this ->post ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/labels ' , $ params );
3457 }
3558
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+ */
3669 public function deleteLabel ($ username , $ repository , $ label )
3770 {
3871 return $ this ->delete ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/labels/ ' .rawurlencode ($ label ));
3972 }
4073
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+ */
4185 public function update ($ username , $ repository , $ label , $ newName , $ color )
4286 {
4387 $ params = array (
44- 'name ' => $ newName ,
88+ 'name ' => $ newName ,
4589 'color ' => $ color ,
4690 );
4791
4892 return $ this ->patch ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/labels/ ' .rawurlencode ($ label ), $ params );
4993 }
5094
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+ */
51108 public function add ($ username , $ repository , $ issue , $ labels )
52109 {
53110 if (is_string ($ labels )) {
@@ -59,16 +116,48 @@ public function add($username, $repository, $issue, $labels)
59116 return $ this ->post ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/issues/ ' .rawurlencode ($ issue ).'/labels ' , $ labels );
60117 }
61118
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+ */
62130 public function replace ($ username , $ repository , $ issue , array $ params )
63131 {
64132 return $ this ->put ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/issues/ ' .rawurlencode ($ issue ).'/labels ' , $ params );
65133 }
66134
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+ */
67146 public function remove ($ username , $ repository , $ issue , $ label )
68147 {
69148 return $ this ->delete ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/issues/ ' .rawurlencode ($ issue ).'/labels/ ' .rawurlencode ($ label ));
70149 }
71150
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+ */
72161 public function clear ($ username , $ repository , $ issue )
73162 {
74163 return $ this ->delete ('repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/issues/ ' .rawurlencode ($ issue ).'/labels ' );
0 commit comments