From 828949a8d9b4af7601f4bd98c247ce93a660e1f0 Mon Sep 17 00:00:00 2001 From: Kostas Petrakis Date: Mon, 4 Nov 2024 15:47:26 +0100 Subject: [PATCH 1/4] fix: Use yaml as manifest extension - Instead of yml use yaml as the officially supported manifest extension --- .../leanix/githubagent/shared/Constants.kt | 2 +- .../services/WebhookEventServiceTest.kt | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/leanix/githubagent/shared/Constants.kt b/src/main/kotlin/net/leanix/githubagent/shared/Constants.kt index 9bbaf22..a295efb 100644 --- a/src/main/kotlin/net/leanix/githubagent/shared/Constants.kt +++ b/src/main/kotlin/net/leanix/githubagent/shared/Constants.kt @@ -3,7 +3,7 @@ package net.leanix.githubagent.shared const val TOPIC_PREFIX = "/app/ghe/" const val APP_NAME_TOPIC = "appName" const val LOGS_TOPIC = "logs" -const val MANIFEST_FILE_NAME = "leanix.yml" +const val MANIFEST_FILE_NAME = "leanix.yaml" val SUPPORTED_EVENT_TYPES = listOf( "REPOSITORY", diff --git a/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt b/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt index 153fa1a..7514013 100644 --- a/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt +++ b/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt @@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.ActiveProfiles +const val UNSUPPORTED_MANIFEST_EXTENSION = "leanix.yml" + @SpringBootTest @ActiveProfiles("test") class WebhookEventServiceTest { @@ -266,4 +268,37 @@ class WebhookEventServiceTest { ) } } + + @Test + fun `should handle push event with supported YAML extension`() { + val payload = """{ + "repository": { + "name": "repo", + "full_name": "owner/repo", + "owner": {"name": "owner"}, + "default_branch": "main" + }, + "head_commit": { + "added": ["custom/path/added1/leanix.yml", "custom/path/added2/$MANIFEST_FILE_NAME"], + "modified": [], + "removed": [] + }, + "installation": {"id": 1}, + "ref": "refs/heads/main" + }""" + + webhookEventService.consumeWebhookEvent("PUSH", payload) + + verify(exactly = 1) { + webSocketService.sendMessage( + "/events/manifestFile", + ManifestFileUpdateDto( + "owner/repo", + ManifestFileAction.ADDED, + "content", + "custom/path/added2/$MANIFEST_FILE_NAME" + ) + ) + } + } } From 8fd84c5a1b56e69e2b51d70555bbdbe33ae1f27b Mon Sep 17 00:00:00 2001 From: Kostas Petrakis Date: Tue, 5 Nov 2024 13:19:31 +0100 Subject: [PATCH 2/4] chore: move unsupported yaml extension to const --- .../net/leanix/githubagent/services/WebhookEventServiceTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt b/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt index 7514013..1c0b127 100644 --- a/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt +++ b/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt @@ -279,7 +279,7 @@ class WebhookEventServiceTest { "default_branch": "main" }, "head_commit": { - "added": ["custom/path/added1/leanix.yml", "custom/path/added2/$MANIFEST_FILE_NAME"], + "added": ["custom/path/added1/$UNSUPPORTED_MANIFEST_EXTENSION", "custom/path/added2/$MANIFEST_FILE_NAME"], "modified": [], "removed": [] }, From 5735520794b6ccbe77a52a903f54b4b35cdf0442 Mon Sep 17 00:00:00 2001 From: Kostas Petrakis Date: Tue, 5 Nov 2024 15:57:27 +0100 Subject: [PATCH 3/4] chore: extend tests for unsupported yml --- .../services/WebhookEventServiceTest.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt b/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt index 1c0b127..7d3c86c 100644 --- a/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt +++ b/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt @@ -301,4 +301,37 @@ class WebhookEventServiceTest { ) } } + + @Test + fun `should not handle push event with unsupported YAML extension`() { + val payload = """{ + "repository": { + "name": "repo", + "full_name": "owner/repo", + "owner": {"name": "owner"}, + "default_branch": "main" + }, + "head_commit": { + "added": ["custom/path/added1/$UNSUPPORTED_MANIFEST_EXTENSION"], + "modified": [], + "removed": [] + }, + "installation": {"id": 1}, + "ref": "refs/heads/main" + }""" + + webhookEventService.consumeWebhookEvent("PUSH", payload) + + verify(exactly = 0) { + webSocketService.sendMessage( + "/events/manifestFile", + ManifestFileUpdateDto( + "owner/repo", + ManifestFileAction.ADDED, + "content", + "custom/path/added1/$MANIFEST_FILE_NAME" + ) + ) + } + } } From 507f20460f28a2065db7bb60fdd75231db795f47 Mon Sep 17 00:00:00 2001 From: Kostas Petrakis Date: Tue, 5 Nov 2024 17:12:19 +0100 Subject: [PATCH 4/4] chore: refactor test for unsupported yaml extension --- .../services/WebhookEventServiceTest.kt | 25 ++----------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt b/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt index 7d3c86c..006bd1f 100644 --- a/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt +++ b/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt @@ -270,7 +270,7 @@ class WebhookEventServiceTest { } @Test - fun `should handle push event with supported YAML extension`() { + fun `should handle push event only with supported YAML extension`() { val payload = """{ "repository": { "name": "repo", @@ -300,27 +300,6 @@ class WebhookEventServiceTest { ) ) } - } - - @Test - fun `should not handle push event with unsupported YAML extension`() { - val payload = """{ - "repository": { - "name": "repo", - "full_name": "owner/repo", - "owner": {"name": "owner"}, - "default_branch": "main" - }, - "head_commit": { - "added": ["custom/path/added1/$UNSUPPORTED_MANIFEST_EXTENSION"], - "modified": [], - "removed": [] - }, - "installation": {"id": 1}, - "ref": "refs/heads/main" - }""" - - webhookEventService.consumeWebhookEvent("PUSH", payload) verify(exactly = 0) { webSocketService.sendMessage( @@ -329,7 +308,7 @@ class WebhookEventServiceTest { "owner/repo", ManifestFileAction.ADDED, "content", - "custom/path/added1/$MANIFEST_FILE_NAME" + "custom/path/added1/$UNSUPPORTED_MANIFEST_EXTENSION" ) ) }