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

91 lines
2.8 KiB
TypeScript
Raw Normal View History

2022-03-31 18:31:39 +02:00
import * as z from 'zod'
2022-06-01 12:09:11 +02:00
2023-03-20 09:07:07 +01:00
export const FAIL_ON_SEVERITIES = [
'critical',
'high',
'moderate',
'low',
'none'
] as const
2022-06-01 12:09:11 +02:00
export const SEVERITIES = ['critical', 'high', 'moderate', 'low'] as const
2022-09-15 17:53:34 +00:00
export const SCOPES = ['unknown', 'runtime', 'development'] as const
2022-03-31 18:31:39 +02:00
2023-03-17 21:11:39 +01:00
export const FailOnSeveritySchema = z.enum(FAIL_ON_SEVERITIES).default('low')
export const SeveritySchema = z.enum(SEVERITIES).default('low')
2022-03-31 18:31:39 +02:00
2022-05-31 06:06:19 +02:00
export const ChangeSchema = z.object({
2022-03-31 18:31:39 +02:00
change_type: z.enum(['added', 'removed']),
manifest: z.string(),
ecosystem: z.string(),
name: z.string(),
version: z.string(),
package_url: z.string(),
license: z.string().nullable(),
source_repository_url: z.string().nullable(),
scope: z.enum(SCOPES).optional(),
2022-03-31 18:31:39 +02:00
vulnerabilities: z
.array(
z.object({
severity: SeveritySchema,
2022-03-31 18:31:39 +02:00
advisory_ghsa_id: z.string(),
advisory_summary: z.string(),
advisory_url: z.string()
})
)
.optional()
2022-06-01 05:36:46 +02:00
.default([])
2022-03-31 18:31:39 +02:00
})
export const PullRequestSchema = z.object({
number: z.number(),
2022-06-01 12:09:11 +02:00
base: z.object({sha: z.string()}),
head: z.object({sha: z.string()})
2022-03-31 18:31:39 +02:00
})
2022-06-01 12:09:11 +02:00
export const ConfigurationOptionsSchema = z
.object({
2023-03-17 21:11:39 +01:00
fail_on_severity: FailOnSeveritySchema,
2022-09-15 18:48:58 +00:00
fail_on_scopes: z.array(z.enum(SCOPES)).default(['runtime']),
allow_licenses: z.array(z.string()).optional(),
deny_licenses: z.array(z.string()).optional(),
2022-09-22 21:34:18 +00:00
allow_ghsas: z.array(z.string()).default([]),
license_check: z.boolean().default(true),
vulnerability_check: z.boolean().default(true),
config_file: z.string().optional(),
base_ref: z.string().optional(),
head_ref: z.string().optional(),
comment_summary_in_pr: z.boolean().default(false)
})
.superRefine((config, context) => {
if (config.allow_licenses && config.deny_licenses) {
context.addIssue({
code: z.ZodIssueCode.custom,
message: 'You cannot specify both allow-licenses and deny-licenses'
})
}
if (config.allow_licenses && config.allow_licenses.length < 1) {
context.addIssue({
code: z.ZodIssueCode.custom,
message: 'You should provide at least one license in allow-licenses'
})
}
if (
config.license_check === false &&
config.vulnerability_check === false
) {
context.addIssue({
code: z.ZodIssueCode.custom,
message: "Can't disable both license-check and vulnerability-check"
})
}
2022-06-01 12:09:11 +02:00
})
2022-03-31 18:31:39 +02:00
export const ChangesSchema = z.array(ChangeSchema)
2022-05-31 06:06:19 +02:00
export type Change = z.infer<typeof ChangeSchema>
2022-03-31 18:31:39 +02:00
export type Changes = z.infer<typeof ChangesSchema>
export type ConfigurationOptions = z.infer<typeof ConfigurationOptionsSchema>
2023-03-17 21:11:39 +01:00
export type FailOnSeverity = z.infer<typeof FailOnSeveritySchema>
2022-09-21 16:50:02 +02:00
export type Severity = z.infer<typeof SeveritySchema>
2023-01-09 07:59:55 +01:00
export type Scope = (typeof SCOPES)[number]