Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CID-3107: React to manifest file deletion via Webhook #33

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class WebhookEventService(
}

removedManifestFiles.forEach { filePath ->
handleRemovedManifestFile(repositoryFullName)
handleRemovedManifestFile(repositoryFullName, filePath)
}
}

Expand All @@ -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)

Expand All @@ -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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,39 @@ class WebhookEventServiceTest {
verify { webSocketService.sendMessage(any(), any<ManifestFileUpdateDto>()) }
}

@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 = """{
Expand Down
Loading