Skip to content

Commit 2a1cea0

Browse files
Add project deploy key update API (#892)
Co-authored-by: Nicolas Giraud <9560327+niconoe-@users.noreply.github.com>
1 parent 98a31a5 commit 2a1cea0

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
* Add support for `visibility` in `Groups::all`
1313
* Add support for personal access tokens
1414
* Add support for project integrations endpoints
15+
* Add support for `Projects::updateDeployKey`
1516
* Add support for group hook endpoints
1617
* Add support for `job_inputs` and `job_variables_attributes` in `Jobs::play`
1718
* Add support for `inputs` in `Projects::createPipeline`

‎src/Api/Projects.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,26 @@ public function addDeployKey(int|string $project_id, string $title, string $key,
613613
]);
614614
}
615615

616+
/**
617+
* @param array $parameters {
618+
*
619+
* @var bool $can_push can deploy key push to the project's repository
620+
* @var string $title new deploy key's title
621+
* }
622+
*/
623+
public function updateDeployKey(int|string $project_id, int $key_id, array $parameters = []): mixed
624+
{
625+
$resolver = new OptionsResolver();
626+
$resolver->setDefined('can_push')
627+
->setAllowedTypes('can_push', 'bool')
628+
;
629+
$resolver->setDefined('title')
630+
->setAllowedTypes('title', 'string')
631+
;
632+
633+
return $this->put($this->getProjectPath($project_id, 'deploy_keys/'.self::encodePath($key_id)), $resolver->resolve($parameters));
634+
}
635+
616636
public function deleteDeployKey(int|string $project_id, int $key_id): mixed
617637
{
618638
return $this->delete($this->getProjectPath($project_id, 'deploy_keys/'.self::encodePath($key_id)));

‎tests/Api/ProjectsTest.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,21 @@ public function shouldAddKeyWithPushOption(): void
14191419
$this->assertEquals($expectedArray, $api->addDeployKey(1, 'new-key', '...', true));
14201420
}
14211421

1422+
#[Test]
1423+
public function shouldUpdateDeployKey(): void
1424+
{
1425+
$expectedArray = ['id' => 3, 'title' => 'new-title', 'key' => 'ssh-rsa AAAA...', 'can_push' => true];
1426+
$parameters = ['can_push' => true, 'title' => 'new-title'];
1427+
1428+
$api = $this->getApiMock();
1429+
$api->expects($this->once())
1430+
->method('put')
1431+
->with('projects/1/deploy_keys/3', $parameters)
1432+
->willReturn($expectedArray);
1433+
1434+
$this->assertEquals($expectedArray, $api->updateDeployKey(1, 3, $parameters));
1435+
}
1436+
14221437
#[Test]
14231438
public function shouldDeleteDeployKey(): void
14241439
{

0 commit comments

Comments
 (0)