Skip to content

[11.1] Add 'search_namespaces' for list-all-projects #615

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

Merged
merged 10 commits into from
Jan 13, 2021
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Added CI schedule variables endpoints
* Added support for triggering a pipeline
* Added support for the search_namespaces projects parameter

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

Expand Down
5 changes: 5 additions & 0 deletions src/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Projects extends AbstractApi
* or last_activity_at fields (default is created_at)
* @var string $sort Return projects sorted in asc or desc order (default is desc)
* @var string $search return list of projects matching the search criteria
* @var bool $search_namespaces Include ancestor namespaces when matching search criteria
* @var bool $simple return only the ID, URL, name, and path of each project
* @var bool $owned limit by projects owned by the current user
* @var bool $membership limit by projects that the current user is a member of
Expand Down Expand Up @@ -66,6 +67,10 @@ public function all(array $parameters = [])
->setAllowedValues('sort', ['asc', 'desc'])
;
$resolver->setDefined('search');
$resolver->setDefined('search_namespaces')
->setAllowedTypes('search_namespaces', 'bool')
->setNormalizer('search_namespaces', $booleanNormalizer)
;
$resolver->setDefined('simple')
->setAllowedTypes('simple', 'bool')
->setNormalizer('simple', $booleanNormalizer)
Expand Down
19 changes: 19 additions & 0 deletions tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ public function shouldSearchProjects(): void
$this->assertEquals($expectedArray, $api->all(['search' => 'a project']));
}

/**
* @test
*/
public function shouldSearchProjectsWithNamespace(): void
{
$expectedArray = $this->getMultipleProjectsDataWithNamespace();

$api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, ['search' => 'a_project', 'search_namespaces' => 'true']);
$this->assertEquals($expectedArray, $api->all(['search' => 'a_project', 'search_namespaces' => true]));
}

/**
* @test
*/
Expand Down Expand Up @@ -1914,6 +1925,14 @@ protected function getMultipleProjectsData()
];
}

protected function getMultipleProjectsDataWithNamespace()
{
return [
['id' => 1, 'name' => 'A project', 'namespace' => ['id' => 4, 'name' => 'A namespace', 'path' => 'a_namespace']],
['id' => 2, 'name' => 'Another project', 'namespace' => ['id' => 5, 'name' => 'Another namespace', 'path' => 'another_namespace']],
];
}

public function possibleAccessLevels()
{
return [
Expand Down