File tree Expand file tree Collapse file tree 4 files changed +111
-7
lines changed Expand file tree Collapse file tree 4 files changed +111
-7
lines changed Original file line number Diff line number Diff line change @@ -314,7 +314,7 @@ public function labels($project_id)
314314 */
315315 public function addLabel ($ project_id , array $ params )
316316 {
317- return $ this ->post ($ this ->getProjectPath ($ project_id , 'labels ' , $ params) );
317+ return $ this ->post ($ this ->getProjectPath ($ project_id , 'labels ' ) , $ params );
318318 }
319319
320320 /**
@@ -324,17 +324,19 @@ public function addLabel($project_id, array $params)
324324 */
325325 public function updateLabel ($ project_id , array $ params )
326326 {
327- return $ this ->put ($ this ->getProjectPath ($ project_id , 'labels ' , $ params) );
327+ return $ this ->put ($ this ->getProjectPath ($ project_id , 'labels ' ) , $ params );
328328 }
329329
330330 /**
331331 * @param int $project_id
332- * @param array $params
332+ * @param string $name
333333 * @return mixed
334334 */
335- public function removeLabel ($ project_id , array $ params )
335+ public function removeLabel ($ project_id , $ name )
336336 {
337- return $ this ->delete ($ this ->getProjectPath ($ project_id , 'labels ' ), $ params );
337+ return $ this ->delete ($ this ->getProjectPath ($ project_id , 'labels ' ), array (
338+ 'name ' => $ name
339+ ));
338340 }
339341
340342 /**
Original file line number Diff line number Diff line change 1111 * @property-read string $title
1212 * @property-read string $description
1313 * @property-read array $labels
14- * @property-read User $assignee
15- * @property-read User $author
1614 * @property-read bool $closed
1715 * @property-read string $updated_at
1816 * @property-read string $created_at
1917 * @property-read string $state
18+ * @property-read User $assignee
19+ * @property-read User $author
2020 * @property-read Milestone $milestone
2121 * @property-read Project $project
2222 */
Original file line number Diff line number Diff line change 1+ <?php namespace Gitlab \Model ;
2+
3+ use Gitlab \Client ;
4+
5+ /**
6+ * Class Label
7+ *
8+ * @property-read string $name
9+ * @property-read string $color
10+ */
11+ class Label extends AbstractModel
12+ {
13+ /**
14+ * @var array
15+ */
16+ protected static $ properties = array (
17+ 'name ' ,
18+ 'color '
19+ );
20+
21+ /**
22+ * @param Client $client
23+ * @param Project $project
24+ * @param array $data
25+ * @return Label
26+ */
27+ public static function fromArray (Client $ client , Project $ project , array $ data )
28+ {
29+ $ label = new static ($ project , $ client );
30+
31+ return $ label ->hydrate ($ data );
32+ }
33+
34+ /**
35+ * @param Project $project
36+ * @param Client $client
37+ */
38+ public function __construct (Project $ project , Client $ client = null )
39+ {
40+ $ this ->setClient ($ client );
41+ $ this ->setData ('project ' , $ project );
42+ }
43+ }
Original file line number Diff line number Diff line change @@ -918,4 +918,63 @@ public function removeService($service_name)
918918
919919 return true ;
920920 }
921+
922+ /**
923+ * @return Label[]
924+ */
925+ public function labels ()
926+ {
927+ $ data = $ this ->api ('projects ' )->labels ($ this ->id );
928+
929+ $ labels = array ();
930+ foreach ($ data as $ label ) {
931+ $ labels [] = Label::fromArray ($ this ->getClient (), $ this , $ label );
932+ }
933+
934+ return $ labels ;
935+ }
936+
937+ /**
938+ * @param string $name
939+ * @param string $color
940+ * @return Label
941+ */
942+ public function addLabel ($ name , $ color )
943+ {
944+ $ data = $ this ->api ('projects ' )->addLabel ($ this ->id , array (
945+ 'name ' => $ name ,
946+ 'color ' => $ color
947+ ));
948+
949+ return Label::fromArray ($ this ->getClient (), $ this , $ data );
950+ }
951+
952+ /**
953+ * @param string $name
954+ * @param array $params
955+ * @return Label
956+ */
957+ public function updateLabel ($ name , array $ params )
958+ {
959+ if (isset ($ params ['name ' ])) {
960+ $ params ['new_name ' ] = $ params ['name ' ];
961+ }
962+
963+ $ params ['name ' ] = $ name ;
964+
965+ $ data = $ this ->api ('projects ' )->updateLabel ($ this ->id , $ params );
966+
967+ return Label::fromArray ($ this ->getClient (), $ this , $ data );
968+ }
969+
970+ /**
971+ * @param string $name
972+ * @return bool
973+ */
974+ public function removeLabel ($ name )
975+ {
976+ $ this ->api ('projects ' )->removeLabel ($ this ->id , $ name );
977+
978+ return true ;
979+ }
921980}
You can’t perform that action at this time.
0 commit comments