Skip to content
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
8 changes: 8 additions & 0 deletions doc/repo/protection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```
14 changes: 14 additions & 0 deletions lib/Github/Api/Repository/Protection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
16 changes: 16 additions & 0 deletions test/Github/Tests/Api/Repository/ProtectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down