Move config into its own file.

This commit is contained in:
Federico Builes
2022-05-12 18:05:14 +02:00
parent fdcc204dbb
commit 0e9a322413
2 changed files with 34 additions and 15 deletions
+30
View File
@@ -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"])
})
+2 -13
View File
@@ -4,7 +4,7 @@ import * as github from '@actions/github'
import styles from 'ansi-styles' import styles from 'ansi-styles'
import { RequestError } from '@octokit/request-error' import { RequestError } from '@octokit/request-error'
import { PullRequestSchema } from './schemas' import { PullRequestSchema } from './schemas'
import * as fs from 'fs'
async function run(): Promise<void> { async function run(): Promise<void> {
try { try {
@@ -35,8 +35,7 @@ async function run(): Promise<void> {
) { ) {
for (const vuln of change.vulnerabilities) { for (const vuln of change.vulnerabilities) {
core.info( core.info(
`${styles.bold.open}${change.manifest} » ${change.name}@${ `${styles.bold.open}${change.manifest} » ${change.name}@${change.version
change.version
}${styles.bold.close} ${vuln.advisory_summary} ${renderSeverity( }${styles.bold.close} ${vuln.advisory_summary} ${renderSeverity(
vuln.severity vuln.severity
)}` )}`
@@ -47,16 +46,6 @@ async function run(): Promise<void> {
} }
} }
// 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) { if (failed) {
throw new Error('Dependency review detected vulnerable packages.') throw new Error('Dependency review detected vulnerable packages.')
} else { } else {