Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add support for `visibility` in `Groups::all`
* Add support for personal access tokens
* Add support for project integrations endpoints
* Add support for `Projects::updateDeployKey`
* Add support for group hook endpoints
* Add support for `job_inputs` and `job_variables_attributes` in `Jobs::play`
* Add support for `inputs` in `Projects::createPipeline`
Expand Down
20 changes: 20 additions & 0 deletions src/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,26 @@ public function addDeployKey(int|string $project_id, string $title, string $key,
]);
}

/**
* @param array $parameters {
*
* @var bool $can_push can deploy key push to the project's repository
* @var string $title new deploy key's title
* }
*/
public function updateDeployKey(int|string $project_id, int $key_id, array $parameters = []): mixed
{
$resolver = new OptionsResolver();
$resolver->setDefined('can_push')
->setAllowedTypes('can_push', 'bool')
;
$resolver->setDefined('title')
->setAllowedTypes('title', 'string')
;

return $this->put($this->getProjectPath($project_id, 'deploy_keys/'.self::encodePath($key_id)), $resolver->resolve($parameters));
}

public function deleteDeployKey(int|string $project_id, int $key_id): mixed
{
return $this->delete($this->getProjectPath($project_id, 'deploy_keys/'.self::encodePath($key_id)));
Expand Down
15 changes: 15 additions & 0 deletions tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,21 @@ public function shouldAddKeyWithPushOption(): void
$this->assertEquals($expectedArray, $api->addDeployKey(1, 'new-key', '...', true));
}

#[Test]
public function shouldUpdateDeployKey(): void
{
$expectedArray = ['id' => 3, 'title' => 'new-title', 'key' => 'ssh-rsa AAAA...', 'can_push' => true];
$parameters = ['can_push' => true, 'title' => 'new-title'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with('projects/1/deploy_keys/3', $parameters)
->willReturn($expectedArray);

$this->assertEquals($expectedArray, $api->updateDeployKey(1, 3, $parameters));
}

#[Test]
public function shouldDeleteDeployKey(): void
{
Expand Down