Files
dependency-review-action/src/config.ts
T

31 lines
969 B
TypeScript
Raw Normal View History

2022-06-13 19:55:08 +02:00
import * as core from '@actions/core'
2022-06-14 06:48:58 +02:00
import {z} from 'zod'
2022-06-01 12:09:11 +02:00
import {ConfigurationOptions, ConfigurationOptionsSchema} from './schemas'
2022-06-13 19:55:08 +02:00
import {Severity} from './schemas'
export const CONFIG_FILEPATH = './.github/dependency-review.yml'
2022-05-12 18:05:14 +02:00
2022-06-13 19:55:08 +02:00
export function readConfig(): ConfigurationOptions {
2022-06-01 12:09:11 +02:00
// By default we want to fail on all severities and allow all licenses.
2022-06-14 06:48:58 +02:00
let options: ConfigurationOptions = {}
2022-05-12 18:05:14 +02:00
2022-06-13 19:55:08 +02:00
let severity = core.getInput('fail-on-severity')
let allowedLicenses = core.getInput('allowed-licenses')
let denyLicenses = core.getInput('deny-licenses')
2022-06-01 12:09:11 +02:00
2022-06-13 19:55:08 +02:00
// TODO test the empty string case
if (severity.length > 0) {
options.fail_on_severity = severity as Severity
2022-06-01 12:09:11 +02:00
}
2022-06-13 19:55:08 +02:00
if (allowedLicenses.length > 0) {
options.allow_licenses = allowedLicenses.split(',').map(s => s.trim())
}
if (denyLicenses.length > 0) {
options.deny_licenses = denyLicenses.split(',').map(s => s.trim())
}
return ConfigurationOptionsSchema.parse(options)
}