From 6e145f71f819975240cce511c79b9794abc16ecb Mon Sep 17 00:00:00 2001 From: Eric Castillo Date: Mon, 12 Jun 2023 16:10:39 +0200 Subject: [PATCH 1/4] feat: Added Jira Integration --- src/Api/Projects.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Api/Projects.php b/src/Api/Projects.php index fa2877dc..5b68c504 100644 --- a/src/Api/Projects.php +++ b/src/Api/Projects.php @@ -1597,4 +1597,36 @@ public function deleteProtectedTag($project_id, string $tag_name) { return $this->delete($this->getProjectPath($project_id, 'protected_tags/'.self::encodePath($tag_name))); } + + + /** + * @param $project_id + * @param $integration + * @param array $parameters + * + * @return mixed + */ + public function updateIntegration($project_id, $integration, array $parameters = []) + { + $resolver = new OptionsResolver(); + if ('jira' === $integration) { + $resolver->setDefined('url') + ->setAllowedTypes('url', 'string') + ->setRequired('url') + ; + $resolver->setDefined('password') + ->setAllowedTypes('password', 'string') + ->setRequired('password') + ; + $resolver->setDefined('username') + ->setAllowedTypes('username', 'string') + ; + $resolver->setDefined('jira_auth_type') + ->setAllowedTypes('jira_auth_type', 'int') + ->setAllowedValues('jira_auth_type', [0, 1]); + ; + } + + return $this->put($this->getProjectPath($project_id, 'integrations/'. $integration), $parameters); + } } From 5abe39a33f79a7cd66d4cb5c1216728cd85d5d21 Mon Sep 17 00:00:00 2001 From: Eric Castillo Date: Mon, 12 Jun 2023 16:51:59 +0200 Subject: [PATCH 2/4] feat: Added slack integration --- src/Api/Projects.php | 40 +++++++++++++++++++++++++++++++++++--- tests/Api/ProjectsTest.php | 16 +++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/Api/Projects.php b/src/Api/Projects.php index 5b68c504..39305072 100644 --- a/src/Api/Projects.php +++ b/src/Api/Projects.php @@ -1600,15 +1600,19 @@ public function deleteProtectedTag($project_id, string $tag_name) /** - * @param $project_id - * @param $integration + * @param int|string $project_id + * @param string $integration * @param array $parameters * * @return mixed */ - public function updateIntegration($project_id, $integration, array $parameters = []) + public function updateIntegration($project_id, string $integration, array $parameters = []) { $resolver = new OptionsResolver(); + $booleanNormalizer = function (Options $resolver, $value): string { + return $value ? 'true' : 'false'; + }; + if ('jira' === $integration) { $resolver->setDefined('url') ->setAllowedTypes('url', 'string') @@ -1627,6 +1631,36 @@ public function updateIntegration($project_id, $integration, array $parameters ; } + if ('slack' === $integration) { + $resolver->setDefined('webhook') + ->setAllowedTypes('webhook', 'string') + ->setRequired('webhook') + ; + $resolver->setDefined('username') + ->setAllowedTypes('username', 'string') + ; + $resolver->setDefined('channel') + ->setAllowedTypes('channel', 'string') + ; + $resolver->setDefined('pipeline_channel') + ->setAllowedTypes('pipeline_channel', 'string') + ; + $resolver->setDefined('pipeline_events') + ->setAllowedTypes('pipeline_events', 'bool') + ->setNormalizer('pipeline_events', $booleanNormalizer) + ; + $resolver->setDefined('notify_only_broken_pipelines') + ->setAllowedTypes('notify_only_broken_pipelines', 'bool') + ->setNormalizer('notify_only_broken_pipelines', $booleanNormalizer) + ; + + $resolver->setDefined('branches_to_be_notified') + ->setAllowedTypes('branches_to_be_notified', 'string') + ->setAllowedValues('branches_to_be_notified', ['all', 'default', 'protected', 'default_and_protected']) + ; + + } + return $this->put($this->getProjectPath($project_id, 'integrations/'. $integration), $parameters); } } diff --git a/tests/Api/ProjectsTest.php b/tests/Api/ProjectsTest.php index 709752e1..2aa11a29 100644 --- a/tests/Api/ProjectsTest.php +++ b/tests/Api/ProjectsTest.php @@ -2890,6 +2890,22 @@ public function shouldRemoveProtectedTag(): void $this->assertEquals($expectedBool, $api->deleteProtectedTag(1, 'release-*')); } + /** + * @test + */ + public function shouldUpdateIntegrationConfig(): void + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with( + 'projects/1/integrations/jira' + ) + ->will($this->returnValue([])); + ; + $this->assertEquals([], $api->updateIntegration(1, 'jira', [])); + } + protected function getApiClass() { return Projects::class; From 5cd188a7ed72691201d6ca18f259f98c6b267f57 Mon Sep 17 00:00:00 2001 From: Eric Castillo Date: Mon, 12 Jun 2023 17:17:45 +0200 Subject: [PATCH 3/4] fix: Style fix --- src/Api/Projects.php | 8 ++++---- tests/Api/ProjectsTest.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Api/Projects.php b/src/Api/Projects.php index 39305072..136bc169 100644 --- a/src/Api/Projects.php +++ b/src/Api/Projects.php @@ -1601,12 +1601,12 @@ public function deleteProtectedTag($project_id, string $tag_name) /** * @param int|string $project_id - * @param string $integration - * @param array $parameters + * @param string $integration + * @param array $parameters * * @return mixed */ - public function updateIntegration($project_id, string $integration, array $parameters = []) + public function updateIntegration($project_id, string $integration, array $parameters = []) { $resolver = new OptionsResolver(); $booleanNormalizer = function (Options $resolver, $value): string { @@ -1661,6 +1661,6 @@ public function updateIntegration($project_id, string $integration, array $para } - return $this->put($this->getProjectPath($project_id, 'integrations/'. $integration), $parameters); + return $this->put($this->getProjectPath($project_id, 'integrations/'.$integration), $parameters); } } diff --git a/tests/Api/ProjectsTest.php b/tests/Api/ProjectsTest.php index 2aa11a29..f2a532e9 100644 --- a/tests/Api/ProjectsTest.php +++ b/tests/Api/ProjectsTest.php @@ -2902,7 +2902,7 @@ public function shouldUpdateIntegrationConfig(): void 'projects/1/integrations/jira' ) ->will($this->returnValue([])); - ; + $this->assertEquals([], $api->updateIntegration(1, 'jira', [])); } From eb0a0b72a10aa38453766f94dfef0a6194cd5c89 Mon Sep 17 00:00:00 2001 From: Eric Castillo Date: Mon, 12 Jun 2023 17:20:50 +0200 Subject: [PATCH 4/4] fix: Style fix --- src/Api/Projects.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Api/Projects.php b/src/Api/Projects.php index 136bc169..9edf6b76 100644 --- a/src/Api/Projects.php +++ b/src/Api/Projects.php @@ -1598,7 +1598,6 @@ public function deleteProtectedTag($project_id, string $tag_name) return $this->delete($this->getProjectPath($project_id, 'protected_tags/'.self::encodePath($tag_name))); } - /** * @param int|string $project_id * @param string $integration @@ -1627,7 +1626,7 @@ public function updateIntegration($project_id, string $integration, array $param ; $resolver->setDefined('jira_auth_type') ->setAllowedTypes('jira_auth_type', 'int') - ->setAllowedValues('jira_auth_type', [0, 1]); + ->setAllowedValues('jira_auth_type', [0, 1]) ; } @@ -1658,7 +1657,6 @@ public function updateIntegration($project_id, string $integration, array $param ->setAllowedTypes('branches_to_be_notified', 'string') ->setAllowedValues('branches_to_be_notified', ['all', 'default', 'protected', 'default_and_protected']) ; - } return $this->put($this->getProjectPath($project_id, 'integrations/'.$integration), $parameters);