diff --git a/src/Api/Projects.php b/src/Api/Projects.php index e96ee96c..7bbc10ba 100644 --- a/src/Api/Projects.php +++ b/src/Api/Projects.php @@ -1363,4 +1363,57 @@ public function deleteProjectAccessToken($project_id, $token_id) { return $this->delete($this->getProjectPath($project_id, 'access_tokens/'.$token_id)); } + + /** + * @param int|string $project_id + * + * @return mixed + */ + public function protectedTags($project_id) + { + return $this->get('projects/'.self::encodePath($project_id).'/protected_tags'); + } + + /** + * @param int|string $project_id + * @param string $tag_name + * + * @return mixed + */ + public function protectedTag($project_id, string $tag_name) + { + return $this->get('projects/'.self::encodePath($project_id).'/protected_tags/'.self::encodePath($tag_name)); + } + + /** + * @param int|string $project_id + * @param array $parameters + * + * @return mixed + */ + public function addProtectedTag($project_id, array $parameters = []) + { + $resolver = new OptionsResolver(); + $resolver->setDefined('name') + ->setAllowedTypes('name', 'string') + ->setRequired('name') + ; + $resolver->setDefined('create_access_level') + ->setAllowedTypes('create_access_level', 'int') + ->setAllowedValues('create_access_level', [0, 30, 40]) + ; + + return $this->post($this->getProjectPath($project_id, 'protected_tags'), $resolver->resolve($parameters)); + } + + /** + * @param int|string $project_id + * @param string $tag_name + * + * @return mixed + */ + public function deleteProtectedTag($project_id, string $tag_name) + { + return $this->delete($this->getProjectPath($project_id, 'protected_tags/'.self::encodePath($tag_name))); + } } diff --git a/tests/Api/ProjectsTest.php b/tests/Api/ProjectsTest.php index 070393df..06c5c4fe 100644 --- a/tests/Api/ProjectsTest.php +++ b/tests/Api/ProjectsTest.php @@ -2530,6 +2530,46 @@ public function shouldUploadAvatar(): void \unlink($fileName); } + /** + * @test + */ + public function shouldAddProtectedTag(): void + { + $expectedArray = [ + 'name' => 'release-*', + 'create_access_level' => [ + 'access_level' => 40, + 'access_level_description' => 'Maintainers', + ], + ]; + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with( + 'projects/1/protected_tags', + ['name' => 'release-*', 'create_access_level' => 40] + ) + ->will($this->returnValue($expectedArray)); + $this->assertEquals($expectedArray, $api->addProtectedTag(1, ['name' => 'release-*', 'create_access_level' => 40])); + } + + /** + * @test + */ + public function shouldRemoveProtectedTag(): void + { + $expectedBool = true; + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with( + 'projects/1/protected_tags/release-%2A' + ) + ->will($this->returnValue($expectedBool)); + + $this->assertEquals($expectedBool, $api->deleteProtectedTag(1, 'release-*')); + } + protected function getApiClass() { return Projects::class;