Skip to content

Commit

Permalink
Fix declared license not in discovered license for certain cases
Browse files Browse the repository at this point in the history
In some cases, CD (scancode summarizer) goes through the root files to
derive license information.  file.licenses is an array of licenses with
varying matching scores.  Currently, after the license file is found,
we concat all the license expressions as declared license (even though
some of them have low matching scores).  However, when the licenses are
tallied from the files, those licenses with score lower than 80 are
filtered out.  This inconsistency causes the declared license does not
show up in the discovered license (>80 score) in some cases.

Refactor the logic, so that only license score above 80 is considered
for declared license.

Test case:
https://clearlydefined.io/definitions/composer/packagist/colinmollenhour/cache-backend-redis/1.14.4
  • Loading branch information
qtomlinson committed Oct 10, 2023
1 parent c2b020d commit c9ea150
Show file tree
Hide file tree
Showing 3 changed files with 2,194 additions and 3 deletions.
12 changes: 9 additions & 3 deletions providers/summary/scancode.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class ScanCodeSummarizer {
const fullLicenses = files
.filter(file => file.is_license_text && file.licenses)
.reduce((licenses, file) => {
file.licenses.forEach(license => {
licenses.add(this._createExpressionFromLicense(license))
file.licenses.forEach((license) => {
if (this._isMatchedLicense(license)) licenses.add(this._createExpressionFromLicense(license))
})
return licenses
}, new Set())
Expand Down Expand Up @@ -169,7 +169,9 @@ class ScanCodeSummarizer {
const fileLicense = asserted || file.licenses || []
let licenses = new Set(fileLicense.map(x => x.license).filter(x => x))
if (!licenses.size)
licenses = new Set(fileLicense.filter(x => x.score >= 80).map(x => this._createExpressionFromLicense(x)))
licenses = new Set(
fileLicense.filter((x) => this._isMatchedLicense(x)).map((x) => this._createExpressionFromLicense(x))
)
const licenseExpression = this._joinExpressions(licenses)
setIfValue(result, 'license', licenseExpression)
if (this._getLicenseByIsLicenseText([file]) || this._getLicenseByFileName([file], coordinates)) {
Expand All @@ -187,6 +189,10 @@ class ScanCodeSummarizer {
.filter(e => e)
}

_isMatchedLicense(license) {
return license.score >= 80
}

_joinExpressions(expressions) {
if (!expressions) return null
const list = setToArray(expressions)
Expand Down
Loading

0 comments on commit c9ea150

Please # to comment.