diff --git a/src/main/kotlin/net/leanix/githubagent/services/WebhookEventService.kt b/src/main/kotlin/net/leanix/githubagent/services/WebhookEventService.kt index 95bac9c..58b9157 100644 --- a/src/main/kotlin/net/leanix/githubagent/services/WebhookEventService.kt +++ b/src/main/kotlin/net/leanix/githubagent/services/WebhookEventService.kt @@ -85,7 +85,7 @@ class WebhookEventService( } removedManifestFiles.forEach { filePath -> - handleRemovedManifestFile(repositoryFullName) + handleRemovedManifestFile(repositoryFullName, filePath) } } @@ -108,11 +108,7 @@ class WebhookEventService( manifestFilePath: String, action: ManifestFileAction ) { - val location = if ('/' in manifestFilePath) { - "directory '/${manifestFilePath.substringBeforeLast('/')}'" - } else { - "root folder" - } + val location = getManifestFileLocation(manifestFilePath) logger.info("Manifest file {} in repository {} under {}", action, repositoryFullName, location) @@ -133,16 +129,25 @@ class WebhookEventService( ) } - private fun handleRemovedManifestFile(repositoryFullName: String) { - logger.info("Manifest file ${ManifestFileAction.REMOVED} from repository $repositoryFullName") + private fun handleRemovedManifestFile(repositoryFullName: String, manifestFilePath: String) { + val location = getManifestFileLocation(manifestFilePath) + logger.info("Manifest file ${ManifestFileAction.REMOVED} from repository $repositoryFullName under $location") webSocketService.sendMessage( "/events/manifestFile", ManifestFileUpdateDto( repositoryFullName, ManifestFileAction.REMOVED, null, - null + manifestFilePath ) ) } + + private fun getManifestFileLocation(manifestFilePath: String): String { + return if (manifestFilePath.contains('/')) { + "directory '/${manifestFilePath.substringBeforeLast('/')}'" + } else { + "root folder" + } + } } diff --git a/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt b/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt index 7de900c..153fa1a 100644 --- a/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt +++ b/src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt @@ -150,6 +150,39 @@ class WebhookEventServiceTest { verify { webSocketService.sendMessage(any(), any()) } } + @Test + fun `should handle manifest file removal in subdirectory`() { + val payload = """{ + "repository": { + "name": "repo", + "full_name": "owner/repo", + "owner": {"name": "owner"}, + "default_branch": "main" + }, + "head_commit": { + "added": [], + "modified": [], + "removed": ["a/b/c/$MANIFEST_FILE_NAME", "a/b/c/some_other_file.yaml"] + }, + "installation": {"id": 1}, + "ref": "refs/heads/main" + }""" + + webhookEventService.consumeWebhookEvent("PUSH", payload) + + verify(exactly = 1) { + webSocketService.sendMessage( + "/events/manifestFile", + ManifestFileUpdateDto( + "owner/repo", + ManifestFileAction.REMOVED, + null, + "a/b/c/$MANIFEST_FILE_NAME" + ) + ) + } + } + @Test fun `should handle manifest file in subdirectory`() { val payload = """{