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

51 lines
1.4 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
export const SEVERITIES = ['critical', 'high', 'moderate', 'low'] as const
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(),
vulnerabilities: z
.array(
z.object({
severity: z.enum(['critical', 'high', 'moderate', 'low']),
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({
fail_on_severity: z.enum(SEVERITIES).default('low'),
allow_licenses: z.array(z.string()).default([]),
deny_licenses: z.array(z.string()).default([])
})
.partial()
.refine(
obj => !(obj.allow_licenses && obj.deny_licenses),
"Can't specify both allow_licenses and deny_licenses"
)
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>
2022-06-01 12:09:11 +02:00
export type Severity = typeof SEVERITIES[number]