2022-06-13 19:55:08 +02:00
|
|
|
import * as core from '@actions/core'
|
2022-06-14 11:29:13 +02:00
|
|
|
import * as z from 'zod'
|
|
|
|
|
import {ConfigurationOptions, SEVERITIES} from './schemas'
|
|
|
|
|
|
|
|
|
|
function getOptionalInput(name: string): string | undefined {
|
|
|
|
|
const value = core.getInput(name)
|
|
|
|
|
return value.length > 0 ? value : undefined
|
|
|
|
|
}
|
2022-05-12 18:05:14 +02:00
|
|
|
|
2022-06-13 19:55:08 +02:00
|
|
|
export function readConfig(): ConfigurationOptions {
|
2022-06-14 11:29:13 +02:00
|
|
|
const fail_on_severity = z
|
|
|
|
|
.enum(SEVERITIES)
|
|
|
|
|
.default('low')
|
|
|
|
|
.parse(getOptionalInput('fail-on-severity'))
|
|
|
|
|
const allow_licenses = getOptionalInput('allow-licenses')
|
|
|
|
|
const deny_licenses = getOptionalInput('deny-licenses')
|
2022-05-12 18:05:14 +02:00
|
|
|
|
2022-06-14 11:29:13 +02:00
|
|
|
if (allow_licenses !== undefined && deny_licenses !== undefined) {
|
|
|
|
|
throw new Error("Can't specify both allow_licenses and deny_licenses")
|
2022-06-13 19:55:08 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-21 15:47:05 -04:00
|
|
|
const base_ref = getOptionalInput('base-ref')
|
|
|
|
|
const head_ref = getOptionalInput('head-ref')
|
|
|
|
|
|
2022-06-14 11:29:13 +02:00
|
|
|
return {
|
|
|
|
|
fail_on_severity,
|
|
|
|
|
allow_licenses: allow_licenses?.split(',').map(x => x.trim()),
|
2022-07-21 15:47:05 -04:00
|
|
|
deny_licenses: deny_licenses?.split(',').map(x => x.trim()),
|
|
|
|
|
base_ref,
|
|
|
|
|
head_ref
|
2022-06-13 19:55:08 +02:00
|
|
|
}
|
2022-05-31 16:50:39 +02:00
|
|
|
}
|