Skip to content

Commit

Permalink
Merge pull request #61 from leanix/feature/CID-3362/ignore-push-event…
Browse files Browse the repository at this point in the history
…s-without-a-head-commit

CID-3362: ignore push events without a head commit
  • Loading branch information
mohamedlajmileanix authored Dec 19, 2024
2 parents c25c978 + 0d64d3b commit a51801c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class PushEventPayload(
val repository: PushEventRepository,
val installation: PushEventInstallation,
@JsonProperty("head_commit")
val headCommit: PushEventCommit
val headCommit: PushEventCommit?
)

@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class WebhookEventService(

val installationToken = getInstallationToken(pushEventPayload.installation.id)

if (pushEventPayload.ref == "refs/heads/$defaultBranch") {
if (headCommit != null && pushEventPayload.ref == "refs/heads/$defaultBranch") {
handleManifestFileChanges(
defaultBranch,
headCommit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,24 @@ class WebhookEventServiceTest {

verify(exactly = 6) { cachingService.get("runId") }
}

@Test
fun `should ignore push events without a head commit`() {
val payload = """{
"repository": {
"name": "repo",
"full_name": "owner/repo",
"owner": {"name": "owner"},
"default_branch": "main"
},
"installation": {"id": 1},
"ref": "refs/heads/main"
}"""

webhookEventService.consumeWebhookEvent("PUSH", payload)

verify(exactly = 0) {
webSocketService.sendMessage(any(), any())
}
}
}

0 comments on commit a51801c

Please sign in to comment.