Skip to content

[11.2] Add missing parameters to the GitLab\Api\Projects:all method #623

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

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [11.2.0] - UPCOMING

* UPCOMING
* Add support for the following projects parameters: id_after, id_before, last_activity_after, last_activity_before, repository_checksum_failed, repository_storage, wiki_checksum_failed, with_custom_attributes, with_programming_language

## [11.1.0] - 2021-01-25

Expand Down
72 changes: 56 additions & 16 deletions src/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,31 @@ class Projects extends AbstractApi
/**
* @param array $parameters {
*
* @var bool $archived limit by archived status
* @var string $visibility limit by visibility public, internal, or private
* @var string $order_by Return projects ordered by id, name, path, created_at, updated_at,
* last_activity_at, repository_size, storage_size, packages_size or
* wiki_size 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
* @var bool $starred limit by projects starred by the current user
* @var bool $statistics include project statistics
* @var bool $with_issues_enabled limit by enabled issues feature
* @var bool $with_merge_requests_enabled limit by enabled merge requests feature
* @var int $min_access_level Limit by current user minimal access level
* @var bool $archived limit by archived status
* @var string $visibility limit by visibility public, internal, or private
* @var string $order_by Return projects ordered by id, name, path, created_at, updated_at,
* last_activity_at, repository_size, storage_size, packages_size or
* wiki_size 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
* @var bool $starred limit by projects starred by the current user
* @var bool $statistics include project statistics
* @var bool $with_issues_enabled limit by enabled issues feature
* @var bool $with_merge_requests_enabled limit by enabled merge requests feature
* @var int $min_access_level Limit by current user minimal access level
* @var int $id_after Limit by project id's greater than the specified id
* @var int $id_before Limit by project id's less than the specified id
* @var \DateTimeInterface $last_activity_after Limit by last_activity after specified time
* @var \DateTimeInterface $last_activity_before Limit by last_activity before specified time
* @var bool $repository_checksum_failed Limit by failed repository checksum calculation
* @var string $repository_storage Limit by repository storage type
* @var bool $wiki_checksum_failed Limit by failed wiki checksum calculation
* @var bool $with_custom_attributes Include custom attributes in response
* @var string $with_programming_language Limit by programming language
* }
*
* @throws UndefinedOptionsException If an option name is undefined
Expand All @@ -54,6 +63,9 @@ public function all(array $parameters = [])
$booleanNormalizer = function (Options $resolver, $value): string {
return $value ? 'true' : 'false';
};
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
return $value->format('c');
};
$resolver->setDefined('archived')
->setAllowedTypes('archived', 'bool')
->setNormalizer('archived', $booleanNormalizer)
Expand Down Expand Up @@ -107,6 +119,34 @@ public function all(array $parameters = [])
$resolver->setDefined('min_access_level')
->setAllowedValues('min_access_level', [null, 10, 20, 30, 40, 50])
;
$resolver->setDefined('id_after')
->setAllowedTypes('id_after', 'integer')
;
$resolver->setDefined('id_before')
->setAllowedTypes('id_before', 'integer')
;
$resolver->setDefined('last_activity_after')
->setAllowedTypes('last_activity_after', \DateTimeInterface::class)
->setNormalizer('last_activity_after', $datetimeNormalizer)
;
$resolver->setDefined('last_activity_before')
->setAllowedTypes('last_activity_before', \DateTimeInterface::class)
->setNormalizer('last_activity_before', $datetimeNormalizer)
;
$resolver->setDefined('repository_checksum_failed')
->setAllowedTypes('repository_checksum_failed', 'bool')
->setNormalizer('repository_checksum_failed', $booleanNormalizer)
;
$resolver->setDefined('repository_storage');
$resolver->setDefined('wiki_checksum_failed')
->setAllowedTypes('wiki_checksum_failed', 'bool')
->setNormalizer('wiki_checksum_failed', $booleanNormalizer)
;
$resolver->setDefined('with_custom_attributes')
->setAllowedTypes('with_custom_attributes', 'bool')
->setNormalizer('with_custom_attributes', $booleanNormalizer)
;
$resolver->setDefined('with_programming_language');

return $this->get('projects', $resolver->resolve($parameters));
}
Expand Down
113 changes: 113 additions & 0 deletions tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Gitlab\Tests\Api;

use DateTime;
use Gitlab\Api\Projects;

class ProjectsTest extends TestCase
Expand Down Expand Up @@ -136,6 +137,118 @@ public function shouldSearchProjectsWithNamespace(): void
$this->assertEquals($expectedArray, $api->all(['search' => 'a_project', 'search_namespaces' => true]));
}

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

$api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, ['id_after' => 0]);

$this->assertEquals($expectedArray, $api->all(['id_after' => 0]));
}

/**
* @test
*/
public function shouldGetProjectsWithLastActivityAfter(): void
{
$unixEpochDateTime = new DateTime('@0');

$expectedArray = $this->getMultipleProjectsData();

$api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, ['last_activity_after' => $unixEpochDateTime->format('c')]);

$this->assertEquals($expectedArray, $api->all(['last_activity_after' => $unixEpochDateTime]));
}

/**
* @test
*/
public function shouldGetProjectsWithLastActivityBefore(): void
{
$now = new DateTime();

$expectedArray = $this->getMultipleProjectsData();

$api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, ['last_activity_before' => $now->format('c')]);

$this->assertEquals($expectedArray, $api->all(['last_activity_before' => $now]));
}

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

$api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, ['repository_checksum_failed' => 'false']);

$this->assertEquals($expectedArray, $api->all(['repository_checksum_failed' => false]));
}

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

$api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, ['repository_storage' => 'default']);

$this->assertEquals($expectedArray, $api->all(['repository_storage' => 'default']));
}

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

$api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, ['starred' => 'true']);

$this->assertEquals($expectedArray, $api->all(['starred' => true]));
}

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

$api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, ['wiki_checksum_failed' => 'false']);

$this->assertEquals($expectedArray, $api->all(['wiki_checksum_failed' => false]));
}

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

$api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, ['with_custom_attributes' => 'true']);

$this->assertEquals($expectedArray, $api->all(['with_custom_attributes' => true]));
}

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

$api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, ['with_programming_language' => 'php']);

$this->assertEquals($expectedArray, $api->all(['with_programming_language' => 'php']));
}

/**
* @test
*/
Expand Down