Skip to content

Commit

Permalink
CID-3369: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedlajmileanix committed Jan 2, 2025
2 parents 6091908 + 3c57f0a commit 0c6f920
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = "net.leanix"
version = "v0.0.2"
version = "v0.0.3"

java {
toolchain {
Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/net/leanix/githubagent/config/AsyncConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.leanix.githubagent.config

import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile
import org.springframework.scheduling.annotation.EnableAsync

@Profile("!test")
@EnableAsync
@Configuration
class AsyncConfig
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class GitHubScanningService(
return installations
}

private fun fetchAndSendOrganisationsData(
fun fetchAndSendOrganisationsData(
installations: List<Installation>
) {
if (installations.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class WebhookEventService(
installation.events
)
gitHubAuthenticationService.refreshTokens()
gitHubScanningService.fetchAndSendOrganisationsData(listOf(installation))
gitHubScanningService.fetchAndSendRepositoriesData(installation).forEach { repository ->
gitHubScanningService.fetchManifestFilesAndSend(installation, repository)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import io.mockk.every
import io.mockk.just
import io.mockk.runs
import io.mockk.verify
import net.leanix.githubagent.client.GitHubClient
import net.leanix.githubagent.dto.ManifestFileAction
import net.leanix.githubagent.dto.ManifestFileUpdateDto
import net.leanix.githubagent.dto.Organization
import net.leanix.githubagent.shared.MANIFEST_FILE_NAME
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
import java.util.UUID

const val UNSUPPORTED_MANIFEST_EXTENSION = "leanix.yml"

Expand All @@ -32,6 +35,9 @@ class WebhookEventServiceTest {
@MockkBean
private lateinit var gitHubAuthenticationService: GitHubAuthenticationService

@MockkBean
private lateinit var gitHubClient: GitHubClient

@Autowired
private lateinit var webhookEventService: WebhookEventService

Expand Down Expand Up @@ -358,4 +364,34 @@ class WebhookEventServiceTest {
webSocketService.sendMessage(any(), any())
}
}

@Test
fun `should send the org to the backend when an new installation is created`() {
val runId = UUID.randomUUID()
every { cachingService.get("runId") } returnsMany listOf("value", null, runId)
every { cachingService.set("runId", any(), any()) } just runs
every { cachingService.remove("runId") } just runs
every { gitHubClient.getOrganizations(any()) } returns listOf(Organization("testOrganization", 1))

val eventType = "INSTALLATION"
val payload = """{
"action": "created",
"installation": {
"id": 30,
"account": {
"login": "test-org",
"id": 20
}
}
}"""

webhookEventService.consumeWebhookEvent(eventType, payload)

verify {
webSocketService.sendMessage(
"$runId/organizations",
any()
)
}
}
}

0 comments on commit 0c6f920

Please sign in to comment.