Skip to content

Commit a7ef084

Browse files
[11.5] Add deleteProtectedBranch method to projects api (#680)
* add deleteProtectedBranch method to projects api. Handles the functionality to delete/unprotect a protected branch which is documented here: https://docs.gitlab.com/ee/api/protected_branches.html#unprotect-repository-branches * Fixed param name Co-authored-by: Graham Campbell <[email protected]>
1 parent b138596 commit a7ef084

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Api/Projects.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,17 @@ public function addProtectedBranch($project_id, array $parameters = [])
12021202
return $this->post($this->getProjectPath($project_id, 'protected_branches'), $parameters);
12031203
}
12041204

1205+
/**
1206+
* @param int|string $project_id
1207+
* @param string $branch_name
1208+
*
1209+
* @return mixed
1210+
*/
1211+
public function deleteProtectedBranch($project_id, string $branch_name)
1212+
{
1213+
return $this->delete($this->getProjectPath($project_id, 'protected_branches/'.self::encodePath($branch_name)));
1214+
}
1215+
12051216
/**
12061217
* @param int|string $project_id
12071218
*

tests/Api/ProjectsTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,23 @@ public function shouldAddProtectedBranch(): void
22172217
$this->assertEquals($expectedArray, $api->addProtectedBranch(1, ['name' => 'master', 'push_access_level' => 0, 'merge_access_level' => 30]));
22182218
}
22192219

2220+
/**
2221+
* @test
2222+
*/
2223+
public function shouldRemoveProtectedBranch(): void
2224+
{
2225+
$expectedBool = true;
2226+
$api = $this->getApiMock();
2227+
$api->expects($this->once())
2228+
->method('delete')
2229+
->with(
2230+
'projects/1/protected_branches/test-branch'
2231+
)
2232+
->will($this->returnValue($expectedBool));
2233+
2234+
$this->assertEquals($expectedBool, $api->deleteProtectedBranch(1, 'test-branch'));
2235+
}
2236+
22202237
/**
22212238
* @test
22222239
*/

0 commit comments

Comments
 (0)