Skip to content

Commit

Permalink
chore: SP-1543 Fixes linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
agustingroh committed Sep 30, 2024
1 parent c37194a commit 15a506c
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/linters/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ rules:
'no-unused-vars': 'off',
'prettier/prettier': 'error',
'semi': 'off',
'no-shadow': 'warn',
'no-shadow': 'off',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
Expand Down
6 changes: 3 additions & 3 deletions __tests__/copyleft-policy-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ describe('CopyleftPolicyCheck', () => {

beforeEach(() => {
jest.clearAllMocks();

policyCheck = new CopyleftPolicyCheck();
jest.spyOn(PolicyCheck.prototype, 'uploadArtifact').mockImplementation(async () => {
return Promise.resolve({ id: 123456 });
});
jest.spyOn(PolicyCheck.prototype, 'run').mockImplementation();
jest.spyOn(PolicyCheck.prototype, 'initStatus').mockImplementation();
jest.spyOn(PolicyCheck.prototype, 'finish').mockImplementation();

policyCheck = new CopyleftPolicyCheck();
});

it('should pass the policy check when no copyleft components are found', async () => {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/undeclared-policy-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ describe('UndeclaredPolicyCheck', () => {

beforeEach(() => {
jest.clearAllMocks();
jest.spyOn(PolicyCheck.prototype, 'uploadArtifact').mockImplementation(async () => {
jest.spyOn(UndeclaredPolicyCheck.prototype, 'uploadArtifact').mockImplementation(async () => {
return Promise.resolve({ id: 123456 });
});
jest.spyOn(PolicyCheck.prototype, 'run').mockImplementation();
jest.spyOn(PolicyCheck.prototype, 'updateCheck').mockImplementation();
jest.spyOn(PolicyCheck.prototype, 'initStatus').mockImplementation();
jest.spyOn(UndeclaredPolicyCheck.prototype, 'updateCheck').mockImplementation();

scannerResults = JSON.parse(resultsMock[3].content);

Expand Down
8 changes: 4 additions & 4 deletions dist/index.js

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

16 changes: 16 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 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.2",
"version": "0.2.3",
"author": "SCANOSS",
"private": true,
"homepage": "https://github.com/scanoss/code-scan-action/",
Expand Down Expand Up @@ -74,6 +74,7 @@
"@actions/github": "^6.0.0"
},
"devDependencies": {
"@octokit/types": "^13.5.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.20",
"@typescript-eslint/eslint-plugin": "^6.19.1",
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 @@ -66,7 +66,7 @@ export class CopyleftPolicyCheck extends PolicyCheck {
}

async run(scannerResults: ScannerResults): Promise<void> {
super.run(scannerResults);
super.initStatus();
const components = getComponents(scannerResults);

// Filter copyleft components
Expand Down
16 changes: 11 additions & 5 deletions src/policies/policy-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import { GitHub } from '@actions/github/lib/utils';
import * as inputs from '../app.input';
import { DefaultArtifactClient, UploadArtifactResponse } from '@actions/artifact';
import path from 'path';
import type { Endpoints } from '@octokit/types';

type ChecksCreateResponse = Endpoints['POST /repos/{owner}/{repo}/check-runs']['response'];
type CheckRun = ChecksCreateResponse['data'];

export enum CONCLUSION {
ActionRequired = 'action_required',
Expand Down Expand Up @@ -58,7 +62,7 @@ export abstract class PolicyCheck {

private checkRunId: number;

private _raw: any;
private _raw?: CheckRun;

private _status: STATUS;

Expand All @@ -78,7 +82,9 @@ export abstract class PolicyCheck {

abstract getPolicyName(): string;

async start(runId: number): Promise<any> {
abstract run(scannerResults: ScannerResults): Promise<void>;

async start(runId: number): Promise<CheckRun> {
const result = await this.octokit.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
Expand All @@ -103,15 +109,15 @@ export abstract class PolicyCheck {
return this._conclusion;
}

get raw(): any {
get raw(): CheckRun | undefined {
return this._raw;
}

get url(): string {
return `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${this._firstRunId}/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> {
initStatus(): void {
if (this._status === STATUS.UNINITIALIZED)
throw new Error(`Error on finish. Policy "${this.checkName}" is not created.`);

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 @@ -44,7 +44,7 @@ export class UndeclaredPolicyCheck extends PolicyCheck {
}

async run(scannerResults: ScannerResults): Promise<void> {
super.run(scannerResults);
super.initStatus();

const nonDeclaredComponents: Component[] = [];
let declaredComponents: Partial<Component>[] = [];
Expand Down
5 changes: 4 additions & 1 deletion src/services/result.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ export interface ScannerComponent extends CommonComponent {
score: string;
source: string;
}[];
cryptography: any[];
cryptography: {
algorithm: string;
strength: string;
}[];
health: {
creation_date: string;
issues: number;
Expand Down
7 changes: 6 additions & 1 deletion src/utils/github.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@
import { context, getOctokit } from '@actions/github';
import * as core from '@actions/core';
import * as inputs from '../app.input';
import type { Endpoints } from '@octokit/types';

const prEvents = ['pull_request', 'pull_request_review', 'pull_request_review_comment'];
const FIND_FIRST_RUN_EVENT = 'workflow_dispatch';

// Use the types from @octokit/types
type WorkflowRunsResponse = Endpoints['GET /repos/{owner}/{repo}/actions/runs']['response'];
type WorkflowRun = WorkflowRunsResponse['data']['workflow_runs'][number];

export function isPullRequest(): boolean {
return prEvents.includes(context.eventName);
}
Expand Down Expand Up @@ -68,7 +73,7 @@ export async function getFirstRunId(): Promise<number> {
return firstRunId;
}

async function loadFirstRun(owner: string, repo: string): Promise<any | null> {
async function loadFirstRun(owner: string, repo: string): Promise<WorkflowRun | null> {
const octokit = getOctokit(inputs.GITHUB_TOKEN);
const sha = getSHA();

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"rules": {
"@typescript-eslint/no-explicit-any": "off"
},
"exclude": ["./dist", "./node_modules", "./__tests__", "./coverage"]
"exclude": ["./dist", "./node_modules", "./__tests__", "./coverage", "./tsconfig.json", "./.prettierrc.json"]
}

0 comments on commit 15a506c

Please sign in to comment.