Skip to content

Added missing features in the labels API #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions doc/issue/labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,33 @@ $labels = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api');
List all project labels by username and repo.
Returns an array of project labels.

### Create a label

```php
$labels = $client->api('issue')->labels()->create('KnpLabs', 'php-github-api', array(
'name' => 'Bug',
'color' => 'FFFFFF',
));
```

Create a new label in the repository.

### Update a label

```php
$labels = $client->api('issue')->labels()->update('KnpLabs', 'php-github-api', 'Enhancement', 'Feature', 'FFFFFF');
```

Update the label name and color.

### Delete a label

```php
$labels = $client->api('issue')->labels()->deleteLabel('KnpLabs', 'php-github-api', 'Bug');
```

Delete a new label from the repository.

### Add a label on an issue

> Requires [authentication](../security.md).
Expand Down
16 changes: 16 additions & 0 deletions lib/Github/Api/Issue/Labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Github\Api\AbstractApi;
use Github\Exception\InvalidArgumentException;
use Github\Exception\MissingArgumentException;

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

public function deleteLabel($username, $repository, $label)
{
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
}

public function update($username, $repository, $label, $newName, $color)
{
$params = array(
'name' => $newName,
'color' => $color,
);

return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params);
}

public function add($username, $repository, $issue, $labels)
{
if (is_string($labels)) {
Expand Down
34 changes: 33 additions & 1 deletion test/Github/Tests/Api/Issue/LabelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class LabelsTest extends TestCase
{

/**
* @test
*/
Expand Down Expand Up @@ -76,6 +75,39 @@ public function shouldCreateLabelWithColor()
$this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data));
}

/**
* @test
*/
public function shouldDeleteLabel()
{
$expectedValue = array('someOutput');

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('repos/KnpLabs/php-github-api/labels/foo')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->deleteLabel('KnpLabs', 'php-github-api', 'foo'));
}

/**
* @test
*/
public function shouldUpdateLabel()
{
$expectedValue = array(array('name' => 'bar', 'color' => 'FFF'));
$data = array('name' => 'bar', 'color' => 'FFF');

$api = $this->getApiMock();
$api->expects($this->once())
->method('patch')
->with('repos/KnpLabs/php-github-api/labels/foo', $data)
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'foo', 'bar', 'FFF'));
}

/**
* @test
*/
Expand Down