From ef97470a0f67b9f7b105b8b4856ea8ce6fcea6f7 Mon Sep 17 00:00:00 2001 From: Federico Builes Date: Tue, 14 Jun 2022 07:04:26 +0200 Subject: [PATCH] Don't set the defaults in the test :/ --- __tests__/config.test.ts | 3 +-- src/config.ts | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/__tests__/config.test.ts b/__tests__/config.test.ts index a3101af..811347d 100644 --- a/__tests__/config.test.ts +++ b/__tests__/config.test.ts @@ -4,14 +4,13 @@ import {readConfig} from '../src/config' beforeEach(() => { /* reset to our defaults after every test run */ - process.env['INPUT_FAIL-ON-SEVERITY'] = 'low' + delete process.env['INPUT_FAIL-ON-SEVERITY'] delete process.env['INPUT_ALLOWED-LICENSES'] delete process.env['INPUT_DENY-LICENSES'] }) test('it defaults to low severity', async () => { let options = readConfig() - expect(options.fail_on_severity).toEqual('low') }) diff --git a/src/config.ts b/src/config.ts index 01aea80..a3eedce 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,22 +1,19 @@ import * as core from '@actions/core' -import {z} from 'zod' -import {ConfigurationOptions, ConfigurationOptionsSchema} from './schemas' -import {Severity} from './schemas' - -export const CONFIG_FILEPATH = './.github/dependency-review.yml' +import { + ConfigurationOptions, + ConfigurationOptionsSchema, + Severity +} from './schemas' export function readConfig(): ConfigurationOptions { - // By default we want to fail on all severities and allow all licenses. let options: ConfigurationOptions = {} - let severity = core.getInput('fail-on-severity') - let allowedLicenses = core.getInput('allowed-licenses') - let denyLicenses = core.getInput('deny-licenses') + // By default we want to fail on all severities and allow all licenses. + const severity = core.getInput('fail-on-severity') || 'low' + const allowedLicenses = core.getInput('allowed-licenses') + const denyLicenses = core.getInput('deny-licenses') - // TODO test the empty string case - if (severity.length > 0) { - options.fail_on_severity = severity as Severity - } + options.fail_on_severity = severity as Severity if (allowedLicenses.length > 0) { options.allow_licenses = allowedLicenses.split(',').map(s => s.trim()) @@ -26,5 +23,7 @@ export function readConfig(): ConfigurationOptions { options.deny_licenses = denyLicenses.split(',').map(s => s.trim()) } + // we call parse on the ConfigurationOptions object because we want Zod + // to validate part of the input. return ConfigurationOptionsSchema.parse(options) }