Skip to content

Commit 496f0f1

Browse files
committed
Merge branch 'feat/more_fork_parameters' into 12.0
# Conflicts: # tests/Api/ProjectsTest.php
2 parents 1bf5326 + c60ebb8 commit 496f0f1

File tree

2 files changed

+87
-13
lines changed

2 files changed

+87
-13
lines changed

src/Api/Projects.php

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,16 @@ public function all(array $parameters = []): mixed
7272
->setAllowedValues('visibility', ['public', 'internal', 'private'])
7373
;
7474
$orderBy = [
75-
'id', 'name', 'path', 'created_at', 'updated_at', 'last_activity_at',
76-
'repository_size', 'storage_size', 'packages_size', 'wiki_size',
75+
'id',
76+
'name',
77+
'path',
78+
'created_at',
79+
'updated_at',
80+
'last_activity_at',
81+
'repository_size',
82+
'storage_size',
83+
'packages_size',
84+
'wiki_size',
7785
];
7886
$resolver->setDefined('order_by')
7987
->setAllowedValues('order_by', $orderBy)
@@ -294,12 +302,12 @@ public function pipelines(int|string $project_id, array $parameters = []): mixed
294302
$resolver->setDefined('name');
295303
$resolver->setDefined('username');
296304
$resolver->setDefined('updated_after')
297-
->setAllowedTypes('updated_after', \DateTimeInterface::class)
298-
->setNormalizer('updated_after', $datetimeNormalizer)
305+
->setAllowedTypes('updated_after', \DateTimeInterface::class)
306+
->setNormalizer('updated_after', $datetimeNormalizer)
299307
;
300308
$resolver->setDefined('updated_before')
301-
->setAllowedTypes('updated_before', \DateTimeInterface::class)
302-
->setNormalizer('updated_before', $datetimeNormalizer)
309+
->setAllowedTypes('updated_before', \DateTimeInterface::class)
310+
->setNormalizer('updated_before', $datetimeNormalizer)
303311
;
304312
$resolver->setDefined('order_by')
305313
->setAllowedValues('order_by', ['id', 'status', 'ref', 'updated_at', 'user_id'])
@@ -771,8 +779,16 @@ public function forks(int|string $project_id, array $parameters = []): mixed
771779
->setAllowedValues('visibility', ['public', 'internal', 'private'])
772780
;
773781
$orderBy = [
774-
'id', 'name', 'path', 'created_at', 'updated_at', 'last_activity_at',
775-
'repository_size', 'storage_size', 'packages_size', 'wiki_size',
782+
'id',
783+
'name',
784+
'path',
785+
'created_at',
786+
'updated_at',
787+
'last_activity_at',
788+
'repository_size',
789+
'storage_size',
790+
'packages_size',
791+
'wiki_size',
776792
];
777793
$resolver->setDefined('order_by')
778794
->setAllowedValues('order_by', $orderBy)
@@ -831,15 +847,47 @@ public function forks(int|string $project_id, array $parameters = []): mixed
831847
/**
832848
* @param array $parameters {
833849
*
834-
* @var string $namespace The ID or path of the namespace that the project will be forked to
835-
* @var string $path The path of the forked project (optional)
836-
* @var string $name The name of the forked project (optional)
850+
* @var string $namespace (Deprecated) The ID or path of the namespace that the project will be forked to (optional)
851+
* @var int $namespace_id The ID of the namespace that the project is forked to. (optional)
852+
* @var string $namespace_path The path of the namespace that the project is forked to. (optional)
853+
* @var string $path The path of the forked project (optional)
854+
* @var string $name The name of the forked project (optional)
855+
* @var string $branches The branches to fork (empty for all branches) (optional)
856+
* @var string $description The description assigned to the resultant project after forking (optional)
857+
* @var boolean $mr_default_target_self For forked projects, target merge requests to this project. If false, the target is the upstream project. (optional)
858+
* @var string $visibility The visibility level assigned to the resultant project after forking. (optional)
837859
* }
838860
*/
839861
public function fork(int|string $project_id, array $parameters = []): mixed
840862
{
841863
$resolver = new OptionsResolver();
842-
$resolver->setDefined(['namespace', 'path', 'name']);
864+
$resolver->setDefined('namespace')
865+
->setDeprecated('namespace', '13.0', 'The "namespace" parameter is deprecated. Use "namespace_id" or "namespace_path" instead.')
866+
;
867+
$resolver->setDefined('namespace_id')
868+
->setAllowedTypes('namespace_id', 'int')
869+
;
870+
$resolver->setDefined('namespace_path')
871+
->setAllowedTypes('namespace_path', 'string')
872+
;
873+
$resolver->setDefined('path')
874+
->setAllowedTypes('path', 'string')
875+
;
876+
$resolver->setDefined('name')
877+
->setAllowedTypes('name', 'string')
878+
;
879+
$resolver->setDefined('branches')
880+
->setAllowedTypes('branches', 'string')
881+
;
882+
$resolver->setDefined('description')
883+
->setAllowedTypes('description', 'string')
884+
;
885+
$resolver->setDefined('mr_default_target_self')
886+
->setAllowedTypes('mr_default_target_self', 'bool')
887+
;
888+
$resolver->setDefined('visibility')
889+
->setAllowedValues('visibility', ['private', 'internal', 'public'])
890+
;
843891

844892
$resolved = $resolver->resolve($parameters);
845893

tests/Api/ProjectsTest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,33 @@ public function shouldForkWithNamespaceAndPathAndName(): void
16861686
]));
16871687
}
16881688

1689-
#[Test]
1689+
/**
1690+
* @test
1691+
*/
1692+
public function shouldForkWithAllParametersNamespacePath(): void
1693+
{
1694+
$expectedArray = [
1695+
'branches' => 'master',
1696+
'namespace_path' => 'new_namespace',
1697+
'path' => 'new_path',
1698+
'name' => 'new_name',
1699+
'description' => 'new_description',
1700+
'visibility' => 'public',
1701+
'mr_default_target_self' => 'true',
1702+
];
1703+
1704+
$api = $this->getApiMock();
1705+
$api->expects($this->once())
1706+
->method('post')
1707+
->with('projects/1/fork', $expectedArray)
1708+
->will($this->returnValue($expectedArray));
1709+
1710+
$this->assertEquals($expectedArray, $api->fork(1, $expectedArray));
1711+
}
1712+
1713+
/**
1714+
* @test
1715+
*/
16901716
public function shouldCreateForkRelation(): void
16911717
{
16921718
$expectedArray = ['project_id' => 1, 'forked_id' => 2];

0 commit comments

Comments
 (0)