Skip to content

Commit

Permalink
fix(fossid-webapp): Generate ignore rules also for non-delta scans
Browse files Browse the repository at this point in the history
Generate ignore rules from path excludes in .ort.yml also if
FossID delta scans are disabled.

Signed-off-by: Wolfgang Klenk <[email protected]>
  • Loading branch information
wkl3nk authored and mnonnenmacher committed Jun 19, 2024
1 parent aa1a5a6 commit 9c7494f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
21 changes: 19 additions & 2 deletions plugins/scanners/fossid/src/main/kotlin/FossId.kt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class FossId internal constructor(
val (scanCode, scanId) = if (config.deltaScans) {
checkAndCreateDeltaScan(scans, url, revision, projectCode, projectName, context, issues)
} else {
checkAndCreateScan(scans, url, revision, projectCode, projectName)
checkAndCreateScan(scans, url, revision, projectCode, projectName, context, issues)
}

if (config.waitForResult && provenance is RepositoryProvenance) {
Expand Down Expand Up @@ -460,7 +460,9 @@ class FossId internal constructor(
url: String,
revision: String,
projectCode: String,
projectName: String
projectName: String,
context: ScanContext,
issues: MutableList<Issue>
): Pair<String, String> {
val existingScan = scans.recentScansForRepository(url, revision = revision).findLatestPendingOrFinishedScan()

Expand All @@ -475,6 +477,21 @@ class FossId internal constructor(
service.downloadFromGit(config.user, config.apiKey, scanCode)
.checkResponse("download data from Git", false)

val excludesRules = context.excludes?.let {
convertRules(it, issues).also {
logger.info { "${it.size} rule(s) from ORT excludes have been found." }
}
}.orEmpty()

excludesRules.forEach {
service.createIgnoreRule(config.user, config.apiKey, scanCode, it.type, it.value, RuleScope.SCAN)
.checkResponse("create ignore rules", false)

logger.info {
"Ignore rule of type '${it.type}' and value '${it.value}' has been created for the new scan."
}
}

scanCode to scanId
} else {
logger.info { "Scan '${existingScan.code}' found for $url and revision $revision." }
Expand Down
40 changes: 40 additions & 0 deletions plugins/scanners/fossid/src/test/kotlin/FossIdTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,46 @@ class FossIdTest : WordSpec({
}
}

"apply exclusion rules to a non-delta scan" {
val projectCode = projectCode(PROJECT)
val scanCode = scanCode(PROJECT, null)
val config = createConfig(deltaScans = false)
val vcsInfo = createVcsInfo()
val scan = createScan(vcsInfo.url, "${vcsInfo.revision}_other", scanCode)

val service = FossIdRestService.create(config.serverUrl)
.expectProjectRequest(projectCode)
.expectListScans(projectCode, listOf(scan))
.expectCheckScanStatus(scanCode, ScanStatus.NEW, ScanStatus.FINISHED)
.expectCreateScan(projectCode, scanCode, vcsInfo, "")
.expectDownload(scanCode)
.expectCreateIgnoreRule(scanCode, IGNORE_RULE.type, IGNORE_RULE.value, DEFAULT_IGNORE_RULE_SCOPE)
.mockFiles(scanCode, identifiedRange = 1..2, markedRange = 1..2)
coEvery { service.runScan(any()) } returns EntityResponseBody(status = 1)

val fossId = createFossId(config)

fossId.scan(
createPackage(createIdentifier(index = 1), vcsInfo),
mapOf(FossId.PROJECT_REVISION_LABEL to ""),
Excludes(listOf(PathExclude("*.docx", PathExcludeReason.OTHER)))
)

coVerify {
service.createScan(USER, API_KEY, projectCode, scanCode, vcsInfo.url, vcsInfo.revision)
service.downloadFromGit(USER, API_KEY, scanCode)
service.checkDownloadStatus(USER, API_KEY, scanCode)
service.createIgnoreRule(
USER,
API_KEY,
scanCode,
IGNORE_RULE.type,
IGNORE_RULE.value,
DEFAULT_IGNORE_RULE_SCOPE
)
}
}

"delete newly triggered scans if a package cannot be scanned" {
val id1 = createIdentifier(index = 1)
val vcsInfo1 = createVcsInfo()
Expand Down

0 comments on commit 9c7494f

Please sign in to comment.