Skip to content
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

[11.6] Add support for protected tags #679

Closed
wants to merge 1 commit into from
Closed
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
44 changes: 44 additions & 0 deletions src/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,50 @@ public function addProtectedBranch($project_id, array $parameters = [])
return $this->post($this->getProjectPath($project_id, 'protected_branches'), $parameters);
}

/**
* @param int|string $project_id
* @param string $branch_name
*
* @return mixed
*/
public function removeProtectedBranch($project_id, string $branch_name)
{
return $this->delete($this->getProjectPath($project_id, 'protected_branches/'.self::encodePath($branch_name)));
}

/**
* @param int|string $project_id
* @param array $parameters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot merge this with arbitrary undocumented parameters. Please either delete the parameter, or document those that are permitted, enforced with the options resolver.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied how the protectedBranches method was implemented. Is there some extra documentation somewhere that I missed, that I should add to?

*
* @return mixed
*/
public function protectedTags($project_id, array $parameters = [])
{
return $this->get('projects/'.self::encodePath($project_id).'/protected_tags', $parameters);
}

/**
* @param int|string $project_id
* @param array $parameters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

*
* @return mixed
*/
public function addProtectedTag($project_id, array $parameters = [])
{
return $this->post($this->getProjectPath($project_id, 'protected_tags'), $parameters);
}

/**
* @param int|string $project_id
* @param string $tag_name
*
* @return mixed
*/
public function removeProtectedTag($project_id, string $tag_name)
{
return $this->delete($this->getProjectPath($project_id, 'protected_tags/'.self::encodePath($tag_name)));
}

/**
* @param int|string $project_id
*
Expand Down
82 changes: 82 additions & 0 deletions tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,62 @@ public function shouldAddProtectedBranch(): void
$this->assertEquals($expectedArray, $api->addProtectedBranch(1, ['name' => 'master', 'push_access_level' => 0, 'merge_access_level' => 30]));
}

/**
* @test
*/
public function shouldRemoveProtectedBranch(): void
{
$expectedBool = true;

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('projects/1/protected_branches/master')
->will($this->returnValue($expectedBool));

$this->assertEquals($expectedBool, $api->removeProtectedBranch(1, 'master'));
}

/**
* @test
*/
public function shouldAddProtectedTag(): void
{
$expectedArray = [
'name' => 'release-1-0',
'create_access_level' => [
'access_level' => 40,
'access_level_description' => 'Maintainer',
],
];
$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with(
'projects/1/protected_tags',
['name' => 'release-1-0', 'create_access_level' => 40]
)
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->addProtectedTag(1, ['name' => 'release-1-0', '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-1-0')
->will($this->returnValue($expectedBool));

$this->assertEquals($expectedBool, $api->removeProtectedTag(1, 'release-1-0'));
}

/**
* @test
*/
Expand Down Expand Up @@ -2321,6 +2377,32 @@ public function shouldGetProtectedBranches(): void
$this->assertEquals($expectedArray, $api->protectedBranches(1));
}

/**
* @test
*/
public function shouldGetProtectedTags(): void
{
$expectedArray = [
[
'name' => 'release-1-0',
'create_access_levels' => [
[
'access_level' => 40,
'access_level_description' => 'Maintainer',
],
],
],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/protected_tags')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->protectedTags(1));
}

/**
* @test
*/
Expand Down