mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-01 18:19:51 +00:00
15f4bd8eff
* chore: migrate from zod/v3 to zod/v4 This commit contains the logic changes * chore: migrate imports from zod/v3 to zod/v4 This contains import updates and adds explicit record keys as zod/v4 requires these now * ci: enforce usage of zod/v4
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import { z } from 'zod/v4';
|
|
import { Timestamp } from '../../../timestamp.ts';
|
|
import type {
|
|
GithubBranchItem,
|
|
GithubGraphqlDatasourceAdapter,
|
|
} from '../types.ts';
|
|
import { prepareQuery } from '../util.ts';
|
|
|
|
const key = 'github-branches-datasource-v1';
|
|
|
|
const GithubGraphqlBranch = z.object({
|
|
version: z.string(),
|
|
target: z.object({
|
|
type: z.literal('Commit'),
|
|
oid: z.string(),
|
|
releaseTimestamp: Timestamp,
|
|
}),
|
|
});
|
|
export type GithubGraphqlBranch = z.infer<typeof GithubGraphqlBranch>;
|
|
|
|
const query = prepareQuery(`
|
|
refs(
|
|
first: $count
|
|
after: $cursor
|
|
refPrefix: "refs/heads/"
|
|
) {
|
|
pageInfo {
|
|
hasNextPage
|
|
endCursor
|
|
}
|
|
nodes {
|
|
version: name
|
|
target {
|
|
type: __typename
|
|
... on Commit {
|
|
oid
|
|
releaseTimestamp: committedDate
|
|
}
|
|
}
|
|
}
|
|
}`);
|
|
|
|
function transform(item: GithubGraphqlBranch): GithubBranchItem | null {
|
|
const res = GithubGraphqlBranch.safeParse(item);
|
|
if (!res.success) {
|
|
return null;
|
|
}
|
|
|
|
const { version, target } = item;
|
|
const releaseTimestamp = target.releaseTimestamp;
|
|
const hash = target.oid;
|
|
return { version, gitRef: version, hash, releaseTimestamp };
|
|
}
|
|
|
|
export const adapter: GithubGraphqlDatasourceAdapter<
|
|
GithubGraphqlBranch,
|
|
GithubBranchItem
|
|
> = { key, query, transform, maxItems: 300 };
|