1
1
import { Change , Changes } from './schemas'
2
2
import { octokitClient } from './utils'
3
- import { parsePURL } from './purl'
3
+ import { parsePURL , PackageURL } from './purl'
4
4
import * as spdx from './spdx'
5
5
6
6
/**
@@ -36,34 +36,8 @@ export async function getInvalidLicenseChanges(
36
36
}
37
37
)
38
38
39
- const groupedChanges = await groupChanges ( changes )
39
+ const groupedChanges = await groupChanges ( changes , licenseExclusions )
40
40
41
- // Takes the changes from the groupedChanges object and filters out the ones that are part of the exclusions list
42
- // It does by creating a new PackageURL object from the change and comparing it to the exclusions list
43
- groupedChanges . licensed = groupedChanges . licensed . filter ( change => {
44
- if ( change . package_url . length === 0 ) {
45
- return true
46
- }
47
-
48
- const changeAsPackageURL = parsePURL ( encodeURI ( change . package_url ) )
49
-
50
- // We want to find if the licenseExclusion list contains the PackageURL of the Change
51
- // If it does, we want to filter it out and therefore return false
52
- // If it doesn't, we want to keep it and therefore return true
53
- if (
54
- licenseExclusions !== null &&
55
- licenseExclusions !== undefined &&
56
- licenseExclusions . findIndex (
57
- exclusion =>
58
- exclusion . type === changeAsPackageURL . type &&
59
- exclusion . name === changeAsPackageURL . name
60
- ) !== - 1
61
- ) {
62
- return false
63
- } else {
64
- return true
65
- }
66
- } )
67
41
const licensedChanges : Changes = groupedChanges . licensed
68
42
69
43
const invalidLicenseChanges : InvalidLicenseChanges = {
@@ -172,16 +146,47 @@ const truncatedDGLicense = (license: string): boolean =>
172
146
license . length === 255 && ! spdx . isValid ( license )
173
147
174
148
async function groupChanges (
175
- changes : Changes
149
+ changes : Changes ,
150
+ licenseExclusions : PackageURL [ ] | null = null
176
151
) : Promise < Record < string , Changes > > {
177
152
const result : Record < string , Changes > = {
178
153
licensed : [ ] ,
179
154
unlicensed : [ ]
180
155
}
181
156
157
+ let candidateChanges = changes
158
+
159
+ // If a package is excluded from license checking, we don't bother trying to
160
+ // fetch the license for it and we leave it off of the `licensed` and
161
+ // `unlicensed` lists.
162
+ if ( licenseExclusions !== null && licenseExclusions !== undefined ) {
163
+ candidateChanges = candidateChanges . filter ( change => {
164
+ if ( change . package_url . length === 0 ) {
165
+ return true
166
+ }
167
+
168
+ const changeAsPackageURL = parsePURL ( encodeURI ( change . package_url ) )
169
+
170
+ // We want to find if the licenseExclusion list contains the PackageURL of the Change
171
+ // If it does, we want to filter it out and therefore return false
172
+ // If it doesn't, we want to keep it and therefore return true
173
+ if (
174
+ licenseExclusions . findIndex (
175
+ exclusion =>
176
+ exclusion . type === changeAsPackageURL . type &&
177
+ exclusion . name === changeAsPackageURL . name
178
+ ) !== - 1
179
+ ) {
180
+ return false
181
+ } else {
182
+ return true
183
+ }
184
+ } )
185
+ }
186
+
182
187
const ghChanges = [ ]
183
188
184
- for ( const change of changes ) {
189
+ for ( const change of candidateChanges ) {
185
190
if ( change . change_type === 'removed' ) {
186
191
continue
187
192
}
0 commit comments