diff --git a/CHANGELOG.md b/CHANGELOG.md index 66e7f104..8f59ee3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Add support for `without_project_bots` in `Users::all` * Add support for date filters and `finished_at` ordering in `Deployments::all` * Add support for listing merge requests associated with a deployment +* Add support for `with_custom_attributes` and `with_projects` in `Groups::show` ## [12.0.0] - 2025-02-23 diff --git a/src/Api/Groups.php b/src/Api/Groups.php index f592422d..5248e36e 100644 --- a/src/Api/Groups.php +++ b/src/Api/Groups.php @@ -68,9 +68,30 @@ public function all(array $parameters = []): mixed return $this->get('groups', $resolver->resolve($parameters)); } - public function show(int|string $id): mixed + /** + * @param array $parameters { + * + * @var bool $with_custom_attributes include custom attributes in response + * @var bool $with_projects Include details from projects that belong to the group. + * } + */ + public function show(int|string $id, array $parameters = []): mixed { - return $this->get('groups/'.self::encodePath($id)); + $resolver = $this->createOptionsResolver(); + $booleanNormalizer = function (Options $resolver, $value): string { + return $value ? 'true' : 'false'; + }; + + $resolver->setDefined('with_custom_attributes') + ->setAllowedTypes('with_custom_attributes', 'bool') + ->setNormalizer('with_custom_attributes', $booleanNormalizer) + ; + $resolver->setDefined('with_projects') + ->setAllowedTypes('with_projects', 'bool') + ->setNormalizer('with_projects', $booleanNormalizer) + ; + + return $this->get('groups/'.self::encodePath($id), $resolver->resolve($parameters)); } public function create(string $name, string $path, ?string $description = null, string $visibility = 'private', ?bool $lfs_enabled = null, ?bool $request_access_enabled = null, ?int $parent_id = null, ?int $shared_runners_minutes_limit = null): mixed diff --git a/tests/Api/GroupsTest.php b/tests/Api/GroupsTest.php index 05a54e03..3bd2c7df 100644 --- a/tests/Api/GroupsTest.php +++ b/tests/Api/GroupsTest.php @@ -143,6 +143,22 @@ public function shouldShowGroup(): void $this->assertEquals($expectedArray, $api->show(1)); } + #[Test] + public function shouldShowGroupWithAdditionalParameters(): void + { + $expectedArray = ['id' => 1, 'name' => 'A group']; + $parameters = ['with_custom_attributes' => true, 'with_projects' => false]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('groups/1', ['with_custom_attributes' => 'true', 'with_projects' => 'false']) + ->willReturn($expectedArray) + ; + + $this->assertEquals($expectedArray, $api->show(1, $parameters)); + } + #[Test] public function shouldCreateGroup(): void {