Skip to content

Commit e36c65b

Browse files
CID-3745: Handle Repository Transfer Events
1 parent 7aed232 commit e36c65b

File tree

4 files changed

+2
-176
lines changed

4 files changed

+2
-176
lines changed

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

Lines changed: 0 additions & 40 deletions
This file was deleted.

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
44
import com.fasterxml.jackson.module.kotlin.readValue
55
import net.leanix.githubagent.client.GitHubClient
66
import net.leanix.githubagent.dto.InstallationEventPayload
7-
import net.leanix.githubagent.dto.InstallationRepositoriesEventPayload
87
import net.leanix.githubagent.dto.ManifestFileAction
98
import net.leanix.githubagent.dto.ManifestFileUpdateDto
109
import net.leanix.githubagent.dto.PushEventCommit
1110
import net.leanix.githubagent.dto.PushEventPayload
12-
import net.leanix.githubagent.dto.toInstallation
1311
import net.leanix.githubagent.exceptions.JwtTokenNotFound
1412
import net.leanix.githubagent.shared.INSTALLATION_LABEL
15-
import net.leanix.githubagent.shared.INSTALLATION_REPOSITORIES
1613
import net.leanix.githubagent.shared.MANIFEST_FILE_NAME
1714
import net.leanix.githubagent.shared.fileNameMatchRegex
1815
import net.leanix.githubagent.shared.generateFullPath
@@ -31,8 +28,7 @@ class WebhookEventService(
3128
private val syncLogService: SyncLogService,
3229
@Value("\${webhookEventService.waitingTime}") private val waitingTime: Long,
3330
private val gitHubClient: GitHubClient,
34-
private val gitHubEnterpriseService: GitHubEnterpriseService,
35-
private val gitHubRepositoryService: GitHubRepositoryService,
31+
private val gitHubEnterpriseService: GitHubEnterpriseService
3632
) {
3733

3834
private val logger = LoggerFactory.getLogger(WebhookEventService::class.java)
@@ -42,7 +38,6 @@ class WebhookEventService(
4238
when (eventType.uppercase()) {
4339
"PUSH" -> handlePushEvent(payload)
4440
"INSTALLATION" -> handleInstallationEvent(payload)
45-
INSTALLATION_REPOSITORIES -> handleInstallationRepositories(payload)
4641
else -> {
4742
logger.info("Sending event of type: $eventType")
4843
webSocketService.sendMessage("/events/other/$eventType", payload)
@@ -207,22 +202,4 @@ class WebhookEventService(
207202
"root folder"
208203
}
209204
}
210-
211-
private val handleInstallationRepositories: (String) -> Unit = { payload ->
212-
logger.info("Handling installation repositories event")
213-
val installationRepositoriesEventPayload: InstallationRepositoriesEventPayload = objectMapper.readValue(payload)
214-
val installation = installationRepositoriesEventPayload.installation
215-
val installationToken = gitHubAuthenticationService.getInstallationToken(installation.id)
216-
217-
installationRepositoriesEventPayload.repositoriesAdded
218-
.forEach { repositoryAdded ->
219-
logger.info("Processing repository: ${repositoryAdded.fullName}")
220-
gitHubRepositoryService.fetchAndSendRepositoryAndManifest(
221-
installation.toInstallation(),
222-
repositoryAdded.name,
223-
repositoryAdded.fullName,
224-
installationToken
225-
)
226-
}
227-
}
228205
}

src/main/kotlin/net/leanix/githubagent/shared/Constants.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ const val APP_NAME_TOPIC = "appName"
55
const val LOGS_TOPIC = "logs"
66
const val MANIFEST_FILE_NAME = "leanix.yaml"
77
const val WORKFLOW_RUN_EVENT = "WORKFLOW_RUN"
8-
const val INSTALLATION_REPOSITORIES = "INSTALLATION_REPOSITORIES"
98

109
val SUPPORTED_EVENT_TYPES = listOf(
1110
"REPOSITORY",
1211
"PUSH",
1312
"ORGANIZATION",
1413
"INSTALLATION",
15-
WORKFLOW_RUN_EVENT,
16-
INSTALLATION_REPOSITORIES
14+
WORKFLOW_RUN_EVENT
1715
)
1816

1917
val fileNameMatchRegex = Regex("/?$MANIFEST_FILE_NAME\$", RegexOption.IGNORE_CASE)

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

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
package net.leanix.githubagent.services
22

33
import com.ninjasquad.springmockk.MockkBean
4-
import com.ninjasquad.springmockk.SpykBean
54
import io.mockk.every
65
import io.mockk.just
76
import io.mockk.runs
87
import io.mockk.verify
98
import net.leanix.githubagent.client.GitHubClient
109
import net.leanix.githubagent.dto.Account
11-
import net.leanix.githubagent.dto.GitHubSearchResponse
1210
import net.leanix.githubagent.dto.Installation
1311
import net.leanix.githubagent.dto.ItemResponse
1412
import net.leanix.githubagent.dto.ManifestFileAction
1513
import net.leanix.githubagent.dto.ManifestFileUpdateDto
1614
import net.leanix.githubagent.dto.Organization
17-
import net.leanix.githubagent.dto.RepositoryDto
1815
import net.leanix.githubagent.dto.RepositoryItemResponse
19-
import net.leanix.githubagent.graphql.data.enums.RepositoryVisibility
20-
import net.leanix.githubagent.shared.INSTALLATION_REPOSITORIES
2116
import net.leanix.githubagent.shared.MANIFEST_FILE_NAME
2217
import org.junit.jupiter.api.BeforeEach
2318
import org.junit.jupiter.api.Test
@@ -53,9 +48,6 @@ class WebhookEventServiceTest {
5348
@MockkBean
5449
private lateinit var gitHubAPIService: GitHubAPIService
5550

56-
@SpykBean
57-
private lateinit var syncLogService: SyncLogService
58-
5951
private val permissions = mapOf("administration" to "read", "contents" to "read", "metadata" to "read")
6052
private val events = listOf("label", "public", "repository", "push")
6153

@@ -495,107 +487,6 @@ class WebhookEventServiceTest {
495487
}
496488
}
497489

498-
@Test
499-
fun `should handle installation repositories event`() {
500-
every { syncLogService.sendSyncLog(any(), any(), any(), any()) } just runs
501-
every { gitHubGraphQLService.getRepository(any(), any(), any()) } returns RepositoryDto(
502-
id = "1",
503-
name = "repo",
504-
organizationName = "owner/repo",
505-
description = "main",
506-
url = "content",
507-
defaultBranch = "main",
508-
archived = false,
509-
visibility = RepositoryVisibility.PRIVATE,
510-
languages = emptyList(),
511-
topics = emptyList(),
512-
updatedAt = "2021-09-01"
513-
)
514-
every { gitHubClient.searchManifestFiles(any(), any()) } returnsMany listOf(
515-
GitHubSearchResponse(
516-
2,
517-
listOf(
518-
createItemResponse("repo-test", "cider-org-3"),
519-
createItemResponse("repo-test", "cider-org-3")
520-
)
521-
),
522-
GitHubSearchResponse(
523-
3,
524-
listOf(
525-
createItemResponse("demo-repo-1", "cider-org-3"),
526-
createItemResponse("demo-repo-1", "cider-org-3")
527-
)
528-
)
529-
)
530-
531-
val payload = """
532-
{
533-
"action": "added",
534-
"installation": {
535-
"id": 150,
536-
"account": {
537-
"login": "cider-org-3",
538-
"id": 47
539-
},
540-
"repository_selection": "selected",
541-
"access_tokens_url": "https://cider-gh-enterprise.northeurope.cloudapp.azure.com/api/v3/app/installations/150/access_tokens",
542-
"repositories_url": "https://cider-gh-enterprise.northeurope.cloudapp.azure.com/api/v3/installation/repositories",
543-
"html_url": "https://cider-gh-enterprise.northeurope.cloudapp.azure.com/organizations/cider-org-3/settings/installations/150",
544-
"app_id": 3,
545-
"app_slug": "test-github-app",
546-
"target_id": 47,
547-
"target_type": "Organization",
548-
"permissions": {
549-
"checks": "write",
550-
"members": "read",
551-
"contents": "read",
552-
"metadata": "read",
553-
"administration": "read"
554-
},
555-
"events": [
556-
"check_run",
557-
"check_suite",
558-
"label",
559-
"organization",
560-
"public",
561-
"push",
562-
"repository"
563-
]
564-
},
565-
"repository_selection": "selected",
566-
"repositories_added": [
567-
{
568-
"id": 30,
569-
"node_id": "MDEwOlJlcG9zaXRvcnkzMA==",
570-
"name": "repo-test",
571-
"full_name": "cider-org-3/kostas-test",
572-
"private": true
573-
},
574-
{
575-
"id": 1648,
576-
"node_id": "MDEwOlJlcG9zaXRvcnkxNjQ4",
577-
"name": "demo-repo-1",
578-
"full_name": "cider-org-3/demo-repo-1",
579-
"private": true
580-
},
581-
{
582-
"id": 1649,
583-
"node_id": "MDEwOlJlcG9zaXRvcnkxNjQ5",
584-
"name": "demo-repo-2",
585-
"full_name": "cider-org-3/demo-repo-2",
586-
"private": true
587-
}
588-
],
589-
"repositories_removed": []
590-
}
591-
"""
592-
593-
webhookEventService.consumeWebhookEvent(INSTALLATION_REPOSITORIES, payload)
594-
595-
verify(exactly = 3) { webSocketService.sendMessage("/events/repository", any()) }
596-
verify(exactly = 6) { webSocketService.sendMessage("/events/manifestFile", any()) }
597-
}
598-
599490
fun createItemResponse(repoName: String, organization: String): ItemResponse {
600491
return ItemResponse(
601492
MANIFEST_FILE_NAME,

0 commit comments

Comments
 (0)