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

bug/SP-1356 Fix policy check reporting #69

Merged
merged 1 commit into from
Aug 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 .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ permissions:
contents: read
pull-requests: write
checks: write
actions: read

jobs:
test-action:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ permissions:
contents: read
pull-requests: write
checks: write
actions: read

jobs:
scanoss-code-scan:
Expand Down Expand Up @@ -109,6 +110,7 @@ permissions:
contents: read
pull-requests: write
checks: write
actions: read

jobs:
scanoss-code-scan:
Expand Down
50 changes: 43 additions & 7 deletions dist/index.js

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

100 changes: 89 additions & 11 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.2.0",
"version": "0.2.1",
"author": "SCANOSS",
"private": true,
"homepage": "https://github.com/scanoss/code-scan-action/",
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
THE SOFTWARE.
*/

import { createCommentOnPR, isPullRequest } from './utils/github.utils';
import { createCommentOnPR, isPullRequest, getFirstRunId } from './utils/github.utils';
import { generateJobSummary, generatePRSummary } from './services/report.service';
import * as core from '@actions/core';
import * as inputs from './app.input';
Expand All @@ -40,11 +40,12 @@ export async function run(): Promise<void> {

// create policies
core.debug(`Creating policies`);
const firstRunId = await getFirstRunId();

//Read declared policies on input parameter 'policies' and create an instance for each one.
const policies = policyManager.getPolicies();
for (const policy of policies) {
await policy.start();
await policy.start(firstRunId);
}

// run scan
Expand Down
2 changes: 1 addition & 1 deletion src/policies/copyleft-policy-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class CopyleftPolicyCheck extends PolicyCheck {

if (details) {
const { id } = await this.uploadArtifact(details);
if (id) details = this.concatPolicyArtifactURLToPolicyCheck(details, id);
if (id) details = await this.concatPolicyArtifactURLToPolicyCheck(details, id);
}

if (componentsWithCopyleft.length === 0) {
Expand Down
10 changes: 7 additions & 3 deletions src/policies/policy-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import { DefaultArtifactClient, UploadArtifactResponse } from '@actions/artifact';
import path from 'path';

export enum CONCLUSION {

Check warning on line 34 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 34 column 13

Check warning on line 34 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 34 column 13
ActionRequired = 'action_required',
Cancelled = 'cancelled',
Failure = 'failure',
Expand All @@ -42,7 +42,7 @@
TimedOut = 'timed_out'
}

export enum STATUS {

Check warning on line 45 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 45 column 13

Check warning on line 45 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 45 column 13
UNINITIALIZED = 'UNINITIALIZED',
INITIALIZED = 'INITIALIZED',
RUNNING = 'RUNNING',
Expand All @@ -58,12 +58,14 @@

private checkRunId: number;

private _raw: any;

Check warning on line 61 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 61 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;

private _conclusion: CONCLUSION;

private _firstRunId = -1;

constructor(checkName: string) {
this.octokit = getOctokit(inputs.GITHUB_TOKEN);
this.checkName = checkName;
Expand All @@ -76,7 +78,7 @@

abstract getPolicyName(): string;

async start(): Promise<any> {
async start(runId: number): Promise<any> {

Check warning on line 81 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 81 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 @@ -87,6 +89,8 @@
this.checkRunId = result.data.id;
this._raw = result.data;

this._firstRunId = runId;

this._status = STATUS.INITIALIZED;
return result.data;
}
Expand All @@ -99,15 +103,15 @@
return this._conclusion;
}

get raw(): any {

Check warning on line 106 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 106 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;
}

get url(): string {
return `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${this.raw.id}`;
return `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${this._firstRunId}/job/${this.raw.id}`;
}

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

Check warning on line 114 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 114 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 Expand Up @@ -152,7 +156,7 @@
return text.length > this.MAX_GH_API_CONTENT_SIZE;
}

protected concatPolicyArtifactURLToPolicyCheck(details: string, artifactId: number): string {
protected async concatPolicyArtifactURLToPolicyCheck(details: string, artifactId: number): Promise<string> {
const link =
`\n\nDownload the ` +
`[${this.getPolicyName()} Result](${context.serverUrl}/` +
Expand Down
2 changes: 1 addition & 1 deletion src/policies/undeclared-policy-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class UndeclaredPolicyCheck extends PolicyCheck {

if (details) {
const { id } = await this.uploadArtifact(details);
if (id) details = this.concatPolicyArtifactURLToPolicyCheck(details, id);
if (id) details = await this.concatPolicyArtifactURLToPolicyCheck(details, id);
}

if (nonDeclaredComponents.length === 0) {
Expand Down
Loading
Loading