Skip to content

Commit f7aa322

Browse files
nnobelissschuberth
authored andcommitted
fix(fossid-webapp): Always create a new scan when delta scans are disabled
The current logic always tries to reuse the existing scans on the same branch if delta scans logic is disabled. This is incorrect as the code in the repository for this branch may have changed (rolling revision). This commit enforces that a new scan is always created when delta scans are disabled. Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
1 parent a2ab0b2 commit f7aa322

File tree

3 files changed

+20
-73
lines changed

3 files changed

+20
-73
lines changed

plugins/scanners/fossid/src/main/kotlin/FossId.kt

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,7 @@ class FossId internal constructor(
304304
val result = if (config.deltaScans) {
305305
checkAndCreateDeltaScan(handler, scans, url, revision, projectCode, repositoryName, context)
306306
} else {
307-
checkAndCreateScan(
308-
handler,
309-
scans,
310-
url,
311-
revision,
312-
projectCode,
313-
repositoryName,
314-
nestedProvenance,
315-
context
316-
)
307+
checkAndCreateScan(handler, url, revision, projectCode, repositoryName, context)
317308
}
318309

319310
if (config.waitForResult && provenance is RepositoryProvenance) {
@@ -501,12 +492,10 @@ class FossId internal constructor(
501492
@Suppress("LongParameterList")
502493
private suspend fun checkAndCreateScan(
503494
handler: EventHandler,
504-
scans: List<Scan>,
505495
url: String,
506496
revision: String,
507497
projectCode: String,
508498
projectName: String,
509-
nestedProvenance: NestedProvenance?,
510499
context: ScanContext
511500
): FossIdResult {
512501
val projectRevision = context.labels[PROJECT_REVISION_LABEL]
@@ -517,41 +506,18 @@ class FossId internal constructor(
517506
logger.info { "Project revision is '$projectRevision'." }
518507
}
519508

520-
val existingScan = scans.recentScansForRepository(
521-
url,
522-
revision = revision,
523-
projectRevision = projectRevision
524-
).findLatestPendingOrFinishedScan()
525-
526-
val result = if (existingScan == null) {
527-
logger.info { "No scan found for $url and revision $revision. Creating scan..." }
509+
logger.info { "Creating scan for $url and revision $revision..." }
528510

529-
val scanCode = namingProvider.createScanCode(repositoryName = projectName, branch = revision)
530-
val newUrl = handler.transformURL(url)
531-
val scanId = createScan(handler, projectCode, scanCode, newUrl, revision, projectRevision.orEmpty())
511+
val scanCode = namingProvider.createScanCode(repositoryName = projectName, branch = revision)
512+
val newUrl = handler.transformURL(url)
513+
val scanId = createScan(handler, projectCode, scanCode, newUrl, revision, projectRevision.orEmpty())
532514

533-
val issues = mutableListOf<Issue>()
534-
handler.afterScanCreation(scanCode, null, issues, context)
535-
536-
if (config.waitForResult) checkScan(handler, scanCode)
537-
538-
FossIdResult(scanCode, scanId, issues)
539-
} else {
540-
logger.info { "Scan '${existingScan.code}' found for $url and revision $revision." }
541-
542-
val existingScanCode = requireNotNull(existingScan.code) {
543-
"The code for an existing scan must not be null."
544-
}
545-
546-
// Create a specific handler for the existing scan.
547-
val handlerForExistingScan = EventHandler.getHandler(existingScan, config, nestedProvenance, service)
548-
549-
if (config.waitForResult) checkScan(handlerForExistingScan, existingScan.code.orEmpty())
515+
val issues = mutableListOf<Issue>()
516+
handler.afterScanCreation(scanCode, null, issues, context)
550517

551-
FossIdResult(existingScanCode, existingScan.id.toString())
552-
}
518+
if (config.waitForResult) checkScan(handler, scanCode)
553519

554-
return result
520+
return FossIdResult(scanCode, scanId, issues)
555521
}
556522

557523
/**

plugins/scanners/fossid/src/main/kotlin/events/EventHandler.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,6 @@ interface EventHandler {
6666

6767
CloneRepositoryHandler(config, service)
6868
}
69-
70-
/**
71-
* Return an [EventHandler] based on the given [config], [nestedProvenance] and [service]. The handler is
72-
* tailored for the given [existingScan].
73-
*/
74-
fun getHandler(
75-
existingScan: Scan,
76-
config: FossIdConfig,
77-
nestedProvenance: NestedProvenance?,
78-
service: FossIdServiceWithVersion
79-
): EventHandler {
80-
// Create a specific handler for the existing scan, based on its configuration, not to the current scanner
81-
// configuration.
82-
val configForExistingScan = config.copy(isArchiveMode = existingScan.gitRepoUrl == null)
83-
return getHandler(configForExistingScan, nestedProvenance, service)
84-
}
8569
}
8670

8771
/**

plugins/scanners/fossid/src/test/kotlin/TestUtils.kt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -757,15 +757,13 @@ internal fun FossIdServiceWithVersion.expectUploadArchiveWorkflow(
757757
apply {
758758
expectProjectRequest(projectCode)
759759
expectListScans(projectCode, existingScans)
760-
// TODO: This should be done only if deltaScans is true, but currently the tests with delta scans disabled still
761-
// rely on existing scans.
762-
existingScans.forEach {
763-
it.code?.also { existingScanCode ->
764-
expectCheckScanStatus(existingScanCode, ScanStatus.FINISHED)
760+
if (deltaScans) {
761+
existingScans.forEach {
762+
it.code?.also { existingScanCode ->
763+
expectCheckScanStatus(existingScanCode, ScanStatus.FINISHED)
764+
}
765765
}
766-
}
767766

768-
if (deltaScans) {
769767
expectCheckScanStatus(scanCode, ScanStatus.NOT_STARTED, ScanStatus.FINISHED)
770768
} else {
771769
expectCheckScanStatus(scanCode, ScanStatus.FINISHED)
@@ -821,13 +819,12 @@ internal fun FossIdServiceWithVersion.expectCloneRepositoryWorkflow(
821819
apply {
822820
expectProjectRequest(projectCode)
823821
expectListScans(projectCode, existingScans)
824-
// TODO: This should be done only if deltaScans is true, but currently the tests with delta scans disabled still
825-
// rely on existing scans.
826-
827-
val resolvedExistingScanCode = existingScanCode ?: existingScans.takeIf { it.isNotEmpty() }?.last()?.code
828-
if (resolvedExistingScanCode != null) {
829-
expectCheckScanStatus(resolvedExistingScanCode, ScanStatus.FINISHED)
830-
expectListIgnoreRules(resolvedExistingScanCode, existingIgnoreRules)
822+
if (deltaScans) {
823+
val resolvedExistingScanCode = existingScanCode ?: existingScans.takeIf { it.isNotEmpty() }?.last()?.code
824+
if (resolvedExistingScanCode != null) {
825+
expectCheckScanStatus(resolvedExistingScanCode, ScanStatus.FINISHED)
826+
expectListIgnoreRules(resolvedExistingScanCode, existingIgnoreRules)
827+
}
831828
}
832829

833830
val statuses = checkScanStatuses ?: if (deltaScans) {

0 commit comments

Comments
 (0)