mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-25 15:01:49 +00:00
171a591d84
* feat(git): validate length commit shas * test: adapt test mocks * chore: update import paths * feat(git): make the validation more strict and support repositories using sha256 * test: add fakeSha function for deterministic git commit shas in tests
20 lines
559 B
TypeScript
20 lines
559 B
TypeScript
import { z } from 'zod/v4';
|
|
import { regEx } from '../regex.ts';
|
|
|
|
export const LongCommitSha = z
|
|
.string()
|
|
.regex(regEx(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/))
|
|
.brand('LongCommitSha');
|
|
export type LongCommitSha = z.infer<typeof LongCommitSha>;
|
|
|
|
export function isLongCommitSha(value: unknown): value is LongCommitSha {
|
|
return LongCommitSha.safeParse(value).success;
|
|
}
|
|
|
|
export function toLongCommitSha(value: unknown): LongCommitSha {
|
|
if (!isLongCommitSha(value)) {
|
|
throw new Error(`Invalid long commit SHA: ${String(value)}`);
|
|
}
|
|
return value;
|
|
}
|