Skip to content

[11.8] Add support for protected tags #699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
40 changes: 40 additions & 0 deletions tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down