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

SP-619 Fixes bug when the sbom format is not valid #52

Merged
merged 2 commits into from
May 2, 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
13 changes: 11 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "scanoss-code-scan-action",
"description": "SCANOSS Code Scan Action",
"version": "0.1.0",
"version": "0.1.1",
"author": "SCANOSS",
"private": true,
"homepage": "https://github.com/scanoss/code-scan-action/",
Expand Down
2 changes: 1 addition & 1 deletion src/policies/policy-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import { GitHub } from '@actions/github/lib/utils';
import * as inputs from '../app.input';

export enum CONCLUSION {

Check warning on line 31 in src/policies/policy-check.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

'CONCLUSION' is already declared in the upper scope on line 31 column 13

Check warning on line 31 in src/policies/policy-check.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

'CONCLUSION' is already declared in the upper scope on line 31 column 13
ActionRequired = 'action_required',
Cancelled = 'cancelled',
Failure = 'failure',
Expand All @@ -39,7 +39,7 @@
TimedOut = 'timed_out'
}

export enum STATUS {

Check warning on line 42 in src/policies/policy-check.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

'STATUS' is already declared in the upper scope on line 42 column 13

Check warning on line 42 in src/policies/policy-check.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

'STATUS' is already declared in the upper scope on line 42 column 13
UNINITIALIZED = 'UNINITIALIZED',
INITIALIZED = 'INITIALIZED',
RUNNING = 'RUNNING',
Expand All @@ -49,11 +49,11 @@
export abstract class PolicyCheck {
private octokit: InstanceType<typeof GitHub>;

private checkName: string;
protected checkName: string;

private checkRunId: number;

private _raw: any;

Check warning on line 56 in src/policies/policy-check.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Unexpected any. Specify a different type

Check warning on line 56 in src/policies/policy-check.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Unexpected any. Specify a different type

private _status: STATUS;

Expand All @@ -67,7 +67,7 @@
this.checkRunId = -1;
}

async start(): Promise<any> {

Check warning on line 70 in src/policies/policy-check.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Unexpected any. Specify a different type

Check warning on line 70 in src/policies/policy-check.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Unexpected any. Specify a different type
const result = await this.octokit.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
Expand All @@ -90,7 +90,7 @@
return this._conclusion;
}

get raw(): any {

Check warning on line 93 in src/policies/policy-check.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Unexpected any. Specify a different type

Check warning on line 93 in src/policies/policy-check.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Unexpected any. Specify a different type
return this._raw;
}

Expand All @@ -98,7 +98,7 @@
return `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${this.raw.id}`;
}

async run(scannerResults: ScannerResults): Promise<void> {

Check warning on line 101 in src/policies/policy-check.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

'scannerResults' is defined but never used

Check warning on line 101 in src/policies/policy-check.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

'scannerResults' is defined but never used
if (this._status === STATUS.UNINITIALIZED)
throw new Error(`Error on finish. Policy "${this.checkName}" is not created.`);

Expand Down
13 changes: 11 additions & 2 deletions src/policies/undeclared-policy-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { CHECK_NAME } from '../app.config';
import { ScannerResults } from '../services/result.interfaces';
import { Component, getComponents } from '../services/result.service';
import * as inputs from '../app.input';
import * as core from '@actions/core';
import { parseSBOM } from '../utils/sbom.utils';
import { generateTable } from '../utils/markdown.utils';

Expand All @@ -45,12 +46,20 @@ export class UndeclaredPolicyCheck extends PolicyCheck {
super.run(scannerResults);

const nonDeclaredComponents: Component[] = [];
let declaredComponents: Partial<Component>[] = [];

const comps = getComponents(scannerResults);
const sbom = await parseSBOM(inputs.SBOM_FILEPATH);

// get declared components
try {
const sbom = await parseSBOM(inputs.SBOM_FILEPATH);
declaredComponents = sbom.components || [];
} catch (e) {
core.info(`Warning on policy check: ${this.checkName}. SBOM file could not be parsed (${inputs.SBOM_FILEPATH})`);
}

comps.forEach(c => {
if (!sbom.components.some(component => component.purl === c.purl)) {
if (!declaredComponents.some(component => component.purl === c.purl)) {
nonDeclaredComponents.push(c);
}
});
Expand Down
Loading