From 8c5616c2886d27f58956e8ad2014036db34c993f Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Mon, 13 Apr 2020 10:18:26 -0700 Subject: [PATCH] remove incorrect MissingArgumentException, add docs, update tests --- doc/README.md | 1 + doc/repo/labels.md | 48 +++++++++++++++++++ lib/Github/Api/Repository/Labels.php | 4 -- .../Tests/Api/Repository/LabelsTest.php | 34 +------------ 4 files changed, 51 insertions(+), 36 deletions(-) create mode 100644 doc/repo/labels.md diff --git a/doc/README.md b/doc/README.md index 3d3d3570b8b..c97c33ddc17 100644 --- a/doc/README.md +++ b/doc/README.md @@ -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) diff --git a/doc/repo/labels.md b/doc/repo/labels.md new file mode 100644 index 00000000000..5e924058f77 --- /dev/null +++ b/doc/repo/labels.md @@ -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'); +``` diff --git a/lib/Github/Api/Repository/Labels.php b/lib/Github/Api/Repository/Labels.php index 7829e551e25..28ca4d53c0f 100644 --- a/lib/Github/Api/Repository/Labels.php +++ b/lib/Github/Api/Repository/Labels.php @@ -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); } diff --git a/test/Github/Tests/Api/Repository/LabelsTest.php b/test/Github/Tests/Api/Repository/LabelsTest.php index 6373d459e08..4fe2fd81493 100644 --- a/test/Github/Tests/Api/Repository/LabelsTest.php +++ b/test/Github/Tests/Api/Repository/LabelsTest.php @@ -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())