From 0e9a3224130379f6606b101e4ce2af296e18c46a Mon Sep 17 00:00:00 2001 From: Federico Builes Date: Thu, 12 May 2022 18:05:14 +0200 Subject: [PATCH] Move config into its own file. --- src/config.ts | 30 ++++++++++++++++++++++++++++++ src/main.ts | 19 ++++--------------- 2 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 src/config.ts diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..011e8b4 --- /dev/null +++ b/src/config.ts @@ -0,0 +1,30 @@ +import * as fs from 'fs' +import YAML from 'yaml' +import * as z from 'zod' + +const CONFIG_FILEPATH = "./.github/dep-review.yml" +const SEVERITIES = ["critical", "high", "moderate", "low"] + +// TODO check for file not existing +// TODO check for file with both extensions +// TODO parse yaml format, validate keys + +var severity: string +var allowlist, blocklist: [string] + +var data = fs.readFile(CONFIG_FILEPATH, "utf-8", (err, data) => { + const values = YAML.parse(data) + const parsed = z.object({ + fail_on_severity: z.enum(SEVERITIES), + allow_licenses: z.array(z.string()), + deny_licenses: z.array(z.string()) + }) + .partial() + .refine(obj => !(obj.allow_licenses && obj.deny_licenses), "Can't specify both allow_licenses and deny_licenses") + .parse(values) + + // vlaidate licenses dynamically + core.info(parsed.fail_on_severity!) + //core.info(values["allow_licenses"]) + //core.info(values["deny_licenses"]) +}) \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 406e6c8..59da369 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,9 +2,9 @@ import * as core from '@actions/core' import * as dependencyGraph from './dependency-graph' import * as github from '@actions/github' import styles from 'ansi-styles' -import {RequestError} from '@octokit/request-error' -import {PullRequestSchema} from './schemas' -import * as fs from 'fs' +import { RequestError } from '@octokit/request-error' +import { PullRequestSchema } from './schemas' + async function run(): Promise { try { @@ -35,8 +35,7 @@ async function run(): Promise { ) { for (const vuln of change.vulnerabilities) { core.info( - `${styles.bold.open}${change.manifest} » ${change.name}@${ - change.version + `${styles.bold.open}${change.manifest} » ${change.name}@${change.version }${styles.bold.close} – ${vuln.advisory_summary} ${renderSeverity( vuln.severity )}` @@ -47,16 +46,6 @@ async function run(): Promise { } } - // TODO check for file not existing - // TODO check for file with both extensions - - var severity: string - var allowlist, blocklist: [string] - - var data = fs.readFile("./.github/dep-review.yml", "utf-8", (err, data) => { - core.info(data) - }) - if (failed) { throw new Error('Dependency review detected vulnerable packages.') } else {