Skip to content

Commit 9121950

Browse files
Merge branch 'main' into feature/cid-3370-send-org-in-new-installation
2 parents a626071 + a51801c commit 9121950

File tree

6 files changed

+40
-9
lines changed

6 files changed

+40
-9
lines changed

src/main/kotlin/net/leanix/githubagent/config/AgentSetupValidation.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package net.leanix.githubagent.config
22

3-
import jakarta.annotation.PostConstruct
43
import net.leanix.githubagent.exceptions.GitHubEnterpriseConfigurationMissingException
4+
import org.springframework.context.event.ContextRefreshedEvent
5+
import org.springframework.context.event.EventListener
56
import org.springframework.stereotype.Component
67

78
@Component
89
class AgentSetupValidation(
9-
private val gitHubEnterpriseProperties: GitHubEnterpriseProperties
10+
private val gitHubEnterpriseProperties: GitHubEnterpriseProperties,
11+
private val leanIXProperties: LeanIXProperties
1012
) {
1113

12-
@PostConstruct
13-
fun validateConfiguration() {
14+
@EventListener
15+
@SuppressWarnings("UnusedParameter")
16+
fun onApplicationEvent(event: ContextRefreshedEvent) {
1417
val missingProperties = mutableListOf<String>()
1518

1619
if (gitHubEnterpriseProperties.baseUrl.isBlank()) {
@@ -23,6 +26,14 @@ class AgentSetupValidation(
2326
missingProperties.add("GITHUB_ENTERPRISE_PEM_FILE")
2427
}
2528

29+
if (leanIXProperties.wsBaseUrl.isBlank()) {
30+
missingProperties.add("LEANIX_WS_BASE_URL")
31+
}
32+
33+
if (leanIXProperties.auth.accessTokenUri.isBlank()) {
34+
missingProperties.add("LEANIX_AUTH_ACCESS_TOKEN_URI")
35+
}
36+
2637
if (missingProperties.isNotEmpty()) {
2738
throw GitHubEnterpriseConfigurationMissingException(missingProperties.joinToString(", "))
2839
}

src/main/kotlin/net/leanix/githubagent/dto/PushEventPayload.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ data class PushEventPayload(
99
val repository: PushEventRepository,
1010
val installation: PushEventInstallation,
1111
@JsonProperty("head_commit")
12-
val headCommit: PushEventCommit
12+
val headCommit: PushEventCommit?
1313
)
1414

1515
@JsonIgnoreProperties(ignoreUnknown = true)

src/main/kotlin/net/leanix/githubagent/services/GitHubEnterpriseService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class GitHubEnterpriseService(private val githubClient: GitHubClient) {
1212

1313
companion object {
1414
val expectedPermissions = listOf("administration", "contents", "metadata")
15-
val expectedEvents = listOf("label", "public", "repository")
15+
val expectedEvents = listOf("label", "public", "repository", "push", "installation")
1616
}
1717
private val logger = LoggerFactory.getLogger(GitHubEnterpriseService::class.java)
1818

src/main/kotlin/net/leanix/githubagent/services/WebhookEventService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class WebhookEventService(
5151

5252
val installationToken = getInstallationToken(pushEventPayload.installation.id)
5353

54-
if (pushEventPayload.ref == "refs/heads/$defaultBranch") {
54+
if (headCommit != null && pushEventPayload.ref == "refs/heads/$defaultBranch") {
5555
handleManifestFileChanges(
5656
defaultBranch,
5757
headCommit,

src/test/kotlin/net/leanix/githubagent/services/GitHubEnterpriseServiceTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class GitHubEnterpriseServiceTest {
2121
val githubApp = GitHubAppResponse(
2222
slug = "validApp",
2323
permissions = mapOf("administration" to "read", "contents" to "read", "metadata" to "read"),
24-
events = listOf("label", "public", "repository")
24+
events = listOf("label", "public", "repository", "push", "installation")
2525
)
2626
every { githubClient.getApp(any()) } returns githubApp
2727

@@ -41,7 +41,7 @@ class GitHubEnterpriseServiceTest {
4141
val response = GitHubAppResponse(
4242
slug = "validApp",
4343
permissions = mapOf("administration" to "read", "contents" to "read", "metadata" to "read"),
44-
events = listOf("label", "public", "repository")
44+
events = listOf("label", "public", "repository", "push", "installation")
4545
)
4646

4747
assertDoesNotThrow { service.validateGithubAppResponse(response) }

src/test/kotlin/net/leanix/githubagent/services/WebhookEventServiceTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,26 @@ class WebhookEventServiceTest {
345345
verify(exactly = 6) { cachingService.get("runId") }
346346
}
347347

348+
@Test
349+
fun `should ignore push events without a head commit`() {
350+
val payload = """{
351+
"repository": {
352+
"name": "repo",
353+
"full_name": "owner/repo",
354+
"owner": {"name": "owner"},
355+
"default_branch": "main"
356+
},
357+
"installation": {"id": 1},
358+
"ref": "refs/heads/main"
359+
}"""
360+
361+
webhookEventService.consumeWebhookEvent("PUSH", payload)
362+
363+
verify(exactly = 0) {
364+
webSocketService.sendMessage(any(), any())
365+
}
366+
}
367+
348368
@Test
349369
fun `should send the org to the backend when an new installation is created`() {
350370
val runId = UUID.randomUUID()

0 commit comments

Comments
 (0)