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

63 lines
2.0 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-09-15 17:53:34 +00:00
export const SCOPES = ['unknown', 'runtime', 'development'] as const
2022-03-31 18:31:39 +02:00
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({
fail_on_severity: SeveritySchema,
2022-09-15 18:48:58 +00:00
fail_on_scopes: z.array(z.enum(SCOPES)).default(['runtime']),
2022-06-01 12:09:11 +02:00
allow_licenses: z.array(z.string()).default([]),
deny_licenses: z.array(z.string()).default([]),
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),
2022-09-19 17:28:20 +02:00
config_file: z.string().optional().default('false'),
base_ref: z.string(),
head_ref: z.string()
2022-06-01 12:09:11 +02:00
})
.partial()
.refine(
obj => !(obj.allow_licenses && obj.deny_licenses),
2022-07-04 20:04:28 +09:00
'Your workflow file has both an allow_licenses list and deny_licenses list, but you can only set one or the other.'
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>
2022-09-21 16:50:02 +02:00
export type Severity = z.infer<typeof SeveritySchema>
2022-09-15 17:53:34 +00:00
export type Scope = typeof SCOPES[number]