Skip to content

Commit b5b6b20

Browse files
authored
Add support for protected tags (#699)
1 parent d9c7923 commit b5b6b20

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

src/Api/Projects.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,4 +1363,57 @@ public function deleteProjectAccessToken($project_id, $token_id)
13631363
{
13641364
return $this->delete($this->getProjectPath($project_id, 'access_tokens/'.$token_id));
13651365
}
1366+
1367+
/**
1368+
* @param int|string $project_id
1369+
*
1370+
* @return mixed
1371+
*/
1372+
public function protectedTags($project_id)
1373+
{
1374+
return $this->get('projects/'.self::encodePath($project_id).'/protected_tags');
1375+
}
1376+
1377+
/**
1378+
* @param int|string $project_id
1379+
* @param string $tag_name
1380+
*
1381+
* @return mixed
1382+
*/
1383+
public function protectedTag($project_id, string $tag_name)
1384+
{
1385+
return $this->get('projects/'.self::encodePath($project_id).'/protected_tags/'.self::encodePath($tag_name));
1386+
}
1387+
1388+
/**
1389+
* @param int|string $project_id
1390+
* @param array $parameters
1391+
*
1392+
* @return mixed
1393+
*/
1394+
public function addProtectedTag($project_id, array $parameters = [])
1395+
{
1396+
$resolver = new OptionsResolver();
1397+
$resolver->setDefined('name')
1398+
->setAllowedTypes('name', 'string')
1399+
->setRequired('name')
1400+
;
1401+
$resolver->setDefined('create_access_level')
1402+
->setAllowedTypes('create_access_level', 'int')
1403+
->setAllowedValues('create_access_level', [0, 30, 40])
1404+
;
1405+
1406+
return $this->post($this->getProjectPath($project_id, 'protected_tags'), $resolver->resolve($parameters));
1407+
}
1408+
1409+
/**
1410+
* @param int|string $project_id
1411+
* @param string $tag_name
1412+
*
1413+
* @return mixed
1414+
*/
1415+
public function deleteProtectedTag($project_id, string $tag_name)
1416+
{
1417+
return $this->delete($this->getProjectPath($project_id, 'protected_tags/'.self::encodePath($tag_name)));
1418+
}
13661419
}

tests/Api/ProjectsTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,6 +2530,46 @@ public function shouldUploadAvatar(): void
25302530
\unlink($fileName);
25312531
}
25322532

2533+
/**
2534+
* @test
2535+
*/
2536+
public function shouldAddProtectedTag(): void
2537+
{
2538+
$expectedArray = [
2539+
'name' => 'release-*',
2540+
'create_access_level' => [
2541+
'access_level' => 40,
2542+
'access_level_description' => 'Maintainers',
2543+
],
2544+
];
2545+
$api = $this->getApiMock();
2546+
$api->expects($this->once())
2547+
->method('post')
2548+
->with(
2549+
'projects/1/protected_tags',
2550+
['name' => 'release-*', 'create_access_level' => 40]
2551+
)
2552+
->will($this->returnValue($expectedArray));
2553+
$this->assertEquals($expectedArray, $api->addProtectedTag(1, ['name' => 'release-*', 'create_access_level' => 40]));
2554+
}
2555+
2556+
/**
2557+
* @test
2558+
*/
2559+
public function shouldRemoveProtectedTag(): void
2560+
{
2561+
$expectedBool = true;
2562+
$api = $this->getApiMock();
2563+
$api->expects($this->once())
2564+
->method('delete')
2565+
->with(
2566+
'projects/1/protected_tags/release-%2A'
2567+
)
2568+
->will($this->returnValue($expectedBool));
2569+
2570+
$this->assertEquals($expectedBool, $api->deleteProtectedTag(1, 'release-*'));
2571+
}
2572+
25332573
protected function getApiClass()
25342574
{
25352575
return Projects::class;

0 commit comments

Comments
 (0)