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

feat: Added new attributes for fork endpoint #820

Open
wants to merge 2 commits into
base: 11.14
Choose a base branch
from
Open
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
72 changes: 60 additions & 12 deletions src/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,16 @@ public function all(array $parameters = [])
->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)
Expand Down Expand Up @@ -379,12 +387,12 @@ public function pipelines($project_id, array $parameters = [])
$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'])
Expand Down Expand Up @@ -1089,8 +1097,16 @@ public function forks($project_id, array $parameters = [])
->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)
Expand Down Expand Up @@ -1150,17 +1166,49 @@ public function forks($project_id, array $parameters = [])
* @param int|string $project_id
* @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 boolean $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)
* }
*
* @return mixed
*/
public function fork($project_id, array $parameters = [])
{
$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);

Expand Down
24 changes: 24 additions & 0 deletions tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,30 @@ public function shouldForkWithNamespaceAndPathAndName(): void
]));
}

/**
* @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
*/
Expand Down