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

30 lines
929 B
TypeScript
Raw Normal View History

2022-06-13 19:55:08 +02:00
import * as core from '@actions/core'
2022-06-14 07:04:26 +02:00
import {
ConfigurationOptions,
ConfigurationOptionsSchema,
Severity
} from './schemas'
2022-05-12 18:05:14 +02:00
2022-06-13 19:55:08 +02:00
export function readConfig(): ConfigurationOptions {
2022-06-14 06:48:58 +02:00
let options: ConfigurationOptions = {}
2022-05-12 18:05:14 +02:00
2022-06-14 07:04:26 +02:00
// By default we want to fail on all severities and allow all licenses.
const severity = core.getInput('fail-on-severity') || 'low'
2022-06-14 09:46:59 +02:00
const allowedLicenses = core.getInput('allow-licenses')
2022-06-14 07:04:26 +02:00
const denyLicenses = core.getInput('deny-licenses')
2022-06-01 12:09:11 +02:00
2022-06-14 07:42:51 +02:00
options.fail_on_severity = severity.toLowerCase() as Severity
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())
}
2022-06-14 07:04:26 +02:00
// we call parse on the ConfigurationOptions object because we want Zod
// to validate part of the input.
2022-06-13 19:55:08 +02:00
return ConfigurationOptionsSchema.parse(options)
}