Files
renovate/lib/modules/platform/github/branch.ts
T
renovate[bot] 4a2578d18d build(deps): update dependency zod to v4 (main) (#41225)
* build(deps): update dependency zod to v4

| datasource | package | from    | to    |
| ---------- | ------- | ------- | ----- |
| npm        | zod     | 3.25.76 | 4.3.6 |

* fix: zod migration

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2026-02-18 07:37:50 +00:00

34 lines
943 B
TypeScript

import { z } from 'zod/v3';
import { regEx } from '../../../util/regex.ts';
import { githubApi } from './common.ts';
const MatchingRef = z
.object({ ref: z.string() })
.transform(({ ref }) => ref.replace(regEx(/^refs\/heads\//), ''))
.array();
async function matchingBranches(
repo: string,
branchName: string,
): Promise<string[]> {
const { body: branches } = await githubApi.getJson(
`/repos/${repo}/git/matching-refs/heads/${branchName}`,
{ memCache: false },
MatchingRef,
);
return branches;
}
export async function remoteBranchExists(
repo: string,
branchName: string,
): Promise<boolean> {
const branches = await matchingBranches(repo, branchName);
if (branches.some((branch) => branch.startsWith(`${branchName}/`))) {
const message = `Trying to create a branch '${branchName}' while it's the part of nested branch`;
throw new Error(message);
}
return branches.includes(branchName);
}