Skip to content

add method to remove branch protection and doc example #603

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 2 commits into from
Jun 12, 2017
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