From b0d125871c46aadf024353ad8a7856eb9ce295da Mon Sep 17 00:00:00 2001 From: Franco Stramana Date: Tue, 27 Feb 2024 14:00:25 -0300 Subject: [PATCH] SCT-141 Changes PR report --- __tests__/report-service.test.ts | 684 +++++++++++++++++++++++++++++-- dist/index.js | 34 +- src/main.ts | 4 +- src/services/report.service.ts | 32 +- 4 files changed, 690 insertions(+), 64 deletions(-) diff --git a/__tests__/report-service.test.ts b/__tests__/report-service.test.ts index 816e323..668c8c3 100644 --- a/__tests__/report-service.test.ts +++ b/__tests__/report-service.test.ts @@ -1,38 +1,668 @@ -import { getLicensesTable } from '../src/services/report.service'; +import * as github from '@actions/github'; -const licenseTableTest = [ +import { generatePRSummary } from '../src/services/report.service'; + +const tableTest = [ { name: '1) report test', - licenses: [{ spdxid: 'MIT', url: null, copyleft: true, count: 1 }], - output: '| License | Copyleft | URL |\n| ------- | -------- | --- |\n| MIT | :x: | |\n' - }, - { - name: '2) report test', - licenses: [ - { spdxid: 'MIT', url: null, copyleft: null, count: 1 }, - { spdxid: 'Apache-2.0', url: null, copyleft: null, count: 1 }, - { spdxid: '0BSD', url: null, copyleft: null, count: 1 } - ], - output: - '| License | Copyleft | URL |\n| ------- | -------- | --- |\n| MIT | | |\n| Apache-2.0 | | |\n| 0BSD | | |\n' - }, - { - name: '3) report test', - licenses: [ - { spdxid: 'GPL-2.0-only', url: 'https://spdx.org/licenses/GPL-2.0-only.html', copyleft: true, count: 1 }, - { spdxid: 'GPL-2.0-or-later', url: 'https://spdx.org/licenses/GPL-2.0-or-later.html', copyleft: true, count: 1 }, - { spdxid: 'JSON', url: 'https://spdx.org/licenses/JSON.html', copyleft: null, count: 1 }, - { spdxid: 'LicenseRef-scancode-unknown-license-reference', url: null, copyleft: null, count: 1 } - ], - output: - '| License | Copyleft | URL |\n| ------- | -------- | --- |\n| GPL-2.0-only | :x: | https://spdx.org/licenses/GPL-2.0-only.html |\n| GPL-2.0-or-later | :x: | https://spdx.org/licenses/GPL-2.0-or-later.html |\n| JSON | | https://spdx.org/licenses/JSON.html |\n| LicenseRef-scancode-unknown-license-reference | | |\n' + scannerResults: `{ + "aaaaa.c": [ + { + "component": "engine", + "file": "cryptography.c", + "file_hash": "45931442719d401103ab8bcbbca1af99", + "file_url": "https://osskb.org/api/file_contents/45931442719d401103ab8bcbbca1af99", + "id": "snippet", + "latest": "5.3.5", + "licenses": [ + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "component_declared", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-or-later.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-or-later", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "file_spdx_tag", + "url": "https://spdx.org/licenses/GPL-2.0-or-later.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "license_file", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + } + ], + "lines": "1-37", + "matched": "97%", + "oss_lines": "33-69", + "purl": [ + "pkg:github/scanoss/engine" + ], + "release_date": "2022-09-26", + "server": { + "kb_version": { + "daily": "24.01.22", + "monthly": "23.12" + }, + "version": "5.3.5" + }, + "source_hash": "aefc7383cccb35ecf8994c49d17c69be", + "status": "pending", + "url": "https://github.com/scanoss/engine", + "url_hash": "d6492e2364b3b7793773edf28a372c75", + "vendor": "scanoss", + "version": "5.0.0" + } + ], + "attributions.c": [ + { + "component": "engine", + "file": "attributions.c", + "file_hash": "4dd9a878731a51b612fedde5ad5d6084", + "file_url": "https://osskb.org/api/file_contents/4dd9a878731a51b612fedde5ad5d6084", + "id": "file", + "latest": "5.3.4", + "licenses": [ + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "component_declared", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + }, + { + "name": "JSON", + "source": "scancode", + "url": "https://spdx.org/licenses/JSON.html" + }, + { + "name": "LicenseRef-scancode-unknown-license-reference", + "source": "scancode" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-or-later.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-or-later", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "scancode", + "url": "https://spdx.org/licenses/GPL-2.0-or-later.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-or-later.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-or-later", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "file_spdx_tag", + "url": "https://spdx.org/licenses/GPL-2.0-or-later.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "license_file", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + } + ], + "lines": "all", + "matched": "100%", + "oss_lines": "all", + "purl": [ + "pkg:github/scanoss/engine" + ], + "release_date": "2022-12-29", + "server": { + "kb_version": { + "daily": "24.01.22", + "monthly": "23.12" + }, + "version": "5.3.5" + }, + "source_hash": "4dd9a878731a51b612fedde5ad5d6084", + "status": "pending", + "url": "https://github.com/scanoss/engine", + "url_hash": "587fc14ceb8fdd57727a2ab98d707916", + "vendor": "scanoss", + "version": "5.1.1" + } + ], + "binary_scan.c": [ + { + "component": "engine", + "file": "binary_scan.c", + "file_hash": "0d27d55d1134cbdaa1536babdff219f5", + "file_url": "https://osskb.org/api/file_contents/0d27d55d1134cbdaa1536babdff219f5", + "id": "file", + "latest": "5.3.5", + "licenses": [ + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "component_declared", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-or-later.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-or-later", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "file_spdx_tag", + "url": "https://spdx.org/licenses/GPL-2.0-or-later.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-or-later.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-or-later", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "scancode", + "url": "https://spdx.org/licenses/GPL-2.0-or-later.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "license_file", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + } + ], + "lines": "all", + "matched": "100%", + "oss_lines": "all", + "purl": [ + "pkg:github/scanoss/engine" + ], + "release_date": "2022-12-29", + "server": { + "kb_version": { + "daily": "24.01.22", + "monthly": "23.12" + }, + "version": "5.3.5" + }, + "source_hash": "0d27d55d1134cbdaa1536babdff219f5", + "status": "pending", + "url": "https://github.com/scanoss/engine", + "url_hash": "587fc14ceb8fdd57727a2ab98d707916", + "vendor": "scanoss", + "version": "5.1.1" + } + ], + "component.c": [ + { + "component": "engine", + "file": "component.c", + "file_hash": "6852eb3bc69f70a15064645ad24446a2", + "file_url": "https://osskb.org/api/file_contents/6852eb3bc69f70a15064645ad24446a2", + "id": "file", + "latest": "5.3.5", + "licenses": [ + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "component_declared", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-or-later.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-or-later", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "file_spdx_tag", + "url": "https://spdx.org/licenses/GPL-2.0-or-later.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "license_file", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + } + ], + "lines": "all", + "matched": "100%", + "oss_lines": "all", + "purl": [ + "pkg:github/scanoss/engine" + ], + "release_date": "2023-06-05", + "server": { + "kb_version": { + "daily": "24.01.22", + "monthly": "23.12" + }, + "version": "5.3.5" + }, + "source_hash": "6852eb3bc69f70a15064645ad24446a2", + "status": "pending", + "url": "https://github.com/scanoss/engine", + "url_hash": "1170a6175564e85c6877886e5ca565b2", + "vendor": "scanoss", + "version": "5.2.6" + } + ], + "copyright.c": [ + { + "component": "engine", + "file": "copyright.c", + "file_hash": "e5965a5937743a78129b73b4171961e9", + "file_url": "https://osskb.org/api/file_contents/e5965a5937743a78129b73b4171961e9", + "id": "file", + "latest": "5.3.5", + "licenses": [ + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "component_declared", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-or-later.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-or-later", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "scancode", + "url": "https://spdx.org/licenses/GPL-2.0-or-later.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-or-later.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-or-later", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "file_spdx_tag", + "url": "https://spdx.org/licenses/GPL-2.0-or-later.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "license_file", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + } + ], + "lines": "all", + "matched": "100%", + "oss_lines": "all", + "purl": [ + "pkg:github/scanoss/engine" + ], + "release_date": "2022-12-29", + "server": { + "kb_version": { + "daily": "24.01.22", + "monthly": "23.12" + }, + "version": "5.3.5" + }, + "source_hash": "e5965a5937743a78129b73b4171961e9", + "status": "pending", + "url": "https://github.com/scanoss/engine", + "url_hash": "587fc14ceb8fdd57727a2ab98d707916", + "vendor": "scanoss", + "version": "5.1.1" + } + ], + "cryptography.c": [ + { + "component": "engine", + "file": "cryptography.c", + "file_hash": "45931442719d401103ab8bcbbca1af99", + "file_url": "https://osskb.org/api/file_contents/45931442719d401103ab8bcbbca1af99", + "id": "file", + "latest": "5.3.5", + "licenses": [ + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "component_declared", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-or-later.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-or-later", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "file_spdx_tag", + "url": "https://spdx.org/licenses/GPL-2.0-or-later.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "license_file", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + } + ], + "lines": "all", + "matched": "100%", + "oss_lines": "all", + "purl": [ + "pkg:github/scanoss/engine" + ], + "release_date": "2022-09-26", + "server": { + "kb_version": { + "daily": "24.01.22", + "monthly": "23.12" + }, + "version": "5.3.5" + }, + "source_hash": "45931442719d401103ab8bcbbca1af99", + "status": "pending", + "url": "https://github.com/scanoss/engine", + "url_hash": "d6492e2364b3b7793773edf28a372c75", + "vendor": "scanoss", + "version": "5.0.0" + } + ], + "debug.c": [ + { + "component": "engine", + "file": "debug.c", + "file_hash": "5adbcacf687f26596731900c07570673", + "file_url": "https://osskb.org/api/file_contents/5adbcacf687f26596731900c07570673", + "id": "file", + "latest": "5.3.4", + "licenses": [ + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "component_declared", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-or-later.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-or-later", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "file_spdx_tag", + "url": "https://spdx.org/licenses/GPL-2.0-or-later.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-or-later.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-or-later", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "scancode", + "url": "https://spdx.org/licenses/GPL-2.0-or-later.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "license_file", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + } + ], + "lines": "all", + "matched": "100%", + "oss_lines": "all", + "purl": [ + "pkg:github/scanoss/engine" + ], + "release_date": "2022-12-29", + "server": { + "kb_version": { + "daily": "24.01.22", + "monthly": "23.12" + }, + "version": "5.3.5" + }, + "source_hash": "5adbcacf687f26596731900c07570673", + "status": "pending", + "url": "https://github.com/scanoss/engine", + "url_hash": "587fc14ceb8fdd57727a2ab98d707916", + "vendor": "scanoss", + "version": "5.1.1" + } + ], + "decrypt.c": [ + { + "component": "engine", + "file": "decrypt.c", + "file_hash": "d954b45c05e338f1a9f56a93110cdae0", + "file_url": "https://osskb.org/api/file_contents/d954b45c05e338f1a9f56a93110cdae0", + "id": "file", + "latest": "5.3.5", + "licenses": [ + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "component_declared", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-or-later.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-or-later", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "file_spdx_tag", + "url": "https://spdx.org/licenses/GPL-2.0-or-later.html" + }, + { + "checklist_url": "https://www.osadl.org/fileadmin/checklists/unreflicenses/GPL-2.0-only.txt", + "copyleft": "yes", + "incompatible_with": "Apache-1.0,Apache-1.1,Apache-2.0,BSD-4-Clause,BSD-4-Clause-UC,FTL,IJG,OpenSSL,Python-2.0,zlib-acknowledgement,XFree86-1.1", + "name": "GPL-2.0-only", + "osadl_updated": "2024-01-21T05:27:00+00:00", + "patent_hints": "yes", + "source": "license_file", + "url": "https://spdx.org/licenses/GPL-2.0-only.html" + } + ], + "lines": "all", + "matched": "100%", + "oss_lines": "all", + "purl": [ + "pkg:github/scanoss/engine" + ], + "release_date": "2022-09-26", + "server": { + "kb_version": { + "daily": "24.01.22", + "monthly": "23.12" + }, + "version": "5.3.5" + }, + "source_hash": "d954b45c05e338f1a9f56a93110cdae0", + "status": "pending", + "url": "https://github.com/scanoss/engine", + "url_hash": "d6492e2364b3b7793773edf28a372c75", + "vendor": "scanoss", + "version": "5.0.0" + } + ], + "no-match.c": [ + { + "id": "none", + "server": { + "kb_version": { + "daily": "24.01.22", + "monthly": "23.12" + }, + "version": "5.3.5" + } + } + ], + "requirements.txt": [ + { + "dependencies": [ + { + "component": "requests", + "licenses": [ + { + "is_spdx_approved": true, + "name": "Apache2.0", + "spdx_id": "Apache-2.0" + } + ], + "purl": "pkg:pypi/requests", + "url": "https://pypi.org/project/requests", + "version": "2.31.0" + }, + { + "licenses": [ + {} + ], + "purl": "pkg:pypi/crc32c" + }, + { + "component": "binaryornot", + "licenses": [ + { + "is_spdx_approved": true, + "name": "BSD", + "spdx_id": "0BSD" + } + ], + "purl": "pkg:pypi/binaryornot", + "url": "https://pypi.org/project/binaryornot", + "version": "0.4.4" + }, + { + "component": "pytest", + "licenses": [ + { + "is_spdx_approved": true, + "name": "MIT", + "spdx_id": "MIT" + } + ], + "purl": "pkg:pypi/pytest", + "url": "https://pypi.org/project/pytest", + "version": "8.0.0rc2" + }, + { + "component": "pytest-cov", + "licenses": [ + { + "is_spdx_approved": true, + "name": "MIT", + "spdx_id": "MIT" + } + ], + "purl": "pkg:pypi/pytest-cov", + "url": "https://pypi.org/project/pytest-cov", + "version": "4.1.0" + }, + { + "component": "beautifulsoup4", + "licenses": [ + { + "is_spdx_approved": true, + "name": "MITLicense", + "spdx_id": "MIT" + } + ], + "purl": "pkg:pypi/beautifulsoup4", + "url": "https://pypi.org/project/beautifulsoup4", + "version": "4.12.3" + } + ], + "id": "dependency", + "status": "pending" + } + ] + }`, + output: ` + ### SCANOSS SCAN Completed :rocket: + - **Components detected:** 9 + - **Licenses detected:** 7 + - **Policies:** (0 total) + + View more details on [SCANOSS Action Summary](https://github.com/x/y/actions/runs/NaN) + ` } ]; describe('Test report service', () => { - for (const t of licenseTableTest) { + beforeEach(() => { + jest.spyOn(github.context, 'repo', 'get').mockReturnValue({ owner: 'x', repo: 'y' }); + }); + + for (const t of tableTest) { it(`${t.name}`, () => { - const report = getLicensesTable(t.licenses); + const report = generatePRSummary(JSON.parse(t.scannerResults), []); + console.log(report); expect(report).toEqual(t.output); }); } diff --git a/dist/index.js b/dist/index.js index cf18879..3f94211 100644 --- a/dist/index.js +++ b/dist/index.js @@ -125826,7 +125826,7 @@ async function run() { } if ((0, github_utils_1.isPullRequest)()) { // create reports - const report = (0, report_service_1.generateSummary)(scan); + const report = (0, report_service_1.generatePRSummary)(scan, policies); await (0, github_utils_1.createCommentOnPR)(report); } await (0, report_service_1.generateJobSummary)(scan, policies); @@ -126197,33 +126197,31 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.generateJobSummary = exports.generateSummary = exports.getLicensesTable = void 0; +exports.generateJobSummary = exports.generatePRSummary = void 0; const result_service_1 = __nccwpck_require__(32414); const core = __importStar(__nccwpck_require__(42186)); const policy_check_1 = __nccwpck_require__(63702); const markdown_utils_1 = __nccwpck_require__(96011); -function getLicensesTable(licenses) { - let markdownTable = '| License | Copyleft | URL |\n'; - markdownTable += '| ------- | -------- | --- |\n'; - licenses.forEach(license => { - const copyleftIcon = license.copyleft ? ':x:' : ' '; - markdownTable += `| ${license.spdxid} | ${copyleftIcon} | ${license.url || ''} |\n`; - }); - return markdownTable; -} -exports.getLicensesTable = getLicensesTable; -function generateSummary(scannerResults) { +const github_1 = __nccwpck_require__(95438); +function generatePRSummary(scannerResults, policies) { + const components = (0, result_service_1.getComponents)(scannerResults); const licenses = (0, result_service_1.getLicenses)(scannerResults); - const licensesReport = getLicensesTable(licenses); + const polCount = { + total: policies.length, + success: policies.filter(p => p.conclusion === policy_check_1.CONCLUSION.Success).length, + fail: policies.filter(p => p.conclusion !== policy_check_1.CONCLUSION.Success).length + }; const content = ` - ## SCANOSS Summary :rocket: - ### Licenses detected: ${licenses.length} + ### SCANOSS SCAN Completed :rocket: + - **Components detected:** ${components.length} + - **Licenses detected:** ${licenses.length} + - **Policies:** ${polCount.fail ? `:x: ${polCount.fail} fail` : ''} ${polCount.success ? `:white_check_mark: ${polCount.success} pass` : ''} (${polCount.total} total) - ${licensesReport} + View more details on [SCANOSS Action Summary](${github_1.context.serverUrl}/${github_1.context.repo.owner}/${github_1.context.repo.repo}/actions/runs/${github_1.context.runId}) `; return content; } -exports.generateSummary = generateSummary; +exports.generatePRSummary = generatePRSummary; async function generateJobSummary(scannerResults, policies) { const licenses = (0, result_service_1.getLicenses)(scannerResults); licenses.sort((l1, l2) => l2.count - l1.count); diff --git a/src/main.ts b/src/main.ts index c51d311..6bed511 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,6 @@ import { createCommentOnPR, isPullRequest } from './utils/github.utils'; import { CopyleftPolicyCheck } from './policies/copyleft-policy-check'; -import { generateJobSummary, generateSummary } from './services/report.service'; +import { generateJobSummary, generatePRSummary } from './services/report.service'; import * as core from '@actions/core'; import * as inputs from './app.input'; import * as outputs from './app.output'; @@ -35,7 +35,7 @@ export async function run(): Promise { if (isPullRequest()) { // create reports - const report = generateSummary(scan); + const report = generatePRSummary(scan, policies); await createCommentOnPR(report); } diff --git a/src/services/report.service.ts b/src/services/report.service.ts index 67d1208..5dd78dc 100644 --- a/src/services/report.service.ts +++ b/src/services/report.service.ts @@ -1,29 +1,27 @@ import { ScannerResults } from './result.interfaces'; -import { License, getLicenses } from './result.service'; +import { License, getComponents, getLicenses } from './result.service'; import * as core from '@actions/core'; import { CONCLUSION, PolicyCheck } from '../policies/policy-check'; import { generateTable } from '../utils/markdown.utils'; -export function getLicensesTable(licenses: License[]): string { - let markdownTable = '| License | Copyleft | URL |\n'; - markdownTable += '| ------- | -------- | --- |\n'; +import { context } from '@actions/github'; - licenses.forEach(license => { - const copyleftIcon = license.copyleft ? ':x:' : ' '; - markdownTable += `| ${license.spdxid} | ${copyleftIcon} | ${license.url || ''} |\n`; - }); - - return markdownTable; -} - -export function generateSummary(scannerResults: ScannerResults): string { +export function generatePRSummary(scannerResults: ScannerResults, policies: PolicyCheck[]): string { + const components = getComponents(scannerResults); const licenses = getLicenses(scannerResults); - const licensesReport = getLicensesTable(licenses); + + const polCount = { + total: policies.length, + success: policies.filter(p => p.conclusion === CONCLUSION.Success).length, + fail: policies.filter(p => p.conclusion !== CONCLUSION.Success).length + }; const content = ` - ## SCANOSS Summary :rocket: - ### Licenses detected: ${licenses.length} + ### SCANOSS SCAN Completed :rocket: + - **Components detected:** ${components.length} + - **Licenses detected:** ${licenses.length} + - **Policies:** ${polCount.fail ? `:x: ${polCount.fail} fail` : ''} ${polCount.success ? `:white_check_mark: ${polCount.success} pass` : ''} (${polCount.total} total) - ${licensesReport} + View more details on [SCANOSS Action Summary](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) `; return content;