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

34 lines
818 B
TypeScript
Raw Normal View History

2022-05-12 18:05:14 +02:00
import * as fs from 'fs'
import YAML from 'yaml'
2022-06-01 12:09:11 +02:00
import {ConfigurationOptions, ConfigurationOptionsSchema} from './schemas'
import path from 'path'
2022-06-01 12:09:11 +02:00
export const CONFIG_FILEPATH = './.github/dep-review.yml'
2022-05-12 18:05:14 +02:00
2022-06-01 12:09:11 +02:00
export function readConfigFile(
filePath: string = CONFIG_FILEPATH
): ConfigurationOptions {
// By default we want to fail on all severities and allow all licenses.
const defaultOptions: ConfigurationOptions = {
fail_on_severity: 'low',
allow_licenses: []
}
2022-05-12 18:05:14 +02:00
2022-06-01 12:09:11 +02:00
let data
try {
data = fs.readFileSync(path.resolve(filePath), 'utf-8')
} catch (error: any) {
if (error.code && error.code === 'ENOENT') {
return defaultOptions
} else {
throw error
}
2022-06-01 12:09:11 +02:00
}
2022-06-01 12:09:11 +02:00
const values = YAML.parse(data)
const parsed = ConfigurationOptionsSchema.parse(values)
2022-06-01 05:31:33 +02:00
2022-06-01 12:09:11 +02:00
return parsed
}