Skip to content

Commit

Permalink
Merge pull request #861 from bobeagan/859/fix-repo-labels-update
Browse files Browse the repository at this point in the history
Remove incorrect MissingArgumentException, add docs, update tests
  • Loading branch information
acrobat authored Apr 15, 2020
2 parents 94dec1e + 8c5616c commit 9c51657
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 36 deletions.
1 change: 1 addition & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ v3 APIs:
* [Checks](repo/checks.md)
* [Contents](repo/contents.md)
* [Deployments](repo/deployments.md)
* [Labels](repo/labels.md)
* [Protection](repo/protection.md)
* [Releases](repo/releases.md)
* [Assets](repo/assets.md)
Expand Down
48 changes: 48 additions & 0 deletions doc/repo/labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Repo / Labels API
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md)

### List all labels for this repository

```php
$labels = $client->api('repo')->labels()->all('twbs', 'bootstrap');
```

### Get a single label

```php
$label = $client->api('repo')->labels()->show('twbs', 'bootstrap', 'feature');
```

### Create a label

> Requires [authentication](../security.md).
```php
$params = [
'name' => 'bug',
'color' => 'f29513',
'description' => 'Something isn\'t working',
];
$label = $client->api('repo')->labels()->create('twbs', 'bootstrap', $params);
```

### Update a label

> Requires [authentication](../security.md).
```php
$params = [
'new_name' => 'bug :bug:',
'color' => 'b01f26',
'description' => 'Small bug fix required',
];
$label = $client->api('repo')->labels()->update('twbs', 'bootstrap', 'bug', $params);
```

### Delete a label

> Requires [authentication](../security.md).
```php
$label = $client->api('repo')->labels()->remove('twbs', 'bootstrap', 'bug');
```
4 changes: 0 additions & 4 deletions lib/Github/Api/Repository/Labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public function create($username, $repository, array $params)

public function update($username, $repository, $label, array $params)
{
if (!isset($params['name'], $params['color'])) {
throw new MissingArgumentException(['name', 'color']);
}

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

Expand Down
34 changes: 2 additions & 32 deletions test/Github/Tests/Api/Repository/LabelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,43 +102,13 @@ public function shouldCreateLabel()
$this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data));
}

/**
* @test
*/
public function shouldNotUpdateLabelWithoutName()
{
$this->expectException(MissingArgumentException::class);
$data = ['color' => 'red'];

$api = $this->getApiMock();
$api->expects($this->never())
->method('patch');

$api->update('KnpLabs', 'php-github-api', 'labelName', $data);
}

/**
* @test
*/
public function shouldNotUpdateLabelWithoutColor()
{
$this->expectException(MissingArgumentException::class);
$data = ['name' => 'test'];

$api = $this->getApiMock();
$api->expects($this->never())
->method('patch');

$api->update('KnpLabs', 'php-github-api', 'labelName', $data);
}

/**
* @test
*/
public function shouldUpdateLabel()
{
$expectedValue = ['label' => 'somename'];
$data = ['name' => 'test', 'color' => 'red'];
$expectedValue = ['name' => 'test'];
$data = ['new_name' => 'test', 'color' => 'red'];

$api = $this->getApiMock();
$api->expects($this->once())
Expand Down

0 comments on commit 9c51657

Please sign in to comment.