add configuration for scopes to fail on
This commit is contained in:
@@ -13,6 +13,7 @@ function setInput(input: string, value: string) {
|
|||||||
function clearInputs() {
|
function clearInputs() {
|
||||||
const allowedOptions = [
|
const allowedOptions = [
|
||||||
'FAIL-ON-SEVERITY',
|
'FAIL-ON-SEVERITY',
|
||||||
|
'FAIL-ON-SCOPES',
|
||||||
'ALLOW-LICENSES',
|
'ALLOW-LICENSES',
|
||||||
'DENY-LICENSES',
|
'DENY-LICENSES',
|
||||||
'BASE-REF',
|
'BASE-REF',
|
||||||
@@ -82,3 +83,22 @@ test('it raises an error when no refs are provided and the event is not a pull r
|
|||||||
})
|
})
|
||||||
).toThrow()
|
).toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('it defaults to runtime scope', async () => {
|
||||||
|
const options = readConfig()
|
||||||
|
expect(options.fail_on_scopes).toEqual(['runtime'])
|
||||||
|
})
|
||||||
|
test('it parses custom scopes preference', async () => {
|
||||||
|
setInput('fail-on-scopes', 'runtime, development')
|
||||||
|
let options = readConfig()
|
||||||
|
expect(options.fail_on_scopes).toEqual(['runtime', 'development'])
|
||||||
|
|
||||||
|
clearInputs()
|
||||||
|
setInput('fail-on-scopes', 'development')
|
||||||
|
options = readConfig()
|
||||||
|
expect(options.fail_on_scopes).toEqual(['development'])
|
||||||
|
})
|
||||||
|
test('it raises an error when given invalid scope', async () => {
|
||||||
|
setInput('fail-on-scopes', 'runtime, zombies')
|
||||||
|
expect(() => readConfig()).toThrow()
|
||||||
|
})
|
||||||
|
|||||||
+16
-3
@@ -1,17 +1,29 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as z from 'zod'
|
import * as z from 'zod'
|
||||||
import {ConfigurationOptions, SEVERITIES} from './schemas'
|
import {ConfigurationOptions, SEVERITIES, SCOPES} from './schemas'
|
||||||
|
|
||||||
function getOptionalInput(name: string): string | undefined {
|
function getOptionalInput(name: string): string | undefined {
|
||||||
const value = core.getInput(name)
|
const value = core.getInput(name)
|
||||||
return value.length > 0 ? value : undefined
|
return value.length > 0 ? value : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseList(list: string | undefined): string[] | undefined {
|
||||||
|
if (list === undefined) {
|
||||||
|
return list
|
||||||
|
} else {
|
||||||
|
return list.split(',').map(x => x.trim())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function readConfig(): ConfigurationOptions {
|
export function readConfig(): ConfigurationOptions {
|
||||||
const fail_on_severity = z
|
const fail_on_severity = z
|
||||||
.enum(SEVERITIES)
|
.enum(SEVERITIES)
|
||||||
.default('low')
|
.default('low')
|
||||||
.parse(getOptionalInput('fail-on-severity'))
|
.parse(getOptionalInput('fail-on-severity'))
|
||||||
|
const fail_on_scopes = z
|
||||||
|
.array(z.enum(SCOPES))
|
||||||
|
.default(['runtime'])
|
||||||
|
.parse(parseList(getOptionalInput('fail-on-scopes')))
|
||||||
const allow_licenses = getOptionalInput('allow-licenses')
|
const allow_licenses = getOptionalInput('allow-licenses')
|
||||||
const deny_licenses = getOptionalInput('deny-licenses')
|
const deny_licenses = getOptionalInput('deny-licenses')
|
||||||
|
|
||||||
@@ -24,8 +36,9 @@ export function readConfig(): ConfigurationOptions {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
fail_on_severity,
|
fail_on_severity,
|
||||||
allow_licenses: allow_licenses?.split(',').map(x => x.trim()),
|
fail_on_scopes,
|
||||||
deny_licenses: deny_licenses?.split(',').map(x => x.trim()),
|
allow_licenses: parseList(allow_licenses),
|
||||||
|
deny_licenses: parseList(deny_licenses),
|
||||||
base_ref,
|
base_ref,
|
||||||
head_ref
|
head_ref
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export const PullRequestSchema = z.object({
|
|||||||
export const ConfigurationOptionsSchema = z
|
export const ConfigurationOptionsSchema = z
|
||||||
.object({
|
.object({
|
||||||
fail_on_severity: z.enum(SEVERITIES).default('low'),
|
fail_on_severity: z.enum(SEVERITIES).default('low'),
|
||||||
|
fail_on_scopes: z.array(z.enum(SCOPES)).default(['runtime']),
|
||||||
allow_licenses: z.array(z.string()).default([]),
|
allow_licenses: z.array(z.string()).default([]),
|
||||||
deny_licenses: z.array(z.string()).default([]),
|
deny_licenses: z.array(z.string()).default([]),
|
||||||
base_ref: z.string(),
|
base_ref: z.string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user