Skip to content

Commit

Permalink
Separate function to better replicate old logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lumaxis authored Jun 24, 2024
1 parent b5a0d38 commit 202b854
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions providers/summary/scancode/new-summarizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class ScanCodeNewSummarizer {
return joinExpressions(fullLicenses)
}

_getClosestLicenseMatchByFileName(files, coordinates, licenseClarityScoreThreshold = 90) {
_getClosestLicenseMatchByFileName(files, coordinates) {
const fullLicenses = files
.filter(file => isLicenseFile(file.path, coordinates) && file.license_detections)
.reduce((licenses, file) => {
Expand All @@ -129,7 +129,8 @@ class ScanCodeNewSummarizer {
return
}
licenseDetection.matches.forEach(match => {
if (match.score >= licenseClarityScoreThreshold) {
// Only consider matches with high clarity score of 90 or higher
if (match.score >= 90) {
licenses.add(match.spdx_license_expression)
}
})
Expand All @@ -139,6 +140,23 @@ class ScanCodeNewSummarizer {
return joinExpressions(fullLicenses)
}

_getLicenseExpressionFromFileLicenseDetections(file) {
const licenseExpressions = file.license_detections.reduce((licenseExpressions, licenseDetection) => {
if (licenseDetection.license_expression_spdx) {
licenseExpressions.add(licenseDetection.license_expression_spdx)
} else {
licenseDetection.matches.forEach(match => {
// Only consider matches with a reasonably high score of 80 or higher
if (match.score >= 80) {
licenseExpressions.add(match.spdx_license_expression)
}
})
}
return licenseExpressions
}, new Set())
return joinExpressions(licenseExpressions)
}

_summarizeFileInfo(files, coordinates) {
return files
.map(file => {
Expand All @@ -147,7 +165,7 @@ class ScanCodeNewSummarizer {
const result = { path: file.path }

const licenseExpression =
file.detected_license_expression_spdx || this._getClosestLicenseMatchByFileName([file], coordinates, 80)
file.detected_license_expression_spdx || this._getLicenseExpressionFromFileLicenseDetections(file)
setIfValue(result, 'license', licenseExpression)

if (
Expand Down

0 comments on commit 202b854

Please # to comment.