Skip to content

Commit c3bac27

Browse files
Merge pull request #64 from leanix/feature/cid-3370-send-org-in-new-installation
cid-3370: Add call to send org when a new installation happens
2 parents d2b3bd4 + 9121950 commit c3bac27

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class GitHubScanningService(
5050
return installations
5151
}
5252

53-
private fun fetchAndSendOrganisationsData(
53+
fun fetchAndSendOrganisationsData(
5454
installations: List<Installation>
5555
) {
5656
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
@@ -82,6 +82,7 @@ class WebhookEventService(
8282
Account(installationEventPayload.installation.account.login)
8383
)
8484
gitHubAuthenticationService.refreshTokens()
85+
gitHubScanningService.fetchAndSendOrganisationsData(listOf(installation))
8586
gitHubScanningService.fetchAndSendRepositoriesData(installation).forEach { repository ->
8687
gitHubScanningService.fetchManifestFilesAndSend(installation, repository)
8788
}

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)