Skip to content

Commit 096d9c3

Browse files
authored
Add method to get protected branches for a project (#567)
Co-authored-by: Lee Boynton <[email protected]>
1 parent 951bf53 commit 096d9c3

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/Api/Projects.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,17 @@ public function updateBadge($project_id, int $badge_id, array $parameters = [])
10411041
return $this->put($this->getProjectPath($project_id, 'badges/'.self::encodePath($badge_id)), $parameters);
10421042
}
10431043

1044+
/**
1045+
* @param int|string $project_id
1046+
* @param array $parameters
1047+
*
1048+
* @return mixed
1049+
*/
1050+
public function protectedBranches($project_id, array $parameters = [])
1051+
{
1052+
return $this->get('projects/'.self::encodePath($project_id).'/protected_branches');
1053+
}
1054+
10441055
/**
10451056
* @param int|string $project_id
10461057
* @param array $parameters

tests/Api/ProjectsTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,41 @@ public function shouldDeleteAllMergedBranches(): void
20042004
$this->assertEquals($expectedBool, $api->deleteAllMergedBranches(1));
20052005
}
20062006

2007+
/**
2008+
* @test
2009+
*/
2010+
public function shouldGetProtectedBranches(): void
2011+
{
2012+
$expectedArray = [
2013+
[
2014+
'id' => 1,
2015+
'name' => 'master',
2016+
'push_access_levels' => [
2017+
'access_level' => 0,
2018+
'access_level_description' => 'No one',
2019+
'user_id' => null,
2020+
'group_id' => null,
2021+
],
2022+
'merge_access_levels' => [
2023+
'access_level' => 40,
2024+
'access_level_description' => 'Maintainers',
2025+
'user_id' => null,
2026+
'group_id' => null,
2027+
],
2028+
'unprotect_access_levels' => [],
2029+
'code_owner_approval_required' => false,
2030+
],
2031+
];
2032+
2033+
$api = $this->getApiMock();
2034+
$api->expects($this->once())
2035+
->method('get')
2036+
->with('projects/1/protected_branches')
2037+
->will($this->returnValue($expectedArray));
2038+
2039+
$this->assertEquals($expectedArray, $api->protectedBranches(1));
2040+
}
2041+
20072042
protected function getApiClass()
20082043
{
20092044
return Projects::class;

0 commit comments

Comments
 (0)