Skip to content

Commit 3011661

Browse files
vkerkhoffponvimishor
authored andcommitted
Updated restriction types
Added newly available restriction types With the update of Bitbucket (premium features) last year, there were some extra Branch Restrictions added: require_tasks_to_be_completed require_passing_builds_to_merge require_all_dependencies_merged require_approvals_to_merge enforce_merge_checks reset_pullrequest_approvals_on_change Also created the option to add new restrictions to the list if Bitbucket adds them. ref: Merged in vkerkhoffpon/bitbucket-api/feature/add-branchpermission-types (pull request #39)
2 parents d9c45f4 + 7716af0 commit 3011661

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

lib/Bitbucket/API/Repositories/BranchRestrictions.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@
2121
*/
2222
class BranchRestrictions extends Api
2323
{
24+
/**
25+
* Allowed restrictions to create a new branch permission for
26+
* @var array
27+
*/
28+
protected $allowedRestrictionTypes = array(
29+
'require_tasks_to_be_completed',
30+
'require_passing_builds_to_merge',
31+
'force',
32+
'require_all_dependencies_merged',
33+
'push',
34+
'require_approvals_to_merge',
35+
'enforce_merge_checks',
36+
'restrict_merges',
37+
'reset_pullrequest_approvals_on_change',
38+
'delete'
39+
);
40+
2441
/**
2542
* Get the information associated with a repository's branch restrictions
2643
*
@@ -64,7 +81,7 @@ public function create($account, $repo, $params = array())
6481

6582
$params = array_merge($defaults, $params);
6683

67-
if (empty($params['kind']) || !in_array($params['kind'], array('push', 'delete', 'force','restrict_merges'))) {
84+
if (empty($params['kind']) || !in_array($params['kind'], $this->allowedRestrictionTypes)) {
6885
throw new \InvalidArgumentException('Invalid restriction kind.');
6986
}
7087

@@ -142,4 +159,14 @@ public function delete($account, $repo, $id)
142159
sprintf('repositories/%s/%s/branch-restrictions/%d', $account, $repo, $id)
143160
);
144161
}
162+
163+
/**
164+
* Add allowed permission types
165+
*
166+
* @param array $restrictions
167+
*/
168+
public function addAllowedRestrictionType($restrictions = array())
169+
{
170+
$this->allowedRestrictionTypes = array_merge($this->allowedRestrictionTypes, $restrictions);
171+
}
145172
}

test/Bitbucket/Tests/API/Repositories/BranchRestrictionsTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ public function testGetAllRestrictions()
2525
$this->assertEquals($expectedResult, $actual);
2626
}
2727

28+
public function testAddRestrictionType()
29+
{
30+
$endpoint = 'repositories/gentle/eof/branch-restrictions';
31+
$params = array(
32+
'kind' => 'testpermission'
33+
);
34+
35+
$client = $this->getHttpClientMock();
36+
$client->expects($this->once())
37+
->method('post')
38+
->with($endpoint, json_encode($params));
39+
40+
/** @var \Bitbucket\API\Repositories\BranchRestrictions $restrictions */
41+
$restrictions = $this->getClassMock('Bitbucket\API\Repositories\BranchRestrictions', $client);
42+
$restrictions->addAllowedRestrictionType(array('testpermission'));
43+
44+
$restrictions->create('gentle', 'eof', $params);
45+
}
46+
2847
public function testCreateRestrictionFromArray()
2948
{
3049
$endpoint = 'repositories/gentle/eof/branch-restrictions';

0 commit comments

Comments
 (0)