Skip to content

Commit 0c6f920

Browse files
CID-3369: merge main
2 parents 6091908 + 3c57f0a commit 0c6f920

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
}
1212

1313
group = "net.leanix"
14-
version = "v0.0.2"
14+
version = "v0.0.3"
1515

1616
java {
1717
toolchain {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package net.leanix.githubagent.config
2+
3+
import org.springframework.context.annotation.Configuration
4+
import org.springframework.context.annotation.Profile
5+
import org.springframework.scheduling.annotation.EnableAsync
6+
7+
@Profile("!test")
8+
@EnableAsync
9+
@Configuration
10+
class AsyncConfig

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class GitHubScanningService(
7272
return installations
7373
}
7474

75-
private fun fetchAndSendOrganisationsData(
75+
fun fetchAndSendOrganisationsData(
7676
installations: List<Installation>
7777
) {
7878
if (installations.isEmpty()) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class WebhookEventService(
9191
installation.events
9292
)
9393
gitHubAuthenticationService.refreshTokens()
94+
gitHubScanningService.fetchAndSendOrganisationsData(listOf(installation))
9495
gitHubScanningService.fetchAndSendRepositoriesData(installation).forEach { repository ->
9596
gitHubScanningService.fetchManifestFilesAndSend(installation, repository)
9697
}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ import io.mockk.every
55
import io.mockk.just
66
import io.mockk.runs
77
import io.mockk.verify
8+
import net.leanix.githubagent.client.GitHubClient
89
import net.leanix.githubagent.dto.ManifestFileAction
910
import net.leanix.githubagent.dto.ManifestFileUpdateDto
11+
import net.leanix.githubagent.dto.Organization
1012
import net.leanix.githubagent.shared.MANIFEST_FILE_NAME
1113
import org.junit.jupiter.api.BeforeEach
1214
import org.junit.jupiter.api.Test
1315
import org.springframework.beans.factory.annotation.Autowired
1416
import org.springframework.boot.test.context.SpringBootTest
1517
import org.springframework.test.context.ActiveProfiles
18+
import java.util.UUID
1619

1720
const val UNSUPPORTED_MANIFEST_EXTENSION = "leanix.yml"
1821

@@ -32,6 +35,9 @@ class WebhookEventServiceTest {
3235
@MockkBean
3336
private lateinit var gitHubAuthenticationService: GitHubAuthenticationService
3437

38+
@MockkBean
39+
private lateinit var gitHubClient: GitHubClient
40+
3541
@Autowired
3642
private lateinit var webhookEventService: WebhookEventService
3743

@@ -358,4 +364,34 @@ class WebhookEventServiceTest {
358364
webSocketService.sendMessage(any(), any())
359365
}
360366
}
367+
368+
@Test
369+
fun `should send the org to the backend when an new installation is created`() {
370+
val runId = UUID.randomUUID()
371+
every { cachingService.get("runId") } returnsMany listOf("value", null, runId)
372+
every { cachingService.set("runId", any(), any()) } just runs
373+
every { cachingService.remove("runId") } just runs
374+
every { gitHubClient.getOrganizations(any()) } returns listOf(Organization("testOrganization", 1))
375+
376+
val eventType = "INSTALLATION"
377+
val payload = """{
378+
"action": "created",
379+
"installation": {
380+
"id": 30,
381+
"account": {
382+
"login": "test-org",
383+
"id": 20
384+
}
385+
}
386+
}"""
387+
388+
webhookEventService.consumeWebhookEvent(eventType, payload)
389+
390+
verify {
391+
webSocketService.sendMessage(
392+
"$runId/organizations",
393+
any()
394+
)
395+
}
396+
}
361397
}

0 commit comments

Comments
 (0)