Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCP-55 Adds extra info into licenses output #5

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/services/result.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type ScannerResults = Record<string, ScannerComponent[] | DependencyComponent[]>

export enum ComponentID {

Check failure on line 3 in src/services/result.interfaces.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

'ComponentID' is already declared in the upper scope on line 3 column 13

Check failure on line 3 in src/services/result.interfaces.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

'ComponentID' is already declared in the upper scope on line 3 column 13
NONE = 'none',
FILE = 'file',
SNIPPET = 'snippet',
Expand Down Expand Up @@ -49,6 +49,7 @@
osadl_updated: string
source: string
incompatible_with?: string
url: string
}[]
dependencies: {
vendor: string
Expand All @@ -74,7 +75,7 @@
score: string
source: string
}[]
cryptography: any[]

Check failure on line 78 in src/services/result.interfaces.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Unexpected any. Specify a different type

Check failure on line 78 in src/services/result.interfaces.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Unexpected any. Specify a different type
health: {
creation_date: string
issues: number
Expand Down
40 changes: 30 additions & 10 deletions src/services/result.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,47 @@ export async function readResult(filepath: string): Promise<ScannerResults> {
return JSON.parse(content) as ScannerResults
}

export function getLicenses(results: ScannerResults): string[] {
const licenses = new Set<string>()
export interface Licenses {
spdxid: string
copyleft: boolean | null
url: string | null
}

export function getLicenses(results: ScannerResults): Licenses[] {
const licenses = new Array<Licenses>()

for (const component of Object.values(results)) {
for (const c of component) {
if (c.id === ComponentID.FILE || c.id === ComponentID.SNIPPET) {
for (const l of (c as ScannerComponent).licenses) {
licenses.push({
spdxid: l.name,
copyleft: !l.copyleft ? null : l.copyleft === 'yes' ? true : false,
url: l?.url ? l.url : null
})
}
}

if (c.id === ComponentID.DEPENDENCY) {
const dependencies = (c as DependencyComponent).dependencies
for (const d of dependencies) {
for (const l of d.licenses) {
licenses.add(l.spdx_id)
if (!l.spdx_id) continue
licenses.push({ spdxid: l.spdx_id, copyleft: null, url: null })
}
}
}

if (c.id === ComponentID.FILE || c.id === ComponentID.SNIPPET) {
for (const l of (c as ScannerComponent).licenses) {
licenses.add(l.name)
}
}
}
}

return Array.from(licenses)
const seenSpdxIds = new Set<string>()
const uniqueLicenses = licenses.filter(license => {
if (!seenSpdxIds.has(license.spdxid)) {
seenSpdxIds.add(license.spdxid)
return true
}
return false
})

return uniqueLicenses
}
Loading
Loading