Skip to content

Commit b793587

Browse files
authored
Merge pull request #71 from leanix/feature/CID-3400/skip-manifests-for-archived-repos
CID-3400 Skip manifest files for archived repositories
2 parents 70dafc9 + d9569a5 commit b793587

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class GitHubScanningService(
123123
}
124124

125125
fun fetchManifestFilesAndSend(installation: Installation, repository: RepositoryDto) {
126+
if (repository.archived) return
126127
val manifestFiles = fetchManifestFiles(installation, repository.name).getOrThrow().items
127128
val manifestFilesContents = fetchManifestContents(
128129
installation,

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,59 @@ class GitHubScanningServiceTest {
187187
verify { syncLogService.sendInfoLog("Finished full scan for all available organizations.") }
188188
}
189189

190+
@Test
191+
fun `scanGitHubResources should not send repositories and manifest files over WebSocket for archived repos`() {
192+
// given
193+
every { cachingService.get("runId") } returns runId
194+
every { gitHubGraphQLService.getRepositories(any(), any()) } returns PagedRepositories(
195+
repositories = listOf(
196+
RepositoryDto(
197+
id = "repo1",
198+
name = "TestRepo",
199+
organizationName = "testOrg",
200+
description = "A test repository",
201+
url = "https://github.com/testRepo",
202+
defaultBranch = "main",
203+
archived = true,
204+
visibility = RepositoryVisibility.PUBLIC,
205+
updatedAt = "2024-01-01T00:00:00Z",
206+
languages = listOf("Kotlin", "Java"),
207+
topics = listOf("test", "example"),
208+
)
209+
),
210+
hasNextPage = false,
211+
cursor = null
212+
)
213+
every { gitHubClient.searchManifestFiles(any(), any()) } returns GitHubSearchResponse(
214+
1,
215+
listOf(
216+
ItemResponse(
217+
name = "leanix.yaml",
218+
path = "dir/leanix.yaml",
219+
repository = RepositoryItemResponse(
220+
name = "TestRepo",
221+
fullName = "testOrg/TestRepo"
222+
),
223+
url = "http://url"
224+
)
225+
)
226+
)
227+
every { gitHubGraphQLService.getManifestFileContent(any(), any(), "dir/leanix.yaml", any()) } returns "content"
228+
229+
// when
230+
gitHubScanningService.scanGitHubResources()
231+
232+
// then
233+
verify(exactly = 0) { webSocketService.sendMessage(eq("$runId/manifestFiles"), any()) }
234+
verify(exactly = 0) { syncLogService.sendInfoLog("Scanning repository TestRepo for manifest files.") }
235+
verify(
236+
exactly = 0
237+
) { syncLogService.sendInfoLog("Fetched manifest file 'dir/leanix.yaml' from repository 'TestRepo'.") }
238+
verify(exactly = 0) { syncLogService.sendInfoLog("Found 1 manifest files in repository TestRepo.") }
239+
verify { syncLogService.sendInfoLog("Finished initial full scan for organization testInstallation.") }
240+
verify { syncLogService.sendInfoLog("Finished full scan for all available organizations.") }
241+
}
242+
190243
@Test
191244
fun `scanGitHubResources should send manifest files with empty path if the file is in the root directory`() {
192245
// given

0 commit comments

Comments
 (0)