From 8ef181b2cb4bf93e44e4efa3144d379d47d6ba53 Mon Sep 17 00:00:00 2001 From: Federico Builes Date: Fri, 16 Sep 2022 14:30:57 +0200 Subject: [PATCH] Read a hardcoded config file. --- src/config.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/config.ts b/src/config.ts index 800a672..3f78c3a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,7 +1,12 @@ +import * as fs from 'fs' +import path from 'path' +import YAML from 'yaml' import * as core from '@actions/core' import * as z from 'zod' import {ConfigurationOptions, SEVERITIES} from './schemas' +export const CONFIG_FILEPATH = './.github/dependency-review.yml' + function getOptionalInput(name: string): string | undefined { const value = core.getInput(name) return value.length > 0 ? value : undefined @@ -30,3 +35,17 @@ export function readConfig(): ConfigurationOptions { head_ref } } + +export function readConfigFile( + filePath: string = CONFIG_FILEPATH +): ConfigurationOptions { + let data + + try { + data = fs.readFileSync(path.resolve(filePath), 'utf-8') + } catch (error: unknown) { + throw error + } + const values = YAML.parse(data) + return values +}