Skip to content

Commit 8a5b9b8

Browse files
CID-3590: Accept manifest files with case ignored
1 parent ea57a4c commit 8a5b9b8

File tree

5 files changed

+134
-5
lines changed

5 files changed

+134
-5
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
@@ -156,7 +156,7 @@ class GitHubScanningService(
156156
"repo:${installation.account.login}/$repositoryName filename:$MANIFEST_FILE_NAME"
157157
)
158158
}
159-
manifestFiles.items.filter { it.name == MANIFEST_FILE_NAME }
159+
manifestFiles.items.filter { it.name.lowercase() == MANIFEST_FILE_NAME }
160160
}
161161
private fun fetchManifestContents(
162162
installation: Installation,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ class WebhookEventService(
110110
repositoryName: String,
111111
installationToken: String
112112
) {
113-
val addedManifestFiles = headCommit.added.filter { isLeanixManifestFile(it) }
114-
val modifiedManifestFiles = headCommit.modified.filter { isLeanixManifestFile(it) }
115-
val removedManifestFiles = headCommit.removed.filter { isLeanixManifestFile(it) }
113+
val addedManifestFiles = headCommit.added.filter { isLeanixManifestFile(it.lowercase()) }
114+
val modifiedManifestFiles = headCommit.modified.filter { isLeanixManifestFile(it.lowercase()) }
115+
val removedManifestFiles = headCommit.removed.filter { isLeanixManifestFile(it.lowercase()) }
116116

117117
addedManifestFiles.forEach { filePath ->
118118
handleAddedOrModifiedManifestFile(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ val SUPPORTED_EVENT_TYPES = listOf(
1212
"INSTALLATION",
1313
)
1414

15-
val fileNameMatchRegex = Regex("/?$MANIFEST_FILE_NAME\$")
15+
val fileNameMatchRegex = Regex("/?$MANIFEST_FILE_NAME\$", RegexOption.IGNORE_CASE)
1616

1717
const val GITHUB_APP_LABEL = "GitHub App"
1818
const val INSTALLATION_LABEL = "Installation"

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,78 @@ class GitHubScanningServiceTest {
357357
verify(exactly = 1) { syncLogService.sendInfoLog("Found 2 manifest files in repository TestRepo.") }
358358
}
359359

360+
@Test
361+
fun `scanGitHubResources should accept manifest files with case ignored`() {
362+
// given
363+
every { cachingService.get("runId") } returns runId
364+
every { gitHubGraphQLService.getRepositories(any(), any()) } returns PagedRepositories(
365+
repositories = listOf(
366+
RepositoryDto(
367+
id = "repo1",
368+
name = "TestRepo",
369+
organizationName = "testOrg",
370+
description = "A test repository",
371+
url = "https://github.com/testRepo",
372+
defaultBranch = "main",
373+
archived = false,
374+
visibility = RepositoryVisibility.PUBLIC,
375+
updatedAt = "2024-01-01T00:00:00Z",
376+
languages = listOf("Kotlin", "Java"),
377+
topics = listOf("test", "example"),
378+
)
379+
),
380+
hasNextPage = false,
381+
cursor = null
382+
)
383+
every { gitHubClient.searchManifestFiles(any(), any()) } returns GitHubSearchResponse(
384+
1,
385+
listOf(
386+
ItemResponse(
387+
name = "leanIX.yaml",
388+
path = "leanIX.yaml",
389+
repository = RepositoryItemResponse(
390+
name = "TestRepo",
391+
fullName = "testOrg/TestRepo"
392+
),
393+
url = "http://url"
394+
),
395+
ItemResponse(
396+
name = "lEAnIX.yaml",
397+
path = "a/lEAnIX.yaml",
398+
repository = RepositoryItemResponse(
399+
name = "TestRepo",
400+
fullName = "testOrg/TestRepo"
401+
),
402+
url = "http://url"
403+
),
404+
ItemResponse(
405+
name = MANIFEST_FILE_NAME,
406+
path = "b/$MANIFEST_FILE_NAME",
407+
repository = RepositoryItemResponse(
408+
name = "TestRepo",
409+
fullName = "testOrg/TestRepo"
410+
),
411+
url = "http://url"
412+
)
413+
)
414+
)
415+
every {
416+
gitHubGraphQLService.getManifestFileContent(any(), any(), "b/leanix.yaml", any())
417+
} returns "content"
418+
every {
419+
gitHubGraphQLService.getManifestFileContent(any(), any(), "leanIX.yaml", any())
420+
} returns "content"
421+
every {
422+
gitHubGraphQLService.getManifestFileContent(any(), any(), "a/lEAnIX.yaml", any())
423+
} returns "content"
424+
425+
// when
426+
gitHubScanningService.scanGitHubResources()
427+
428+
// then
429+
verify(exactly = 1) { syncLogService.sendInfoLog("Found 3 manifest files in repository TestRepo.") }
430+
}
431+
360432
@Test
361433
fun `scanGitHubResources should skip organizations without correct permissions and events`() {
362434
every { cachingService.get("runId") } returns runId

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,63 @@ class WebhookEventServiceTest {
163163
}
164164
}
165165

166+
@Test
167+
fun `should accept manifest files with case ignore`() {
168+
val payload = """{
169+
"repository": {
170+
"name": "repo",
171+
"full_name": "owner/repo",
172+
"owner": {"name": "owner"},
173+
"default_branch": "main"
174+
},
175+
"head_commit": {
176+
"added": [],
177+
"modified": ["a/$MANIFEST_FILE_NAME", "b/leanIX.yaml", "LEanIX.yaml"],
178+
"removed": []
179+
},
180+
"installation": {"id": 1},
181+
"ref": "refs/heads/main"
182+
}"""
183+
184+
webhookEventService.consumeWebhookEvent("PUSH", payload)
185+
186+
verify(exactly = 1) {
187+
webSocketService.sendMessage(
188+
"/events/manifestFile",
189+
ManifestFileUpdateDto(
190+
"owner/repo",
191+
ManifestFileAction.MODIFIED,
192+
"content",
193+
"tree/main/b"
194+
)
195+
)
196+
}
197+
198+
verify(exactly = 1) {
199+
webSocketService.sendMessage(
200+
"/events/manifestFile",
201+
ManifestFileUpdateDto(
202+
"owner/repo",
203+
ManifestFileAction.MODIFIED,
204+
"content",
205+
"tree/main/a"
206+
)
207+
)
208+
}
209+
210+
verify(exactly = 1) {
211+
webSocketService.sendMessage(
212+
"/events/manifestFile",
213+
ManifestFileUpdateDto(
214+
"owner/repo",
215+
ManifestFileAction.MODIFIED,
216+
"content",
217+
""
218+
)
219+
)
220+
}
221+
}
222+
166223
@Test
167224
fun `should send all events of type other than push to backend without processing`() {
168225
val payload = """{

0 commit comments

Comments
 (0)