diff --git a/doc/repo/protection.md b/doc/repo/protection.md index 89a7fc550b3..28ff7c2cb9f 100644 --- a/doc/repo/protection.md +++ b/doc/repo/protection.md @@ -33,3 +33,11 @@ $params = [ ]; $protection = $client->api('repo')->protection()->show('twbs', 'bootstrap', 'master', $params); ``` + +### Remove branch protection + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->remove('twbs', 'bootstrap', 'master'); +``` diff --git a/lib/Github/Api/Repository/Protection.php b/lib/Github/Api/Repository/Protection.php index 6e12410c2ce..33c68bf7960 100644 --- a/lib/Github/Api/Repository/Protection.php +++ b/lib/Github/Api/Repository/Protection.php @@ -52,4 +52,18 @@ public function update($username, $repository, $branch, array $params = array()) { return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection', $params); } + + /** + * Remove the repo's branch protection + * + * @link https://developer.github.com/v3/repos/branches/#remove-branch-protection + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + */ + public function remove($username, $repository, $branch) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection'); + } } diff --git a/test/Github/Tests/Api/Repository/ProtectionTest.php b/test/Github/Tests/Api/Repository/ProtectionTest.php index 48b59b268dd..5b1fb62f17b 100644 --- a/test/Github/Tests/Api/Repository/ProtectionTest.php +++ b/test/Github/Tests/Api/Repository/ProtectionTest.php @@ -39,6 +39,22 @@ public function shouldUpdateProtection() $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'master', $data)); } + /** + * @test + */ + public function shouldRemoveProtection() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'master')); + } + /** * @return string */