Skip to content

Commit f899c38

Browse files
GrahamCampbellpkolmannStyleCIBot
authored
[12.1] Add permanent project removal and restore (#872)
* Add permanent project removal and restore Co-authored-by: Philipp Kolmann <2240760+pkolmann@users.noreply.github.com> * Apply fixes from StyleCI --------- Co-authored-by: Philipp Kolmann <2240760+pkolmann@users.noreply.github.com> Co-authored-by: StyleCI Bot <bot@styleci.io>
1 parent a56b039 commit f899c38

3 files changed

Lines changed: 71 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
* Add support for listing merge requests associated with a deployment
2020
* Add support for `with_custom_attributes` and `with_projects` in `Groups::show`
2121
* Add support for project remote mirror read endpoints
22+
* Add support for permanent project removal and project restoration
2223

2324

2425
## [12.0.0] - 2025-02-23

‎src/Api/Projects.php‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,29 @@ public function update(int|string $project_id, array $parameters): mixed
194194
return $this->put('projects/'.self::encodePath($project_id), $parameters);
195195
}
196196

197-
public function remove(int|string $project_id): mixed
197+
/**
198+
* @param array $parameters {
199+
*
200+
* @var string $full_path full path of project to use with permanently_remove
201+
* @var bool|string $permanently_remove Immediately delete a project that is already marked for deletion.
202+
* }
203+
*/
204+
public function remove(int|string $project_id, array $parameters = []): mixed
205+
{
206+
$resolver = new OptionsResolver();
207+
$resolver->setDefined('full_path')
208+
->setAllowedTypes('full_path', 'string')
209+
;
210+
$resolver->setDefined('permanently_remove')
211+
->setAllowedTypes('permanently_remove', ['bool', 'string'])
212+
;
213+
214+
return $this->delete('projects/'.self::encodePath($project_id), $resolver->resolve($parameters));
215+
}
216+
217+
public function restore(int|string $project_id): mixed
198218
{
199-
return $this->delete('projects/'.self::encodePath($project_id));
219+
return $this->post('projects/'.self::encodePath($project_id).'/restore');
200220
}
201221

202222
public function archive(int|string $project_id): mixed

‎tests/Api/ProjectsTest.php‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,54 @@ public function shouldRemoveProject(): void
345345
$this->assertEquals($expectedBool, $api->remove(1));
346346
}
347347

348+
#[Test]
349+
public function shouldRemoveProjectPermanently(): void
350+
{
351+
$expectedBool = true;
352+
353+
$api = $this->getApiMock();
354+
$api->expects($this->once())
355+
->method('delete')
356+
->with('projects/1', ['full_path' => 'group/project', 'permanently_remove' => true])
357+
->willReturn($expectedBool);
358+
359+
$this->assertEquals($expectedBool, $api->remove(1, [
360+
'full_path' => 'group/project',
361+
'permanently_remove' => true,
362+
]));
363+
}
364+
365+
#[Test]
366+
public function shouldRemoveProjectPermanentlyWithStringParameter(): void
367+
{
368+
$expectedBool = true;
369+
370+
$api = $this->getApiMock();
371+
$api->expects($this->once())
372+
->method('delete')
373+
->with('projects/1', ['full_path' => 'group/project', 'permanently_remove' => 'true'])
374+
->willReturn($expectedBool);
375+
376+
$this->assertEquals($expectedBool, $api->remove(1, [
377+
'full_path' => 'group/project',
378+
'permanently_remove' => 'true',
379+
]));
380+
}
381+
382+
#[Test]
383+
public function shouldRestoreProject(): void
384+
{
385+
$expectedArray = ['id' => 1, 'name' => 'Project Name'];
386+
387+
$api = $this->getApiMock();
388+
$api->expects($this->once())
389+
->method('post')
390+
->with('projects/1/restore')
391+
->willReturn($expectedArray);
392+
393+
$this->assertEquals($expectedArray, $api->restore(1));
394+
}
395+
348396
#[Test]
349397
public function shouldGetPipelines(): void
350398
{

0 commit comments

Comments
 (0)