Skip to content

Commit 27b00fc

Browse files
committed
Merge pull request KnpLabs#248 from mnapoli/label-api
Added missing features in the labels API
2 parents ed39b47 + 70f16ec commit 27b00fc

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

doc/issue/labels.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,33 @@ $labels = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api');
1212
List all project labels by username and repo.
1313
Returns an array of project labels.
1414

15+
### Create a label
16+
17+
```php
18+
$labels = $client->api('issue')->labels()->create('KnpLabs', 'php-github-api', array(
19+
'name' => 'Bug',
20+
'color' => 'FFFFFF',
21+
));
22+
```
23+
24+
Create a new label in the repository.
25+
26+
### Update a label
27+
28+
```php
29+
$labels = $client->api('issue')->labels()->update('KnpLabs', 'php-github-api', 'Enhancement', 'Feature', 'FFFFFF');
30+
```
31+
32+
Update the label name and color.
33+
34+
### Delete a label
35+
36+
```php
37+
$labels = $client->api('issue')->labels()->deleteLabel('KnpLabs', 'php-github-api', 'Bug');
38+
```
39+
40+
Delete a new label from the repository.
41+
1542
### Add a label on an issue
1643

1744
> Requires [authentication](../security.md).

lib/Github/Api/Issue/Labels.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Github\Api\AbstractApi;
66
use Github\Exception\InvalidArgumentException;
7+
use Github\Exception\MissingArgumentException;
78

89
/**
910
* @link http://developer.github.com/v3/issues/labels/
@@ -32,6 +33,21 @@ public function create($username, $repository, array $params)
3233
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params);
3334
}
3435

36+
public function deleteLabel($username, $repository, $label)
37+
{
38+
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
39+
}
40+
41+
public function update($username, $repository, $label, $newName, $color)
42+
{
43+
$params = array(
44+
'name' => $newName,
45+
'color' => $color,
46+
);
47+
48+
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params);
49+
}
50+
3551
public function add($username, $repository, $issue, $labels)
3652
{
3753
if (is_string($labels)) {

test/Github/Tests/Api/Issue/LabelsTest.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class LabelsTest extends TestCase
88
{
9-
109
/**
1110
* @test
1211
*/
@@ -76,6 +75,39 @@ public function shouldCreateLabelWithColor()
7675
$this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data));
7776
}
7877

78+
/**
79+
* @test
80+
*/
81+
public function shouldDeleteLabel()
82+
{
83+
$expectedValue = array('someOutput');
84+
85+
$api = $this->getApiMock();
86+
$api->expects($this->once())
87+
->method('delete')
88+
->with('repos/KnpLabs/php-github-api/labels/foo')
89+
->will($this->returnValue($expectedValue));
90+
91+
$this->assertEquals($expectedValue, $api->deleteLabel('KnpLabs', 'php-github-api', 'foo'));
92+
}
93+
94+
/**
95+
* @test
96+
*/
97+
public function shouldUpdateLabel()
98+
{
99+
$expectedValue = array(array('name' => 'bar', 'color' => 'FFF'));
100+
$data = array('name' => 'bar', 'color' => 'FFF');
101+
102+
$api = $this->getApiMock();
103+
$api->expects($this->once())
104+
->method('patch')
105+
->with('repos/KnpLabs/php-github-api/labels/foo', $data)
106+
->will($this->returnValue($expectedValue));
107+
108+
$this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'foo', 'bar', 'FFF'));
109+
}
110+
79111
/**
80112
* @test
81113
*/

0 commit comments

Comments
 (0)