diff --git a/src/Api/Projects.php b/src/Api/Projects.php index 32aa168a..c13d511e 100644 --- a/src/Api/Projects.php +++ b/src/Api/Projects.php @@ -72,8 +72,16 @@ public function all(array $parameters = []): mixed ->setAllowedValues('visibility', ['public', 'internal', 'private']) ; $orderBy = [ - 'id', 'name', 'path', 'created_at', 'updated_at', 'last_activity_at', - 'repository_size', 'storage_size', 'packages_size', 'wiki_size', + 'id', + 'name', + 'path', + 'created_at', + 'updated_at', + 'last_activity_at', + 'repository_size', + 'storage_size', + 'packages_size', + 'wiki_size', ]; $resolver->setDefined('order_by') ->setAllowedValues('order_by', $orderBy) @@ -294,12 +302,12 @@ public function pipelines(int|string $project_id, array $parameters = []): mixed $resolver->setDefined('name'); $resolver->setDefined('username'); $resolver->setDefined('updated_after') - ->setAllowedTypes('updated_after', \DateTimeInterface::class) - ->setNormalizer('updated_after', $datetimeNormalizer) + ->setAllowedTypes('updated_after', \DateTimeInterface::class) + ->setNormalizer('updated_after', $datetimeNormalizer) ; $resolver->setDefined('updated_before') - ->setAllowedTypes('updated_before', \DateTimeInterface::class) - ->setNormalizer('updated_before', $datetimeNormalizer) + ->setAllowedTypes('updated_before', \DateTimeInterface::class) + ->setNormalizer('updated_before', $datetimeNormalizer) ; $resolver->setDefined('order_by') ->setAllowedValues('order_by', ['id', 'status', 'ref', 'updated_at', 'user_id']) @@ -771,8 +779,16 @@ public function forks(int|string $project_id, array $parameters = []): mixed ->setAllowedValues('visibility', ['public', 'internal', 'private']) ; $orderBy = [ - 'id', 'name', 'path', 'created_at', 'updated_at', 'last_activity_at', - 'repository_size', 'storage_size', 'packages_size', 'wiki_size', + 'id', + 'name', + 'path', + 'created_at', + 'updated_at', + 'last_activity_at', + 'repository_size', + 'storage_size', + 'packages_size', + 'wiki_size', ]; $resolver->setDefined('order_by') ->setAllowedValues('order_by', $orderBy) @@ -831,15 +847,47 @@ public function forks(int|string $project_id, array $parameters = []): mixed /** * @param array $parameters { * - * @var string $namespace The ID or path of the namespace that the project will be forked to - * @var string $path The path of the forked project (optional) - * @var string $name The name of the forked project (optional) + * @var string $namespace (Deprecated) The ID or path of the namespace that the project will be forked to (optional) + * @var int $namespace_id The ID of the namespace that the project is forked to. (optional) + * @var string $namespace_path The path of the namespace that the project is forked to. (optional) + * @var string $path The path of the forked project (optional) + * @var string $name The name of the forked project (optional) + * @var string $branches The branches to fork (empty for all branches) (optional) + * @var string $description The description assigned to the resultant project after forking (optional) + * @var bool $mr_default_target_self For forked projects, target merge requests to this project. If false, the target is the upstream project. (optional) + * @var string $visibility The visibility level assigned to the resultant project after forking. (optional) * } */ public function fork(int|string $project_id, array $parameters = []): mixed { $resolver = new OptionsResolver(); - $resolver->setDefined(['namespace', 'path', 'name']); + $resolver->setDefined('namespace') + ->setDeprecated('namespace', '13.0', 'The "namespace" parameter is deprecated. Use "namespace_id" or "namespace_path" instead.') + ; + $resolver->setDefined('namespace_id') + ->setAllowedTypes('namespace_id', 'int') + ; + $resolver->setDefined('namespace_path') + ->setAllowedTypes('namespace_path', 'string') + ; + $resolver->setDefined('path') + ->setAllowedTypes('path', 'string') + ; + $resolver->setDefined('name') + ->setAllowedTypes('name', 'string') + ; + $resolver->setDefined('branches') + ->setAllowedTypes('branches', 'string') + ; + $resolver->setDefined('description') + ->setAllowedTypes('description', 'string') + ; + $resolver->setDefined('mr_default_target_self') + ->setAllowedTypes('mr_default_target_self', 'bool') + ; + $resolver->setDefined('visibility') + ->setAllowedValues('visibility', ['private', 'internal', 'public']) + ; $resolved = $resolver->resolve($parameters); diff --git a/tests/Api/ProjectsTest.php b/tests/Api/ProjectsTest.php index 62b5dfcc..010560fe 100644 --- a/tests/Api/ProjectsTest.php +++ b/tests/Api/ProjectsTest.php @@ -1686,7 +1686,33 @@ public function shouldForkWithNamespaceAndPathAndName(): void ])); } - #[Test] + /** + * @test + */ + public function shouldForkWithAllParametersNamespacePath(): void + { + $expectedArray = [ + 'branches' => 'master', + 'namespace_path' => 'new_namespace', + 'path' => 'new_path', + 'name' => 'new_name', + 'description' => 'new_description', + 'visibility' => 'public', + 'mr_default_target_self' => true, + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/fork', $expectedArray) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->fork(1, $expectedArray)); + } + + /** + * @test + */ public function shouldCreateForkRelation(): void { $expectedArray = ['project_id' => 1, 'forked_id' => 2];