Skip to content

Commit 25d4fff

Browse files
committed
bug/SP-1356 Fix policy check reporting
1 parent 02fd052 commit 25d4fff

10 files changed

+189
-26
lines changed

.github/workflows/test-action.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ permissions:
1010
contents: read
1111
pull-requests: write
1212
checks: write
13+
actions: read
1314

1415
jobs:
1516
test-action:

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ permissions:
3232
contents: read
3333
pull-requests: write
3434
checks: write
35+
actions: read
3536

3637
jobs:
3738
scanoss-code-scan:
@@ -109,6 +110,7 @@ permissions:
109110
contents: read
110111
pull-requests: write
111112
checks: write
113+
actions: read
112114
113115
jobs:
114116
scanoss-code-scan:

dist/index.js

+43-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+89-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "scanoss-code-scan-action",
33
"description": "SCANOSS Code Scan Action",
4-
"version": "0.2.0",
4+
"version": "0.2.1",
55
"author": "SCANOSS",
66
"private": true,
77
"homepage": "https://github.com/scanoss/code-scan-action/",

src/main.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
THE SOFTWARE.
2222
*/
2323

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

4141
// create policies
4242
core.debug(`Creating policies`);
43+
const firstRunId = await getFirstRunId();
4344

4445
//Read declared policies on input parameter 'policies' and create an instance for each one.
4546
const policies = policyManager.getPolicies();
4647
for (const policy of policies) {
47-
await policy.start();
48+
await policy.start(firstRunId);
4849
}
4950

5051
// run scan

src/policies/copyleft-policy-check.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class CopyleftPolicyCheck extends PolicyCheck {
8181

8282
if (details) {
8383
const { id } = await this.uploadArtifact(details);
84-
if (id) details = this.concatPolicyArtifactURLToPolicyCheck(details, id);
84+
if (id) details = await this.concatPolicyArtifactURLToPolicyCheck(details, id);
8585
}
8686

8787
if (componentsWithCopyleft.length === 0) {

src/policies/policy-check.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export abstract class PolicyCheck {
6464

6565
private _conclusion: CONCLUSION;
6666

67+
private _firstRunId = -1;
68+
6769
constructor(checkName: string) {
6870
this.octokit = getOctokit(inputs.GITHUB_TOKEN);
6971
this.checkName = checkName;
@@ -76,7 +78,7 @@ export abstract class PolicyCheck {
7678

7779
abstract getPolicyName(): string;
7880

79-
async start(): Promise<any> {
81+
async start(runId: number): Promise<any> {
8082
const result = await this.octokit.rest.checks.create({
8183
owner: context.repo.owner,
8284
repo: context.repo.repo,
@@ -87,6 +89,8 @@ export abstract class PolicyCheck {
8789
this.checkRunId = result.data.id;
8890
this._raw = result.data;
8991

92+
this._firstRunId = runId;
93+
9094
this._status = STATUS.INITIALIZED;
9195
return result.data;
9296
}
@@ -104,7 +108,7 @@ export abstract class PolicyCheck {
104108
}
105109

106110
get url(): string {
107-
return `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${this.raw.id}`;
111+
return `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${this._firstRunId}/job/${this.raw.id}`;
108112
}
109113

110114
async run(scannerResults: ScannerResults): Promise<void> {
@@ -152,7 +156,7 @@ export abstract class PolicyCheck {
152156
return text.length > this.MAX_GH_API_CONTENT_SIZE;
153157
}
154158

155-
protected concatPolicyArtifactURLToPolicyCheck(details: string, artifactId: number): string {
159+
protected async concatPolicyArtifactURLToPolicyCheck(details: string, artifactId: number): Promise<string> {
156160
const link =
157161
`\n\nDownload the ` +
158162
`[${this.getPolicyName()} Result](${context.serverUrl}/` +

src/policies/undeclared-policy-check.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class UndeclaredPolicyCheck extends PolicyCheck {
7070

7171
if (details) {
7272
const { id } = await this.uploadArtifact(details);
73-
if (id) details = this.concatPolicyArtifactURLToPolicyCheck(details, id);
73+
if (id) details = await this.concatPolicyArtifactURLToPolicyCheck(details, id);
7474
}
7575

7676
if (nonDeclaredComponents.length === 0) {

0 commit comments

Comments
 (0)