Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add support for project CI/CD job token scope endpoints
* Add support for merge request resource label event endpoints
* Add support for `Environments::stopStale`
* Add support for `last_activity_after` and `last_activity_before` in `Groups::projects`
* Fix `Projects::pipelines` date filters to include time information


## [12.0.0] - 2025-02-23
Expand Down
41 changes: 27 additions & 14 deletions src/Api/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,22 @@ public function removeMember(int|string $group_id, int $user_id): mixed
/**
* @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, 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 authorized projects matching the 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 $starred limit by projects starred by the current user
* @var bool $with_issues_enabled Limit by projects with issues feature enabled (default is false)
* @var bool $with_merge_requests_enabled Limit by projects with merge requests feature enabled (default is false)
* @var bool $with_shared Include projects shared to this group (default is true)
* @var bool $include_subgroups Include projects in subgroups of this group (default is false)
* @var bool $with_custom_attributes Include custom attributes in response (admins only).
* @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, 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 authorized projects matching the 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 $starred limit by projects starred by the current user
* @var bool $with_issues_enabled Limit by projects with issues feature enabled (default is false)
* @var bool $with_merge_requests_enabled Limit by projects with merge requests feature enabled (default is false)
* @var bool $with_shared Include projects shared to this group (default is true)
* @var bool $include_subgroups Include projects in subgroups of this group (default is false)
* @var bool $with_custom_attributes include custom attributes in response (admins only)
* @var \DateTimeInterface $last_activity_after Limit by last_activity after specified time
* @var \DateTimeInterface $last_activity_before Limit by last_activity before specified time
* }
*/
public function projects(int|string $id, array $parameters = []): mixed
Expand All @@ -258,6 +260,9 @@ public function projects(int|string $id, array $parameters = []): mixed
$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')
Expand Down Expand Up @@ -305,6 +310,14 @@ public function projects(int|string $id, array $parameters = []): mixed
->setAllowedTypes('with_custom_attributes', 'bool')
->setNormalizer('with_custom_attributes', $booleanNormalizer)
;
$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)
;

return $this->get('groups/'.self::encodePath($id).'/projects', $resolver->resolve($parameters));
}
Expand Down
32 changes: 17 additions & 15 deletions src/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,18 @@ public function enableRunner(int $project_id, int $runner_id): mixed
/**
* @param array $parameters {
*
* @var string $scope the scope of pipelines, one of: running, pending, finished, branches, tags
* @var string $status the status of pipelines, one of: running, pending, success, failed, canceled, skipped
* @var string $ref the ref of pipelines
* @var string $sha the sha of pipelines
* @var bool $yaml_errors returns pipelines with invalid configurations
* @var string $name the name of the user who triggered pipelines
* @var string $username the username of the user who triggered pipelines
* @var string $order_by order pipelines by id, status, ref, updated_at, or user_id (default: id)
* @var string $order sort pipelines in asc or desc order (default: desc)
* @var string $source the source of the pipeline
* @var string $scope the scope of pipelines, one of: running, pending, finished, branches, tags
* @var string $status the status of pipelines, one of: running, pending, success, failed, canceled, skipped
* @var string $ref the ref of pipelines
* @var string $sha the sha of pipelines
* @var bool $yaml_errors returns pipelines with invalid configurations
* @var string $name the name of the user who triggered pipelines
* @var string $username the username of the user who triggered pipelines
* @var \DateTimeInterface $updated_after Return pipelines updated on or after the given date and time
* @var \DateTimeInterface $updated_before Return pipelines updated on or before the given date and time
* @var string $order_by order pipelines by id, status, ref, updated_at, or user_id (default: id)
* @var string $sort sort pipelines in asc or desc order (default: desc)
* @var string $source the source of the pipeline
* }
*/
public function pipelines(int|string $project_id, array $parameters = []): mixed
Expand All @@ -296,7 +298,7 @@ public function pipelines(int|string $project_id, array $parameters = []): mixed
return $value ? 'true' : 'false';
};
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value): string {
return $value->format('Y-m-d');
return $value->format('c');
};

$resolver->setDefined('scope')
Expand All @@ -314,12 +316,12 @@ public function pipelines(int|string $project_id, array $parameters = []): mixed
$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
40 changes: 40 additions & 0 deletions tests/Api/GroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,46 @@ public function shouldGetAllGroupProjectsIncludingCustomAttributes(): void
$this->assertEquals($expectedArray, $api->projects(1, ['with_custom_attributes' => true]));
}

#[Test]
public function shouldGetAllGroupProjectsWithLastActivityAfter(): void
{
$lastActivityAfter = new DateTime('2018-01-01 00:00:00');

$expectedArray = [
['id' => 1, 'name' => 'A project'],
['id' => 2, 'name' => 'Another project'],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('groups/1/projects', ['last_activity_after' => $lastActivityAfter->format('c')])
->willReturn($expectedArray)
;

$this->assertEquals($expectedArray, $api->projects(1, ['last_activity_after' => $lastActivityAfter]));
}

#[Test]
public function shouldGetAllGroupProjectsWithLastActivityBefore(): void
{
$lastActivityBefore = new DateTime('2018-01-31 00:00:00');

$expectedArray = [
['id' => 1, 'name' => 'A project'],
['id' => 2, 'name' => 'Another project'],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('groups/1/projects', ['last_activity_before' => $lastActivityBefore->format('c')])
->willReturn($expectedArray)
;

$this->assertEquals($expectedArray, $api->projects(1, ['last_activity_before' => $lastActivityBefore]));
}

#[Test]
public function shouldGetIterations(): void
{
Expand Down
12 changes: 6 additions & 6 deletions tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,12 +761,12 @@ public function shouldGetPipelineWithDateParam(): void
['id' => 3, 'status' => 'pending', 'ref' => 'test-pipeline'],
];

$updated_after = new DateTime('2018-01-01 00:00:00');
$updated_before = new DateTime('2018-01-31 00:00:00');
$updatedAfter = new DateTime('2018-01-01 00:00:00');
$updatedBefore = new DateTime('2018-01-31 00:00:00');

$expectedWithArray = [
'updated_after' => $updated_after->format('Y-m-d'),
'updated_before' => $updated_before->format('Y-m-d'),
'updated_after' => $updatedAfter->format('c'),
'updated_before' => $updatedBefore->format('c'),
];

$api = $this->getApiMock();
Expand All @@ -776,8 +776,8 @@ public function shouldGetPipelineWithDateParam(): void
->willReturn($expectedArray);

$this->assertEquals($expectedArray, $api->pipelines(1, [
'updated_after' => $updated_after,
'updated_before' => $updated_before,
'updated_after' => $updatedAfter,
'updated_before' => $updatedBefore,
]));
}

Expand Down