Skip to content

Commit aa4e285

Browse files
authored
Merge pull request #603 from bobeagan/remove-branch-protection
add method to remove branch protection and doc example
2 parents f7be4c5 + 5a5231e commit aa4e285

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

doc/repo/protection.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ $params = [
3333
];
3434
$protection = $client->api('repo')->protection()->show('twbs', 'bootstrap', 'master', $params);
3535
```
36+
37+
### Remove branch protection
38+
39+
> Requires [authentication](../security.md).
40+
41+
```php
42+
$protection = $client->api('repo')->protection()->remove('twbs', 'bootstrap', 'master');
43+
```

lib/Github/Api/Repository/Protection.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,18 @@ public function update($username, $repository, $branch, array $params = array())
5252
{
5353
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection', $params);
5454
}
55+
56+
/**
57+
* Remove the repo's branch protection
58+
*
59+
* @link https://developer.github.com/v3/repos/branches/#remove-branch-protection
60+
*
61+
* @param string $username The user who owns the repository
62+
* @param string $repository The name of the repo
63+
* @param string $branch The name of the branch
64+
*/
65+
public function remove($username, $repository, $branch)
66+
{
67+
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection');
68+
}
5569
}

test/Github/Tests/Api/Repository/ProtectionTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ public function shouldUpdateProtection()
3939
$this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'master', $data));
4040
}
4141

42+
/**
43+
* @test
44+
*/
45+
public function shouldRemoveProtection()
46+
{
47+
$expectedValue = array('someOutput');
48+
49+
$api = $this->getApiMock();
50+
$api->expects($this->once())
51+
->method('delete')
52+
->with('/repos/KnpLabs/php-github-api/branches/master/protection')
53+
->will($this->returnValue($expectedValue));
54+
55+
$this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'master'));
56+
}
57+
4258
/**
4359
* @return string
4460
*/

0 commit comments

Comments
 (0)