From d18e1d10fcd4f2768afcef81c011bcc29ce0c1e1 Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Thu, 11 Nov 2021 18:07:19 +0100 Subject: [PATCH 01/12] feat: add IssueLabelEvents api endpoing --- .gitignore | 3 +++ composer.json | 2 +- src/Api/IssueLabelEvents.php | 39 ++++++++++++++++++++++++++++++++++++ src/Client.php | 17 +++++++++++++--- 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/Api/IssueLabelEvents.php diff --git a/.gitignore b/.gitignore index 04626b2fe..e5fef0746 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ composer.lock phpstan.neon phpunit.xml vendor + +composer.phar +.idea/ diff --git a/composer.json b/composer.json index 839f4bb01..6948b5fde 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "m4tthumphrey/php-gitlab-api", + "name": "shellrent/php-gitlab-api", "description": "GitLab API v4 client for PHP", "keywords": ["gitlab", "api"], "license": "MIT", diff --git a/src/Api/IssueLabelEvents.php b/src/Api/IssueLabelEvents.php new file mode 100644 index 000000000..eda1b3289 --- /dev/null +++ b/src/Api/IssueLabelEvents.php @@ -0,0 +1,39 @@ +get($this->getProjectPath($project_id, $path)); + } + + + /** + * @param int|string $project_id + * @param int $issue_iid + * @param int $resource_label_event_id + * + * @return mixed + */ + public function show($project_id, int $issue_iid, int $resource_label_event_id) + { + $path = 'issues/'.self::encodePath($issue_iid).'/resource_label_events/'; + $path .= self::encodePath($resource_label_event_id); + + return $this->get($this->getProjectPath($project_id, $path)); + } +} \ No newline at end of file diff --git a/src/Client.php b/src/Client.php index 242b5b61d..4b61fe673 100644 --- a/src/Client.php +++ b/src/Client.php @@ -22,6 +22,7 @@ use Gitlab\Api\GroupsEpics; use Gitlab\Api\GroupsMilestones; use Gitlab\Api\IssueBoards; +use Gitlab\Api\IssueLabelEvents; use Gitlab\Api\IssueLinks; use Gitlab\Api\Issues; use Gitlab\Api\IssuesStatistics; @@ -116,9 +117,11 @@ public function __construct(Builder $httpClientBuilder = null) $builder->addPlugin(new ExceptionThrower()); $builder->addPlugin(new HistoryPlugin($this->responseHistory)); - $builder->addPlugin(new HeaderDefaultsPlugin([ - 'User-Agent' => self::USER_AGENT, - ])); + $builder->addPlugin( + new HeaderDefaultsPlugin([ + 'User-Agent' => self::USER_AGENT, + ]) + ); $builder->addPlugin(new RedirectPlugin()); $this->setUrl(self::BASE_URL); @@ -218,6 +221,14 @@ public function issues(): Issues return new Issues($this); } + /** + * @return IssueLabelEvents + */ + public function issuesLabelEvents(): IssueLabelEvents + { + return new IssueLabelEvents($this); + } + /** * @return IssuesStatistics */ From aec6b8e8d2736d815574fa6c2c1ed15b4d397e8e Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Fri, 12 Nov 2021 13:46:41 +0100 Subject: [PATCH 02/12] feat: add all resource events api endpoints --- ...abelEvents.php => ResourceLabelEvents.php} | 2 +- src/Api/ResourceStateEvents.php | 35 ++++++ src/Api/ResourceWeightEvents.php | 36 ++++++ src/Client.php | 25 +++- tests/Api/ResourceLabelEventsTest.php | 115 ++++++++++++++++++ tests/Api/ResourceStateEventsTest.php | 95 +++++++++++++++ tests/Api/ResourceWeightEventsTest.php | 91 ++++++++++++++ 7 files changed, 395 insertions(+), 4 deletions(-) rename src/Api/{IssueLabelEvents.php => ResourceLabelEvents.php} (95%) create mode 100644 src/Api/ResourceStateEvents.php create mode 100644 src/Api/ResourceWeightEvents.php create mode 100644 tests/Api/ResourceLabelEventsTest.php create mode 100644 tests/Api/ResourceStateEventsTest.php create mode 100644 tests/Api/ResourceWeightEventsTest.php diff --git a/src/Api/IssueLabelEvents.php b/src/Api/ResourceLabelEvents.php similarity index 95% rename from src/Api/IssueLabelEvents.php rename to src/Api/ResourceLabelEvents.php index eda1b3289..8d693fd97 100644 --- a/src/Api/IssueLabelEvents.php +++ b/src/Api/ResourceLabelEvents.php @@ -4,7 +4,7 @@ namespace Gitlab\Api; -class IssueLabelEvents extends AbstractApi +class ResourceLabelEvents extends AbstractApi { diff --git a/src/Api/ResourceStateEvents.php b/src/Api/ResourceStateEvents.php new file mode 100644 index 000000000..48cf1882d --- /dev/null +++ b/src/Api/ResourceStateEvents.php @@ -0,0 +1,35 @@ +get($this->getProjectPath($project_id, $path)); + } + + + /** + * @param int|string $project_id + * @param int $issue_iid + * @param int $resource_label_event_id + * + * @return mixed + */ + public function show($project_id, int $issue_iid, int $resource_label_event_id) + { + $path = 'issues/'.self::encodePath($issue_iid).'/resource_state_events/'; + $path .= self::encodePath($resource_label_event_id); + + return $this->get($this->getProjectPath($project_id, $path)); + } +} \ No newline at end of file diff --git a/src/Api/ResourceWeightEvents.php b/src/Api/ResourceWeightEvents.php new file mode 100644 index 000000000..b92c6b621 --- /dev/null +++ b/src/Api/ResourceWeightEvents.php @@ -0,0 +1,36 @@ +get($this->getProjectPath($project_id, $path)); + } + + + /** + * @param int|string $project_id + * @param int $issue_iid + * @param int $resource_label_event_id + * + * @return mixed + */ + public function show($project_id, int $issue_iid, int $resource_label_event_id) + { + $path = 'issues/'.self::encodePath($issue_iid).'/resource_weight_events/'; + $path .= self::encodePath($resource_label_event_id); + + return $this->get($this->getProjectPath($project_id, $path)); + } + +} \ No newline at end of file diff --git a/src/Client.php b/src/Client.php index 4b61fe673..3123c6be0 100644 --- a/src/Client.php +++ b/src/Client.php @@ -34,6 +34,9 @@ use Gitlab\Api\Projects; use Gitlab\Api\Repositories; use Gitlab\Api\RepositoryFiles; +use Gitlab\Api\ResourceLabelEvents; +use Gitlab\Api\ResourceStateEvents; +use Gitlab\Api\ResourceWeightEvents; use Gitlab\Api\Schedules; use Gitlab\Api\Snippets; use Gitlab\Api\SystemHooks; @@ -222,11 +225,27 @@ public function issues(): Issues } /** - * @return IssueLabelEvents + * @return ResourceLabelEvents */ - public function issuesLabelEvents(): IssueLabelEvents + public function resourceLableEvents(): ResourceLabelEvents { - return new IssueLabelEvents($this); + return new ResourceLabelEvents($this); + } + + /** + * @return ResourceStateEvents + */ + public function resourceStateEvents(): ResourceStateEvents + { + return new ResourceStateEvents($this); + } + + /** + * @return ResourceWeightEvents + */ + public function resourceWeightEvents(): ResourceWeightEvents + { + return new ResourceWeightEvents($this); } /** diff --git a/tests/Api/ResourceLabelEventsTest.php b/tests/Api/ResourceLabelEventsTest.php new file mode 100644 index 000000000..698deb8bd --- /dev/null +++ b/tests/Api/ResourceLabelEventsTest.php @@ -0,0 +1,115 @@ + 142, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', + ], + 'created_at' => '2018-08-20T13=>38=>20.077Z', + 'resource_type' => 'Issue', + 'resource_id' => 253, + 'label' => [ + 'id' => 73, + 'name' => 'a1', + 'color' => '#34495E', + 'description' => '', + ], + 'action' => 'add', + ], + [ + 'id' => 143, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', + ], + 'created_at' => '2018-08-20T13=>38=>20.077Z', + 'resource_type' => 'Issue', + 'resource_id' => 253, + 'label' => [ + 'id' => 74, + 'name' => 'p1', + 'color' => '#0033CC', + 'description' => '', + ], + 'action' => 'remove', + ], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/projects/1/issues/253/resource_label_events', []) + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->all(1, 253)); + } + + + /** + * @test + */ + public function shouldShowEvent(): void + { + $expectedArray = [ + 'id' => 142, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', + ], + 'created_at' => '2018-08-20T13=>38=>20.077Z', + 'resource_type' => 'Issue', + 'resource_id' => 253, + 'label' => [ + 'id' => 73, + 'name' => 'a1', + 'color' => '#34495E', + 'description' => '', + ], + 'action' => 'add', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/projects/1/issues/253/resource_label_events/142', []) + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->show(1, 253, 142)); + } + + /** + * @return string + */ + protected function getApiClass(): string + { + return ResourceLabelEvents::class; + } +} diff --git a/tests/Api/ResourceStateEventsTest.php b/tests/Api/ResourceStateEventsTest.php new file mode 100644 index 000000000..fb9da0b0b --- /dev/null +++ b/tests/Api/ResourceStateEventsTest.php @@ -0,0 +1,95 @@ + 142, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', + ], + 'created_at' => '2018-08-20T13=>38=>20.077Z', + 'resource_type' => 'Issue', + 'resource_id' => 11, + 'state' => 'opened', + ], + [ + 'id' => 143, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', + ], + 'created_at' => '2018-08-21T14=>38=>20.077Z', + 'resource_type' => 'Issue', + 'resource_id' => 11, + 'state' => 'closed', + ], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/projects/1/issues/11/resource_state_events', []) + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->all(1, 11)); + } + + + /** + * @test + */ + public function shouldShowEvent(): void + { + $expectedArray = [ + 'id' => 142, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', + ], + 'created_at' => '2018-08-20T13=>38=>20.077Z', + 'resource_type' => 'Issue', + 'resource_id' => 11, + 'state' => 'opened', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/projects/1/issues/11/resource_state_events/142', []) + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->show(1, 11, 142)); + } + + /** + * @return string + */ + protected function getApiClass(): string + { + return ResourceStateEvents::class; + } + +} diff --git a/tests/Api/ResourceWeightEventsTest.php b/tests/Api/ResourceWeightEventsTest.php new file mode 100644 index 000000000..c605a67ff --- /dev/null +++ b/tests/Api/ResourceWeightEventsTest.php @@ -0,0 +1,91 @@ + 142, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', + ], + 'created_at' => '2018-08-20T13=>38=>20.077Z', + 'issue_id' => 253, + 'weight' => 3, + ], + [ + 'id' => 143, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', + ], + 'created_at' => '2018-08-21T14=>38=>20.077Z', + 'issue_id' => 253, + 'weight' => 2, + ], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/projects/1/issues/253/resource_weight_events', []) + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->all(1, 253)); + } + + + /** + * @test + */ + public function shouldShowEvent(): void + { + $expectedArray = [ + 'id' => 142, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', + ], + 'created_at' => '2018-08-20T13=>38=>20.077Z', + 'issue_id' => 253, + 'weight' => 3, + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/projects/1/issues/253/resource_state_events/142', []) + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->show(1, 253, 142)); + } + + /** + * @return string + */ + protected function getApiClass(): string + { + return ResourceWeightEvents::class; + } +} From b36e8dbbbd67dc40f442ab7cf519885abb06947c Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Fri, 12 Nov 2021 13:51:30 +0100 Subject: [PATCH 03/12] fix: add missing define strict types --- src/Api/ResourceStateEvents.php | 2 ++ src/Api/ResourceWeightEvents.php | 2 ++ tests/Api/ResourceStateEventsTest.php | 2 ++ tests/Api/ResourceWeightEventsTest.php | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/Api/ResourceStateEvents.php b/src/Api/ResourceStateEvents.php index 48cf1882d..e142abee7 100644 --- a/src/Api/ResourceStateEvents.php +++ b/src/Api/ResourceStateEvents.php @@ -1,5 +1,7 @@ Date: Fri, 12 Nov 2021 13:55:11 +0100 Subject: [PATCH 04/12] fix: remove leading slash in test paths --- tests/Api/ResourceLabelEventsTest.php | 4 ++-- tests/Api/ResourceStateEventsTest.php | 4 ++-- tests/Api/ResourceWeightEventsTest.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Api/ResourceLabelEventsTest.php b/tests/Api/ResourceLabelEventsTest.php index 698deb8bd..08c37bdf8 100644 --- a/tests/Api/ResourceLabelEventsTest.php +++ b/tests/Api/ResourceLabelEventsTest.php @@ -62,7 +62,7 @@ public function shouldGetAllEvents(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/projects/1/issues/253/resource_label_events', []) + ->with('projects/1/issues/253/resource_label_events', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->all(1, 253)); @@ -99,7 +99,7 @@ public function shouldShowEvent(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/projects/1/issues/253/resource_label_events/142', []) + ->with('projects/1/issues/253/resource_label_events/142', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->show(1, 253, 142)); diff --git a/tests/Api/ResourceStateEventsTest.php b/tests/Api/ResourceStateEventsTest.php index ac9f12990..9d46fa811 100644 --- a/tests/Api/ResourceStateEventsTest.php +++ b/tests/Api/ResourceStateEventsTest.php @@ -49,7 +49,7 @@ public function shouldGetAllEvents(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/projects/1/issues/11/resource_state_events', []) + ->with('projects/1/issues/11/resource_state_events', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->all(1, 11)); @@ -80,7 +80,7 @@ public function shouldShowEvent(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/projects/1/issues/11/resource_state_events/142', []) + ->with('projects/1/issues/11/resource_state_events/142', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->show(1, 11, 142)); diff --git a/tests/Api/ResourceWeightEventsTest.php b/tests/Api/ResourceWeightEventsTest.php index 7f29a7592..683b461d5 100644 --- a/tests/Api/ResourceWeightEventsTest.php +++ b/tests/Api/ResourceWeightEventsTest.php @@ -47,7 +47,7 @@ public function shouldGetAllEvents(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/projects/1/issues/253/resource_weight_events', []) + ->with('projects/1/issues/253/resource_weight_events', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->all(1, 253)); @@ -77,7 +77,7 @@ public function shouldShowEvent(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/projects/1/issues/253/resource_state_events/142', []) + ->with('projects/1/issues/253/resource_state_events/142', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->show(1, 253, 142)); From e9ac8457d1213ee38bc2e65eb64ffd0919b85882 Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Fri, 12 Nov 2021 13:55:11 +0100 Subject: [PATCH 05/12] fix: remove leading slash in test paths --- composer.json | 2 +- tests/Api/ResourceLabelEventsTest.php | 4 ++-- tests/Api/ResourceStateEventsTest.php | 4 ++-- tests/Api/ResourceWeightEventsTest.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 6948b5fde..839f4bb01 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "shellrent/php-gitlab-api", + "name": "m4tthumphrey/php-gitlab-api", "description": "GitLab API v4 client for PHP", "keywords": ["gitlab", "api"], "license": "MIT", diff --git a/tests/Api/ResourceLabelEventsTest.php b/tests/Api/ResourceLabelEventsTest.php index 698deb8bd..08c37bdf8 100644 --- a/tests/Api/ResourceLabelEventsTest.php +++ b/tests/Api/ResourceLabelEventsTest.php @@ -62,7 +62,7 @@ public function shouldGetAllEvents(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/projects/1/issues/253/resource_label_events', []) + ->with('projects/1/issues/253/resource_label_events', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->all(1, 253)); @@ -99,7 +99,7 @@ public function shouldShowEvent(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/projects/1/issues/253/resource_label_events/142', []) + ->with('projects/1/issues/253/resource_label_events/142', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->show(1, 253, 142)); diff --git a/tests/Api/ResourceStateEventsTest.php b/tests/Api/ResourceStateEventsTest.php index ac9f12990..9d46fa811 100644 --- a/tests/Api/ResourceStateEventsTest.php +++ b/tests/Api/ResourceStateEventsTest.php @@ -49,7 +49,7 @@ public function shouldGetAllEvents(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/projects/1/issues/11/resource_state_events', []) + ->with('projects/1/issues/11/resource_state_events', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->all(1, 11)); @@ -80,7 +80,7 @@ public function shouldShowEvent(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/projects/1/issues/11/resource_state_events/142', []) + ->with('projects/1/issues/11/resource_state_events/142', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->show(1, 11, 142)); diff --git a/tests/Api/ResourceWeightEventsTest.php b/tests/Api/ResourceWeightEventsTest.php index 7f29a7592..683b461d5 100644 --- a/tests/Api/ResourceWeightEventsTest.php +++ b/tests/Api/ResourceWeightEventsTest.php @@ -47,7 +47,7 @@ public function shouldGetAllEvents(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/projects/1/issues/253/resource_weight_events', []) + ->with('projects/1/issues/253/resource_weight_events', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->all(1, 253)); @@ -77,7 +77,7 @@ public function shouldShowEvent(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/projects/1/issues/253/resource_state_events/142', []) + ->with('projects/1/issues/253/resource_state_events/142', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->show(1, 253, 142)); From 467e68f03868fca364b5d65117c0aed8248f41ba Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Fri, 12 Nov 2021 14:28:55 +0100 Subject: [PATCH 06/12] refactor: apply styleci patch --- src/Api/ResourceLabelEvents.php | 5 +---- src/Api/ResourceStateEvents.php | 3 +-- src/Api/ResourceWeightEvents.php | 4 +--- src/Client.php | 1 - tests/Api/ResourceLabelEventsTest.php | 2 -- tests/Api/ResourceStateEventsTest.php | 2 -- tests/Api/ResourceWeightEventsTest.php | 1 - 7 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/Api/ResourceLabelEvents.php b/src/Api/ResourceLabelEvents.php index 8d693fd97..767d1a5f1 100644 --- a/src/Api/ResourceLabelEvents.php +++ b/src/Api/ResourceLabelEvents.php @@ -6,8 +6,6 @@ class ResourceLabelEvents extends AbstractApi { - - /** * @param int|string $project_id * @param int $issue_iid @@ -21,7 +19,6 @@ public function all($project_id, int $issue_iid) return $this->get($this->getProjectPath($project_id, $path)); } - /** * @param int|string $project_id * @param int $issue_iid @@ -36,4 +33,4 @@ public function show($project_id, int $issue_iid, int $resource_label_event_id) return $this->get($this->getProjectPath($project_id, $path)); } -} \ No newline at end of file +} diff --git a/src/Api/ResourceStateEvents.php b/src/Api/ResourceStateEvents.php index e142abee7..022f2c02a 100644 --- a/src/Api/ResourceStateEvents.php +++ b/src/Api/ResourceStateEvents.php @@ -19,7 +19,6 @@ public function all($project_id, int $issue_iid) return $this->get($this->getProjectPath($project_id, $path)); } - /** * @param int|string $project_id * @param int $issue_iid @@ -34,4 +33,4 @@ public function show($project_id, int $issue_iid, int $resource_label_event_id) return $this->get($this->getProjectPath($project_id, $path)); } -} \ No newline at end of file +} diff --git a/src/Api/ResourceWeightEvents.php b/src/Api/ResourceWeightEvents.php index 5bfab1f1b..dc1a22637 100644 --- a/src/Api/ResourceWeightEvents.php +++ b/src/Api/ResourceWeightEvents.php @@ -19,7 +19,6 @@ public function all($project_id, int $issue_iid) return $this->get($this->getProjectPath($project_id, $path)); } - /** * @param int|string $project_id * @param int $issue_iid @@ -34,5 +33,4 @@ public function show($project_id, int $issue_iid, int $resource_label_event_id) return $this->get($this->getProjectPath($project_id, $path)); } - -} \ No newline at end of file +} diff --git a/src/Client.php b/src/Client.php index 3123c6be0..bc50a4864 100644 --- a/src/Client.php +++ b/src/Client.php @@ -22,7 +22,6 @@ use Gitlab\Api\GroupsEpics; use Gitlab\Api\GroupsMilestones; use Gitlab\Api\IssueBoards; -use Gitlab\Api\IssueLabelEvents; use Gitlab\Api\IssueLinks; use Gitlab\Api\Issues; use Gitlab\Api\IssuesStatistics; diff --git a/tests/Api/ResourceLabelEventsTest.php b/tests/Api/ResourceLabelEventsTest.php index 08c37bdf8..07cc4e55c 100644 --- a/tests/Api/ResourceLabelEventsTest.php +++ b/tests/Api/ResourceLabelEventsTest.php @@ -4,7 +4,6 @@ namespace Gitlab\Tests\Api; - use Gitlab\Api\ResourceLabelEvents; class ResourceLabelEventsTest extends TestCase @@ -68,7 +67,6 @@ public function shouldGetAllEvents(): void $this->assertEquals($expectedArray, $api->all(1, 253)); } - /** * @test */ diff --git a/tests/Api/ResourceStateEventsTest.php b/tests/Api/ResourceStateEventsTest.php index 9d46fa811..3b7ced7eb 100644 --- a/tests/Api/ResourceStateEventsTest.php +++ b/tests/Api/ResourceStateEventsTest.php @@ -55,7 +55,6 @@ public function shouldGetAllEvents(): void $this->assertEquals($expectedArray, $api->all(1, 11)); } - /** * @test */ @@ -93,5 +92,4 @@ protected function getApiClass(): string { return ResourceStateEvents::class; } - } diff --git a/tests/Api/ResourceWeightEventsTest.php b/tests/Api/ResourceWeightEventsTest.php index 683b461d5..4b9160fc0 100644 --- a/tests/Api/ResourceWeightEventsTest.php +++ b/tests/Api/ResourceWeightEventsTest.php @@ -53,7 +53,6 @@ public function shouldGetAllEvents(): void $this->assertEquals($expectedArray, $api->all(1, 253)); } - /** * @test */ From a684c79468ea813f50aa613c300ad8c91c577f5d Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Mon, 15 Nov 2021 10:07:10 +0100 Subject: [PATCH 07/12] fix: typo and wrong test url --- src/Client.php | 48 +++++++++++++------------- tests/Api/ResourceWeightEventsTest.php | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Client.php b/src/Client.php index 3123c6be0..12b157e15 100644 --- a/src/Client.php +++ b/src/Client.php @@ -130,6 +130,29 @@ public function __construct(Builder $httpClientBuilder = null) $this->setUrl(self::BASE_URL); } + /** + * @param string $url + * + * @return void + */ + public function setUrl(string $url): void + { + $uri = $this->getHttpClientBuilder()->getUriFactory()->createUri($url); + + $this->getHttpClientBuilder()->removePlugin(AddHostPlugin::class); + $this->getHttpClientBuilder()->addPlugin(new AddHostPlugin($uri)); + } + + /** + * Get the HTTP client builder. + * + * @return Builder + */ + protected function getHttpClientBuilder(): Builder + { + return $this->httpClientBuilder; + } + /** * Create a Gitlab\Client using an HTTP client. * @@ -227,7 +250,7 @@ public function issues(): Issues /** * @return ResourceLabelEvents */ - public function resourceLableEvents(): ResourceLabelEvents + public function resourceLabelEvents(): ResourceLabelEvents { return new ResourceLabelEvents($this); } @@ -391,19 +414,6 @@ public function authenticate(string $token, string $authMethod, string $sudo = n $this->getHttpClientBuilder()->addPlugin(new Authentication($authMethod, $token, $sudo)); } - /** - * @param string $url - * - * @return void - */ - public function setUrl(string $url): void - { - $uri = $this->getHttpClientBuilder()->getUriFactory()->createUri($url); - - $this->getHttpClientBuilder()->removePlugin(AddHostPlugin::class); - $this->getHttpClientBuilder()->addPlugin(new AddHostPlugin($uri)); - } - /** * Get the last response. * @@ -433,14 +443,4 @@ public function getStreamFactory(): StreamFactoryInterface { return $this->getHttpClientBuilder()->getStreamFactory(); } - - /** - * Get the HTTP client builder. - * - * @return Builder - */ - protected function getHttpClientBuilder(): Builder - { - return $this->httpClientBuilder; - } } diff --git a/tests/Api/ResourceWeightEventsTest.php b/tests/Api/ResourceWeightEventsTest.php index 683b461d5..3b9bfa5c1 100644 --- a/tests/Api/ResourceWeightEventsTest.php +++ b/tests/Api/ResourceWeightEventsTest.php @@ -77,7 +77,7 @@ public function shouldShowEvent(): void $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('projects/1/issues/253/resource_state_events/142', []) + ->with('projects/1/issues/253/resource_weight_events/142', []) ->willReturn($expectedArray); $this->assertEquals($expectedArray, $api->show(1, 253, 142)); From bb816e682082fd141e150d8cfe697166451b0ef6 Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Thu, 18 Nov 2021 17:36:28 +0100 Subject: [PATCH 08/12] feat: add iteration and milestone APIs --- src/Api/ResourceIterationEvents.php | 39 +++++++ src/Api/ResourceMilestoneEvents.php | 39 +++++++ src/Client.php | 18 +++ tests/Api/ResourceIterationEventsTest.php | 133 +++++++++++++++++++++ tests/Api/ResourceMilestoneEventsTest.php | 136 ++++++++++++++++++++++ 5 files changed, 365 insertions(+) create mode 100644 src/Api/ResourceIterationEvents.php create mode 100644 src/Api/ResourceMilestoneEvents.php create mode 100644 tests/Api/ResourceIterationEventsTest.php create mode 100644 tests/Api/ResourceMilestoneEventsTest.php diff --git a/src/Api/ResourceIterationEvents.php b/src/Api/ResourceIterationEvents.php new file mode 100644 index 000000000..1dcb9edc0 --- /dev/null +++ b/src/Api/ResourceIterationEvents.php @@ -0,0 +1,39 @@ +get($this->getProjectPath($project_id, $path)); + } + + + /** + * @param int|string $project_id + * @param int $issue_iid + * @param int $resource_iteration_event_id + * + * @return mixed + */ + public function show($project_id, int $issue_iid, int $resource_iteration_event_id) + { + $path = 'issues/'.self::encodePath($issue_iid).'/resource_iteration_events/'; + $path .= self::encodePath($resource_iteration_event_id); + + return $this->get($this->getProjectPath($project_id, $path)); + } +} \ No newline at end of file diff --git a/src/Api/ResourceMilestoneEvents.php b/src/Api/ResourceMilestoneEvents.php new file mode 100644 index 000000000..b535b67ef --- /dev/null +++ b/src/Api/ResourceMilestoneEvents.php @@ -0,0 +1,39 @@ +get($this->getProjectPath($project_id, $path)); + } + + + /** + * @param int|string $project_id + * @param int $issue_iid + * @param int $resource_milestone_event_id + * + * @return mixed + */ + public function show($project_id, int $issue_iid, int $resource_milestone_event_id) + { + $path = 'issues/'.self::encodePath($issue_iid).'/resource_milestone_events/'; + $path .= self::encodePath($resource_milestone_event_id); + + return $this->get($this->getProjectPath($project_id, $path)); + } +} \ No newline at end of file diff --git a/src/Client.php b/src/Client.php index 12b157e15..44845e55a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -34,7 +34,9 @@ use Gitlab\Api\Projects; use Gitlab\Api\Repositories; use Gitlab\Api\RepositoryFiles; +use Gitlab\Api\ResourceIterationEvents; use Gitlab\Api\ResourceLabelEvents; +use Gitlab\Api\ResourceMilestoneEvents; use Gitlab\Api\ResourceStateEvents; use Gitlab\Api\ResourceWeightEvents; use Gitlab\Api\Schedules; @@ -247,6 +249,14 @@ public function issues(): Issues return new Issues($this); } + /** + * @return ResourceIterationEvents + */ + public function resourceIterationEvents(): ResourceIterationEvents + { + return new ResourceIterationEvents($this); + } + /** * @return ResourceLabelEvents */ @@ -255,6 +265,14 @@ public function resourceLabelEvents(): ResourceLabelEvents return new ResourceLabelEvents($this); } + /** + * @return ResourceMilestoneEvents + */ + public function resourceMilestoneEvents(): ResourceMilestoneEvents + { + return new ResourceMilestoneEvents($this); + } + /** * @return ResourceStateEvents */ diff --git a/tests/Api/ResourceIterationEventsTest.php b/tests/Api/ResourceIterationEventsTest.php new file mode 100644 index 000000000..abe8818f5 --- /dev/null +++ b/tests/Api/ResourceIterationEventsTest.php @@ -0,0 +1,133 @@ + 142, + "user" => [ + "id" => 1, + "name" => "Administrator", + "username" => "root", + "state" => "active", + "avatar_url" => "https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url" => "http=>//gitlab.example.com/root", + ], + "created_at" => "2018-08-20T13=>38=>20.077Z", + "resource_type" => "Issue", + "resource_id" => 253, + "iteration" => [ + "id" => 50, + "iid" => 9, + "group_id" => 5, + "title" => "Iteration I", + "description" => "Ipsum Lorem", + "state" => 1, + "created_at" => "2020-01-27T05=>07=>12.573Z", + "updated_at" => "2020-01-27T05=>07=>12.573Z", + "due_date" => null, + "start_date" => null, + ], + "action" => "add", + ], + [ + "id" => 143, + "user" => [ + "id" => 1, + "name" => "Administrator", + "username" => "root", + "state" => "active", + "avatar_url" => "https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url" => "http=>//gitlab.example.com/root", + ], + "created_at" => "2018-08-21T14=>38=>20.077Z", + "resource_type" => "Issue", + "resource_id" => 253, + "iteration" => [ + "id" => 53, + "iid" => 13, + "group_id" => 5, + "title" => "Iteration II", + "description" => "Ipsum Lorem ipsum", + "state" => 2, + "created_at" => "2020-01-27T05=>07=>12.573Z", + "updated_at" => "2020-01-27T05=>07=>12.573Z", + "due_date" => null, + "start_date" => null, + ], + "action" => "remove", + ], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/issues/253/resource_iteration_events', []) + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->all(1, 253)); + } + + + /** + * @test + */ + public function shouldShowEvent(): void + { + $expectedArray = [ + "id" => 142, + "user" => [ + "id" => 1, + "name" => "Administrator", + "username" => "root", + "state" => "active", + "avatar_url" => "https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url" => "http=>//gitlab.example.com/root", + ], + "created_at" => "2018-08-20T13=>38=>20.077Z", + "resource_type" => "Issue", + "resource_id" => 253, + "iteration" => [ + "id" => 50, + "iid" => 9, + "group_id" => 5, + "title" => "Iteration I", + "description" => "Ipsum Lorem", + "state" => 1, + "created_at" => "2020-01-27T05=>07=>12.573Z", + "updated_at" => "2020-01-27T05=>07=>12.573Z", + "due_date" => null, + "start_date" => null, + ], + "action" => "add", + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/issues/253/resource_iteration_events/142', []) + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->show(1, 253, 142)); + } + + /** + * @return string + */ + protected function getApiClass(): string + { + return ResourceIterationEvents::class; + } +} diff --git a/tests/Api/ResourceMilestoneEventsTest.php b/tests/Api/ResourceMilestoneEventsTest.php new file mode 100644 index 000000000..480ab7539 --- /dev/null +++ b/tests/Api/ResourceMilestoneEventsTest.php @@ -0,0 +1,136 @@ + 142, + "user" => [ + "id" => 1, + "name" => "Administrator", + "username" => "root", + "state" => "active", + "avatar_url" => "https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url" => "http=>//gitlab.example.com/root", + ], + "created_at" => "2018-08-20T13=>38=>20.077Z", + "resource_type" => "Issue", + "resource_id" => 253, + "milestone" => [ + "id" => 61, + "iid" => 9, + "project_id" => 7, + "title" => "v1.2", + "description" => "Ipsum Lorem", + "state" => "active", + "created_at" => "2020-01-27T05=>07=>12.573Z", + "updated_at" => "2020-01-27T05=>07=>12.573Z", + "due_date" => null, + "start_date" => null, + "web_url" => "http=>//gitlab.example.com=>3000/group/project/-/milestones/9", + ], + "action" => "add", + ], + [ + "id" => 143, + "user" => [ + "id" => 1, + "name" => "Administrator", + "username" => "root", + "state" => "active", + "avatar_url" => "https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url" => "http=>//gitlab.example.com/root", + ], + "created_at" => "2018-08-21T14=>38=>20.077Z", + "resource_type" => "Issue", + "resource_id" => 253, + "milestone" => [ + "id" => 61, + "iid" => 9, + "project_id" => 7, + "title" => "v1.2", + "description" => "Ipsum Lorem", + "state" => "active", + "created_at" => "2020-01-27T05=>07=>12.573Z", + "updated_at" => "2020-01-27T05=>07=>12.573Z", + "due_date" => null, + "start_date" => null, + "web_url" => "http=>//gitlab.example.com=>3000/group/project/-/milestones/9", + ], + "action" => "remove", + ], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/issues/253/resource_milestone_events', []) + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->all(1, 253)); + } + + + /** + * @test + */ + public function shouldShowEvent(): void + { + $expectedArray = [ + "id" => 142, + "user" => [ + "id" => 1, + "name" => "Administrator", + "username" => "root", + "state" => "active", + "avatar_url" => "https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "web_url" => "http=>//gitlab.example.com/root", + ], + "created_at" => "2018-08-20T13=>38=>20.077Z", + "resource_type" => "Issue", + "resource_id" => 253, + "milestone" => [ + "id" => 61, + "iid" => 9, + "project_id" => 7, + "title" => "v1.2", + "description" => "Ipsum Lorem", + "state" => "active", + "created_at" => "2020-01-27T05=>07=>12.573Z", + "updated_at" => "2020-01-27T05=>07=>12.573Z", + "due_date" => null, + "start_date" => null, + "web_url" => "http=>//gitlab.example.com=>3000/group/project/-/milestones/9", + ], + "action" => "add", + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/issues/253/resource_milestone_events/142', []) + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->show(1, 253, 142)); + } + + /** + * @return string + */ + protected function getApiClass(): string + { + return ResourceMilestoneEvents::class; + } +} From a5b350646508437367a3298682954429006feaf8 Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Thu, 18 Nov 2021 17:42:22 +0100 Subject: [PATCH 09/12] refactor: apply style cli diff --- src/Api/ResourceIterationEvents.php | 5 +- src/Api/ResourceMilestoneEvents.php | 5 +- tests/Api/ResourceIterationEventsTest.php | 140 ++++++++++----------- tests/Api/ResourceMilestoneEventsTest.php | 146 +++++++++++----------- 4 files changed, 143 insertions(+), 153 deletions(-) diff --git a/src/Api/ResourceIterationEvents.php b/src/Api/ResourceIterationEvents.php index 1dcb9edc0..419096338 100644 --- a/src/Api/ResourceIterationEvents.php +++ b/src/Api/ResourceIterationEvents.php @@ -6,8 +6,6 @@ class ResourceIterationEvents extends AbstractApi { - - /** * @param int|string $project_id * @param int $issue_iid @@ -21,7 +19,6 @@ public function all($project_id, int $issue_iid) return $this->get($this->getProjectPath($project_id, $path)); } - /** * @param int|string $project_id * @param int $issue_iid @@ -36,4 +33,4 @@ public function show($project_id, int $issue_iid, int $resource_iteration_event_ return $this->get($this->getProjectPath($project_id, $path)); } -} \ No newline at end of file +} diff --git a/src/Api/ResourceMilestoneEvents.php b/src/Api/ResourceMilestoneEvents.php index b535b67ef..bb368209d 100644 --- a/src/Api/ResourceMilestoneEvents.php +++ b/src/Api/ResourceMilestoneEvents.php @@ -6,8 +6,6 @@ class ResourceMilestoneEvents extends AbstractApi { - - /** * @param int|string $project_id * @param int $issue_iid @@ -21,7 +19,6 @@ public function all($project_id, int $issue_iid) return $this->get($this->getProjectPath($project_id, $path)); } - /** * @param int|string $project_id * @param int $issue_iid @@ -36,4 +33,4 @@ public function show($project_id, int $issue_iid, int $resource_milestone_event_ return $this->get($this->getProjectPath($project_id, $path)); } -} \ No newline at end of file +} diff --git a/tests/Api/ResourceIterationEventsTest.php b/tests/Api/ResourceIterationEventsTest.php index abe8818f5..65c48a9bf 100644 --- a/tests/Api/ResourceIterationEventsTest.php +++ b/tests/Api/ResourceIterationEventsTest.php @@ -4,7 +4,6 @@ namespace Gitlab\Tests\Api; - use Gitlab\Api\ResourceIterationEvents; class ResourceIterationEventsTest extends TestCase @@ -16,58 +15,58 @@ public function shouldGetAllEvents(): void { $expectedArray = [ [ - "id" => 142, - "user" => [ - "id" => 1, - "name" => "Administrator", - "username" => "root", - "state" => "active", - "avatar_url" => "https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", - "web_url" => "http=>//gitlab.example.com/root", + 'id' => 142, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', ], - "created_at" => "2018-08-20T13=>38=>20.077Z", - "resource_type" => "Issue", - "resource_id" => 253, - "iteration" => [ - "id" => 50, - "iid" => 9, - "group_id" => 5, - "title" => "Iteration I", - "description" => "Ipsum Lorem", - "state" => 1, - "created_at" => "2020-01-27T05=>07=>12.573Z", - "updated_at" => "2020-01-27T05=>07=>12.573Z", - "due_date" => null, - "start_date" => null, + 'created_at' => '2018-08-20T13=>38=>20.077Z', + 'resource_type' => 'Issue', + 'resource_id' => 253, + 'iteration' => [ + 'id' => 50, + 'iid' => 9, + 'group_id' => 5, + 'title' => 'Iteration I', + 'description' => 'Ipsum Lorem', + 'state' => 1, + 'created_at' => '2020-01-27T05=>07=>12.573Z', + 'updated_at' => '2020-01-27T05=>07=>12.573Z', + 'due_date' => null, + 'start_date' => null, ], - "action" => "add", + 'action' => 'add', ], [ - "id" => 143, - "user" => [ - "id" => 1, - "name" => "Administrator", - "username" => "root", - "state" => "active", - "avatar_url" => "https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", - "web_url" => "http=>//gitlab.example.com/root", + 'id' => 143, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', ], - "created_at" => "2018-08-21T14=>38=>20.077Z", - "resource_type" => "Issue", - "resource_id" => 253, - "iteration" => [ - "id" => 53, - "iid" => 13, - "group_id" => 5, - "title" => "Iteration II", - "description" => "Ipsum Lorem ipsum", - "state" => 2, - "created_at" => "2020-01-27T05=>07=>12.573Z", - "updated_at" => "2020-01-27T05=>07=>12.573Z", - "due_date" => null, - "start_date" => null, + 'created_at' => '2018-08-21T14=>38=>20.077Z', + 'resource_type' => 'Issue', + 'resource_id' => 253, + 'iteration' => [ + 'id' => 53, + 'iid' => 13, + 'group_id' => 5, + 'title' => 'Iteration II', + 'description' => 'Ipsum Lorem ipsum', + 'state' => 2, + 'created_at' => '2020-01-27T05=>07=>12.573Z', + 'updated_at' => '2020-01-27T05=>07=>12.573Z', + 'due_date' => null, + 'start_date' => null, ], - "action" => "remove", + 'action' => 'remove', ], ]; @@ -80,38 +79,37 @@ public function shouldGetAllEvents(): void $this->assertEquals($expectedArray, $api->all(1, 253)); } - /** * @test */ public function shouldShowEvent(): void { $expectedArray = [ - "id" => 142, - "user" => [ - "id" => 1, - "name" => "Administrator", - "username" => "root", - "state" => "active", - "avatar_url" => "https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", - "web_url" => "http=>//gitlab.example.com/root", + 'id' => 142, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', ], - "created_at" => "2018-08-20T13=>38=>20.077Z", - "resource_type" => "Issue", - "resource_id" => 253, - "iteration" => [ - "id" => 50, - "iid" => 9, - "group_id" => 5, - "title" => "Iteration I", - "description" => "Ipsum Lorem", - "state" => 1, - "created_at" => "2020-01-27T05=>07=>12.573Z", - "updated_at" => "2020-01-27T05=>07=>12.573Z", - "due_date" => null, - "start_date" => null, + 'created_at' => '2018-08-20T13=>38=>20.077Z', + 'resource_type' => 'Issue', + 'resource_id' => 253, + 'iteration' => [ + 'id' => 50, + 'iid' => 9, + 'group_id' => 5, + 'title' => 'Iteration I', + 'description' => 'Ipsum Lorem', + 'state' => 1, + 'created_at' => '2020-01-27T05=>07=>12.573Z', + 'updated_at' => '2020-01-27T05=>07=>12.573Z', + 'due_date' => null, + 'start_date' => null, ], - "action" => "add", + 'action' => 'add', ]; $api = $this->getApiMock(); diff --git a/tests/Api/ResourceMilestoneEventsTest.php b/tests/Api/ResourceMilestoneEventsTest.php index 480ab7539..677b14cb9 100644 --- a/tests/Api/ResourceMilestoneEventsTest.php +++ b/tests/Api/ResourceMilestoneEventsTest.php @@ -4,7 +4,6 @@ namespace Gitlab\Tests\Api; - use Gitlab\Api\ResourceMilestoneEvents; class ResourceMilestoneEventsTest extends TestCase @@ -16,60 +15,60 @@ public function shouldGetAllEvents(): void { $expectedArray = [ [ - "id" => 142, - "user" => [ - "id" => 1, - "name" => "Administrator", - "username" => "root", - "state" => "active", - "avatar_url" => "https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", - "web_url" => "http=>//gitlab.example.com/root", + 'id' => 142, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', ], - "created_at" => "2018-08-20T13=>38=>20.077Z", - "resource_type" => "Issue", - "resource_id" => 253, - "milestone" => [ - "id" => 61, - "iid" => 9, - "project_id" => 7, - "title" => "v1.2", - "description" => "Ipsum Lorem", - "state" => "active", - "created_at" => "2020-01-27T05=>07=>12.573Z", - "updated_at" => "2020-01-27T05=>07=>12.573Z", - "due_date" => null, - "start_date" => null, - "web_url" => "http=>//gitlab.example.com=>3000/group/project/-/milestones/9", + 'created_at' => '2018-08-20T13=>38=>20.077Z', + 'resource_type' => 'Issue', + 'resource_id' => 253, + 'milestone' => [ + 'id' => 61, + 'iid' => 9, + 'project_id' => 7, + 'title' => 'v1.2', + 'description' => 'Ipsum Lorem', + 'state' => 'active', + 'created_at' => '2020-01-27T05=>07=>12.573Z', + 'updated_at' => '2020-01-27T05=>07=>12.573Z', + 'due_date' => null, + 'start_date' => null, + 'web_url' => 'http=>//gitlab.example.com=>3000/group/project/-/milestones/9', ], - "action" => "add", + 'action' => 'add', ], [ - "id" => 143, - "user" => [ - "id" => 1, - "name" => "Administrator", - "username" => "root", - "state" => "active", - "avatar_url" => "https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", - "web_url" => "http=>//gitlab.example.com/root", + 'id' => 143, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', ], - "created_at" => "2018-08-21T14=>38=>20.077Z", - "resource_type" => "Issue", - "resource_id" => 253, - "milestone" => [ - "id" => 61, - "iid" => 9, - "project_id" => 7, - "title" => "v1.2", - "description" => "Ipsum Lorem", - "state" => "active", - "created_at" => "2020-01-27T05=>07=>12.573Z", - "updated_at" => "2020-01-27T05=>07=>12.573Z", - "due_date" => null, - "start_date" => null, - "web_url" => "http=>//gitlab.example.com=>3000/group/project/-/milestones/9", + 'created_at' => '2018-08-21T14=>38=>20.077Z', + 'resource_type' => 'Issue', + 'resource_id' => 253, + 'milestone' => [ + 'id' => 61, + 'iid' => 9, + 'project_id' => 7, + 'title' => 'v1.2', + 'description' => 'Ipsum Lorem', + 'state' => 'active', + 'created_at' => '2020-01-27T05=>07=>12.573Z', + 'updated_at' => '2020-01-27T05=>07=>12.573Z', + 'due_date' => null, + 'start_date' => null, + 'web_url' => 'http=>//gitlab.example.com=>3000/group/project/-/milestones/9', ], - "action" => "remove", + 'action' => 'remove', ], ]; @@ -82,39 +81,38 @@ public function shouldGetAllEvents(): void $this->assertEquals($expectedArray, $api->all(1, 253)); } - /** * @test */ public function shouldShowEvent(): void { $expectedArray = [ - "id" => 142, - "user" => [ - "id" => 1, - "name" => "Administrator", - "username" => "root", - "state" => "active", - "avatar_url" => "https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", - "web_url" => "http=>//gitlab.example.com/root", + 'id' => 142, + 'user' => [ + 'id' => 1, + 'name' => 'Administrator', + 'username' => 'root', + 'state' => 'active', + 'avatar_url' => 'https=>//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', + 'web_url' => 'http=>//gitlab.example.com/root', ], - "created_at" => "2018-08-20T13=>38=>20.077Z", - "resource_type" => "Issue", - "resource_id" => 253, - "milestone" => [ - "id" => 61, - "iid" => 9, - "project_id" => 7, - "title" => "v1.2", - "description" => "Ipsum Lorem", - "state" => "active", - "created_at" => "2020-01-27T05=>07=>12.573Z", - "updated_at" => "2020-01-27T05=>07=>12.573Z", - "due_date" => null, - "start_date" => null, - "web_url" => "http=>//gitlab.example.com=>3000/group/project/-/milestones/9", + 'created_at' => '2018-08-20T13=>38=>20.077Z', + 'resource_type' => 'Issue', + 'resource_id' => 253, + 'milestone' => [ + 'id' => 61, + 'iid' => 9, + 'project_id' => 7, + 'title' => 'v1.2', + 'description' => 'Ipsum Lorem', + 'state' => 'active', + 'created_at' => '2020-01-27T05=>07=>12.573Z', + 'updated_at' => '2020-01-27T05=>07=>12.573Z', + 'due_date' => null, + 'start_date' => null, + 'web_url' => 'http=>//gitlab.example.com=>3000/group/project/-/milestones/9', ], - "action" => "add", + 'action' => 'add', ]; $api = $this->getApiMock(); From 0e99ae4539e6ac055247bc2856c6bc99f1394f12 Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Mon, 27 Dec 2021 11:45:24 +0100 Subject: [PATCH 10/12] fix: revert changes --- .gitignore | 3 --- src/Client.php | 56 ++++++++++++++++++++++++-------------------------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index e5fef0746..04626b2fe 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,3 @@ composer.lock phpstan.neon phpunit.xml vendor - -composer.phar -.idea/ diff --git a/src/Client.php b/src/Client.php index 8bb5def10..b4db114e9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -121,39 +121,14 @@ public function __construct(Builder $httpClientBuilder = null) $builder->addPlugin(new ExceptionThrower()); $builder->addPlugin(new HistoryPlugin($this->responseHistory)); - $builder->addPlugin( - new HeaderDefaultsPlugin([ - 'User-Agent' => self::USER_AGENT, - ]) - ); + $builder->addPlugin(new HeaderDefaultsPlugin([ + 'User-Agent' => self::USER_AGENT, + ])); $builder->addPlugin(new RedirectPlugin()); $this->setUrl(self::BASE_URL); } - /** - * @param string $url - * - * @return void - */ - public function setUrl(string $url): void - { - $uri = $this->getHttpClientBuilder()->getUriFactory()->createUri($url); - - $this->getHttpClientBuilder()->removePlugin(AddHostPlugin::class); - $this->getHttpClientBuilder()->addPlugin(new AddHostPlugin($uri)); - } - - /** - * Get the HTTP client builder. - * - * @return Builder - */ - protected function getHttpClientBuilder(): Builder - { - return $this->httpClientBuilder; - } - /** * Create a Gitlab\Client using an HTTP client. * @@ -430,6 +405,19 @@ public function authenticate(string $token, string $authMethod, string $sudo = n $this->getHttpClientBuilder()->removePlugin(Authentication::class); $this->getHttpClientBuilder()->addPlugin(new Authentication($authMethod, $token, $sudo)); } + + /** + * @param string $url + * + * @return void + */ + public function setUrl(string $url): void + { + $uri = $this->getHttpClientBuilder()->getUriFactory()->createUri($url); + + $this->getHttpClientBuilder()->removePlugin(AddHostPlugin::class); + $this->getHttpClientBuilder()->addPlugin(new AddHostPlugin($uri)); + } /** * Get the last response. @@ -450,7 +438,7 @@ public function getHttpClient(): HttpMethodsClientInterface { return $this->getHttpClientBuilder()->getHttpClient(); } - + /** * Get the stream factory. * @@ -460,4 +448,14 @@ public function getStreamFactory(): StreamFactoryInterface { return $this->getHttpClientBuilder()->getStreamFactory(); } + + /** + * Get the HTTP client builder. + * + * @return Builder + */ + protected function getHttpClientBuilder(): Builder + { + return $this->httpClientBuilder; + } } From 6fd7668d21365c76aa1634bd918bdef739d02fa1 Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Mon, 27 Dec 2021 11:50:34 +0100 Subject: [PATCH 11/12] fix: revert changes --- src/Client.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Client.php b/src/Client.php index b4db114e9..9c1abdd34 100644 --- a/src/Client.php +++ b/src/Client.php @@ -121,7 +121,7 @@ public function __construct(Builder $httpClientBuilder = null) $builder->addPlugin(new ExceptionThrower()); $builder->addPlugin(new HistoryPlugin($this->responseHistory)); - $builder->addPlugin(new HeaderDefaultsPlugin([ + $builder->addPlugin(new HeaderDefaultsPlugin([ 'User-Agent' => self::USER_AGENT, ])); $builder->addPlugin(new RedirectPlugin()); @@ -405,19 +405,19 @@ public function authenticate(string $token, string $authMethod, string $sudo = n $this->getHttpClientBuilder()->removePlugin(Authentication::class); $this->getHttpClientBuilder()->addPlugin(new Authentication($authMethod, $token, $sudo)); } - - /** - * @param string $url - * - * @return void - */ - public function setUrl(string $url): void - { - $uri = $this->getHttpClientBuilder()->getUriFactory()->createUri($url); - - $this->getHttpClientBuilder()->removePlugin(AddHostPlugin::class); - $this->getHttpClientBuilder()->addPlugin(new AddHostPlugin($uri)); - } + + /** + * @param string $url + * + * @return void + */ + public function setUrl(string $url): void + { + $uri = $this->getHttpClientBuilder()->getUriFactory()->createUri($url); + + $this->getHttpClientBuilder()->removePlugin(AddHostPlugin::class); + $this->getHttpClientBuilder()->addPlugin(new AddHostPlugin($uri)); + } /** * Get the last response. @@ -438,7 +438,7 @@ public function getHttpClient(): HttpMethodsClientInterface { return $this->getHttpClientBuilder()->getHttpClient(); } - + /** * Get the stream factory. * @@ -448,7 +448,7 @@ public function getStreamFactory(): StreamFactoryInterface { return $this->getHttpClientBuilder()->getStreamFactory(); } - + /** * Get the HTTP client builder. * From 026697f64a51f75bb4ff1dc66e87b1ee06b366ce Mon Sep 17 00:00:00 2001 From: Joshua Chapman Date: Mon, 27 Dec 2021 14:36:55 +0100 Subject: [PATCH 12/12] fix: add missing copyright text --- src/Api/ResourceIterationEvents.php | 10 ++++++++++ src/Api/ResourceLabelEvents.php | 10 ++++++++++ src/Api/ResourceMilestoneEvents.php | 10 ++++++++++ src/Api/ResourceStateEvents.php | 10 ++++++++++ src/Api/ResourceWeightEvents.php | 10 ++++++++++ tests/Api/ResourceIterationEventsTest.php | 10 ++++++++++ tests/Api/ResourceLabelEventsTest.php | 10 ++++++++++ tests/Api/ResourceMilestoneEventsTest.php | 10 ++++++++++ tests/Api/ResourceStateEventsTest.php | 10 ++++++++++ tests/Api/ResourceWeightEventsTest.php | 10 ++++++++++ 10 files changed, 100 insertions(+) diff --git a/src/Api/ResourceIterationEvents.php b/src/Api/ResourceIterationEvents.php index 419096338..9112882b1 100644 --- a/src/Api/ResourceIterationEvents.php +++ b/src/Api/ResourceIterationEvents.php @@ -2,6 +2,16 @@ declare(strict_types=1); +/* + * This file is part of the Gitlab API library. + * + * (c) Matt Humphrey + * (c) Graham Campbell + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Gitlab\Api; class ResourceIterationEvents extends AbstractApi diff --git a/src/Api/ResourceLabelEvents.php b/src/Api/ResourceLabelEvents.php index 767d1a5f1..d0d8cd5ee 100644 --- a/src/Api/ResourceLabelEvents.php +++ b/src/Api/ResourceLabelEvents.php @@ -2,6 +2,16 @@ declare(strict_types=1); +/* + * This file is part of the Gitlab API library. + * + * (c) Matt Humphrey + * (c) Graham Campbell + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Gitlab\Api; class ResourceLabelEvents extends AbstractApi diff --git a/src/Api/ResourceMilestoneEvents.php b/src/Api/ResourceMilestoneEvents.php index bb368209d..e7f2d19ea 100644 --- a/src/Api/ResourceMilestoneEvents.php +++ b/src/Api/ResourceMilestoneEvents.php @@ -2,6 +2,16 @@ declare(strict_types=1); +/* + * This file is part of the Gitlab API library. + * + * (c) Matt Humphrey + * (c) Graham Campbell + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Gitlab\Api; class ResourceMilestoneEvents extends AbstractApi diff --git a/src/Api/ResourceStateEvents.php b/src/Api/ResourceStateEvents.php index 022f2c02a..511d1dce5 100644 --- a/src/Api/ResourceStateEvents.php +++ b/src/Api/ResourceStateEvents.php @@ -2,6 +2,16 @@ declare(strict_types=1); +/* + * This file is part of the Gitlab API library. + * + * (c) Matt Humphrey + * (c) Graham Campbell + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Gitlab\Api; class ResourceStateEvents extends AbstractApi diff --git a/src/Api/ResourceWeightEvents.php b/src/Api/ResourceWeightEvents.php index dc1a22637..c2bd105ad 100644 --- a/src/Api/ResourceWeightEvents.php +++ b/src/Api/ResourceWeightEvents.php @@ -2,6 +2,16 @@ declare(strict_types=1); +/* + * This file is part of the Gitlab API library. + * + * (c) Matt Humphrey + * (c) Graham Campbell + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Gitlab\Api; class ResourceWeightEvents extends AbstractApi diff --git a/tests/Api/ResourceIterationEventsTest.php b/tests/Api/ResourceIterationEventsTest.php index 65c48a9bf..f7b8e06f6 100644 --- a/tests/Api/ResourceIterationEventsTest.php +++ b/tests/Api/ResourceIterationEventsTest.php @@ -2,6 +2,16 @@ declare(strict_types=1); +/* + * This file is part of the Gitlab API library. + * + * (c) Matt Humphrey + * (c) Graham Campbell + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Gitlab\Tests\Api; use Gitlab\Api\ResourceIterationEvents; diff --git a/tests/Api/ResourceLabelEventsTest.php b/tests/Api/ResourceLabelEventsTest.php index 07cc4e55c..d65b25ecc 100644 --- a/tests/Api/ResourceLabelEventsTest.php +++ b/tests/Api/ResourceLabelEventsTest.php @@ -2,6 +2,16 @@ declare(strict_types=1); +/* + * This file is part of the Gitlab API library. + * + * (c) Matt Humphrey + * (c) Graham Campbell + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Gitlab\Tests\Api; use Gitlab\Api\ResourceLabelEvents; diff --git a/tests/Api/ResourceMilestoneEventsTest.php b/tests/Api/ResourceMilestoneEventsTest.php index 677b14cb9..7b3699e6e 100644 --- a/tests/Api/ResourceMilestoneEventsTest.php +++ b/tests/Api/ResourceMilestoneEventsTest.php @@ -2,6 +2,16 @@ declare(strict_types=1); +/* + * This file is part of the Gitlab API library. + * + * (c) Matt Humphrey + * (c) Graham Campbell + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Gitlab\Tests\Api; use Gitlab\Api\ResourceMilestoneEvents; diff --git a/tests/Api/ResourceStateEventsTest.php b/tests/Api/ResourceStateEventsTest.php index 3b7ced7eb..f3a5a1198 100644 --- a/tests/Api/ResourceStateEventsTest.php +++ b/tests/Api/ResourceStateEventsTest.php @@ -2,6 +2,16 @@ declare(strict_types=1); +/* + * This file is part of the Gitlab API library. + * + * (c) Matt Humphrey + * (c) Graham Campbell + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Gitlab\Tests\Api; use Gitlab\Api\ResourceStateEvents; diff --git a/tests/Api/ResourceWeightEventsTest.php b/tests/Api/ResourceWeightEventsTest.php index 7c851cf25..4d712a4a5 100644 --- a/tests/Api/ResourceWeightEventsTest.php +++ b/tests/Api/ResourceWeightEventsTest.php @@ -2,6 +2,16 @@ declare(strict_types=1); +/* + * This file is part of the Gitlab API library. + * + * (c) Matt Humphrey + * (c) Graham Campbell + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Gitlab\Tests\Api; use Gitlab\Api\ResourceWeightEvents;