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

176 lines
5.2 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']),
allow_licenses: z.array(z.string()).optional(),
deny_licenses: z.array(z.string()).optional(),
2023-04-06 09:37:42 +02:00
allow_dependencies_licenses: z.array(z.string()).optional(),
2022-09-22 21:34:18 +00:00
allow_ghsas: z.array(z.string()).default([]),
2023-08-07 14:04:41 +02:00
deny_packages: z.array(z.string()).default([]),
deny_groups: 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(),
2023-09-06 18:04:10 +00:00
retry_on_snapshot_warnings: z.boolean().default(false),
retry_on_snapshot_warnings_timeout: z.number().default(120),
show_openssf_scorecard: z.boolean().optional(),
warn_on_openssf_scorecard_level: z.number(),
2023-08-09 15:57:03 -04:00
comment_summary_in_pr: z
2023-08-09 21:10:48 -04:00
.union([
z.preprocess(
val => (val === 'true' ? true : val === 'false' ? false : val),
z.boolean()
),
z.enum(['always', 'never', 'on-failure'])
])
.default('never'),
2023-06-12 11:26:44 +02:00
warn_only: z.boolean().default(false)
})
2023-08-09 15:57:03 -04:00
.transform(config => {
if (config.comment_summary_in_pr === true) {
config.comment_summary_in_pr = 'always'
} else if (config.comment_summary_in_pr === false) {
config.comment_summary_in_pr = 'never'
}
return config
})
.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)
2023-03-22 21:13:20 +00:00
export const ComparisonResponseSchema = z.object({
changes: z.array(ChangeSchema),
snapshot_warnings: z.string()
})
2024-03-03 05:59:37 +00:00
export const DepsDevProjectSchema = z
.object({
projectKey: z.object({
id: z.string({})
2024-03-02 22:37:50 +00:00
}),
2024-03-03 06:08:47 +00:00
openIssuesCount: z.string().nullish(),
starsCount: z.string().nullish(),
forksCount: z.string().nullish(),
license: z.string().nullish(),
description: z.string().nullish(),
homepage: z.string().nullish(),
2024-03-03 05:24:07 +00:00
scorecard: z.object({
2024-03-03 05:59:37 +00:00
date: z.string(),
2024-03-03 06:08:47 +00:00
repository: z
.object({
2024-03-03 05:59:37 +00:00
name: z.string(),
2024-03-03 06:08:47 +00:00
commit: z.string()
2024-03-03 05:59:37 +00:00
})
2024-03-03 06:08:47 +00:00
.nullish(),
scorecard: z
.object({
version: z.string(),
commit: z.string()
})
.nullish(),
checks: z
.array(
z.object({
name: z.string(),
documentation: z.object({
shortDescription: z.string(),
url: z.string()
}),
2024-03-04 20:03:39 +00:00
score: z.string(),
2024-03-03 06:08:47 +00:00
reason: z.string(),
details: z.array(z.string())
})
)
.nullish(),
overallScore: z.number().nullish()
2024-03-03 05:59:37 +00:00
}),
ossFuzz: z
.object({
lineCount: z.string(),
lineCoverCount: z.string(),
date: z.string(),
configUrl: z.string()
2024-03-03 05:24:07 +00:00
})
2024-03-03 05:59:37 +00:00
.nullish()
2024-03-02 22:37:50 +00:00
})
2024-03-03 05:59:37 +00:00
.nullish()
2024-03-02 22:37:50 +00:00
2024-03-03 05:24:07 +00:00
export const ScorecardSchema = z.object({
dependencies: z.array(
z.object({
ecosystem: z.string(),
packageName: z.string(),
version: z.string().nullish(),
depsDevData: DepsDevProjectSchema
})
)
})
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>
2023-03-22 21:13:20 +00:00
export type ComparisonResponse = z.infer<typeof ComparisonResponseSchema>
export type ConfigurationOptions = z.infer<typeof ConfigurationOptionsSchema>
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]
2024-03-02 22:37:50 +00:00
export type DepsDevProject = z.infer<typeof DepsDevProjectSchema>
2024-03-03 05:24:07 +00:00
export type Scorecard = z.infer<typeof ScorecardSchema>