Skip to content

Commit 992dc61

Browse files
Add 'search_namespaces' for list-all-projects (#615)
Co-authored-by: Graham Campbell <[email protected]>
1 parent 20fd406 commit 992dc61

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
* Added CI schedule variables endpoints
1111
* Added support for triggering a pipeline
12+
* Added support for the search_namespaces projects parameter
1213

1314
[11.1.0]: https://github.com/GitLabPHP/Client/compare/11.0.0...11.1.0
1415

src/Api/Projects.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Projects extends AbstractApi
3030
* or last_activity_at fields (default is created_at)
3131
* @var string $sort Return projects sorted in asc or desc order (default is desc)
3232
* @var string $search return list of projects matching the search criteria
33+
* @var bool $search_namespaces Include ancestor namespaces when matching search criteria
3334
* @var bool $simple return only the ID, URL, name, and path of each project
3435
* @var bool $owned limit by projects owned by the current user
3536
* @var bool $membership limit by projects that the current user is a member of
@@ -66,6 +67,10 @@ public function all(array $parameters = [])
6667
->setAllowedValues('sort', ['asc', 'desc'])
6768
;
6869
$resolver->setDefined('search');
70+
$resolver->setDefined('search_namespaces')
71+
->setAllowedTypes('search_namespaces', 'bool')
72+
->setNormalizer('search_namespaces', $booleanNormalizer)
73+
;
6974
$resolver->setDefined('simple')
7075
->setAllowedTypes('simple', 'bool')
7176
->setNormalizer('simple', $booleanNormalizer)

tests/Api/ProjectsTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ public function shouldSearchProjects(): void
125125
$this->assertEquals($expectedArray, $api->all(['search' => 'a project']));
126126
}
127127

128+
/**
129+
* @test
130+
*/
131+
public function shouldSearchProjectsWithNamespace(): void
132+
{
133+
$expectedArray = $this->getMultipleProjectsDataWithNamespace();
134+
135+
$api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, ['search' => 'a_project', 'search_namespaces' => 'true']);
136+
$this->assertEquals($expectedArray, $api->all(['search' => 'a_project', 'search_namespaces' => true]));
137+
}
138+
128139
/**
129140
* @test
130141
*/
@@ -1914,6 +1925,14 @@ protected function getMultipleProjectsData()
19141925
];
19151926
}
19161927

1928+
protected function getMultipleProjectsDataWithNamespace()
1929+
{
1930+
return [
1931+
['id' => 1, 'name' => 'A project', 'namespace' => ['id' => 4, 'name' => 'A namespace', 'path' => 'a_namespace']],
1932+
['id' => 2, 'name' => 'Another project', 'namespace' => ['id' => 5, 'name' => 'Another namespace', 'path' => 'another_namespace']],
1933+
];
1934+
}
1935+
19171936
public function possibleAccessLevels()
19181937
{
19191938
return [

0 commit comments

Comments
 (0)