Add common type definitions
This commit is contained in:
parent
0ecd2049ab
commit
534b90cfe0
1 changed files with 132 additions and 0 deletions
132
src/github/common/types.ts
Normal file
132
src/github/common/types.ts
Normal file
|
|
@ -0,0 +1,132 @@
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
// Base schemas for common types
|
||||||
|
export const GitHubAuthorSchema = z.object({
|
||||||
|
name: z.string(),
|
||||||
|
email: z.string(),
|
||||||
|
date: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const GitHubOwnerSchema = z.object({
|
||||||
|
login: z.string(),
|
||||||
|
id: z.number(),
|
||||||
|
node_id: z.string(),
|
||||||
|
avatar_url: z.string(),
|
||||||
|
url: z.string(),
|
||||||
|
html_url: z.string(),
|
||||||
|
type: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const GitHubRepositorySchema = z.object({
|
||||||
|
id: z.number(),
|
||||||
|
node_id: z.string(),
|
||||||
|
name: z.string(),
|
||||||
|
full_name: z.string(),
|
||||||
|
private: z.boolean(),
|
||||||
|
owner: GitHubOwnerSchema,
|
||||||
|
html_url: z.string(),
|
||||||
|
description: z.string().nullable(),
|
||||||
|
fork: z.boolean(),
|
||||||
|
url: z.string(),
|
||||||
|
created_at: z.string(),
|
||||||
|
updated_at: z.string(),
|
||||||
|
pushed_at: z.string(),
|
||||||
|
git_url: z.string(),
|
||||||
|
ssh_url: z.string(),
|
||||||
|
clone_url: z.string(),
|
||||||
|
default_branch: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const GithubFileContentLinks = z.object({
|
||||||
|
self: z.string(),
|
||||||
|
git: z.string().nullable(),
|
||||||
|
html: z.string().nullable()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const GitHubFileContentSchema = z.object({
|
||||||
|
name: z.string(),
|
||||||
|
path: z.string(),
|
||||||
|
sha: z.string(),
|
||||||
|
size: z.number(),
|
||||||
|
url: z.string(),
|
||||||
|
html_url: z.string(),
|
||||||
|
git_url: z.string(),
|
||||||
|
download_url: z.string(),
|
||||||
|
type: z.string(),
|
||||||
|
content: z.string().optional(),
|
||||||
|
encoding: z.string().optional(),
|
||||||
|
_links: GithubFileContentLinks
|
||||||
|
});
|
||||||
|
|
||||||
|
export const GitHubDirectoryContentSchema = z.object({
|
||||||
|
type: z.string(),
|
||||||
|
size: z.number(),
|
||||||
|
name: z.string(),
|
||||||
|
path: z.string(),
|
||||||
|
sha: z.string(),
|
||||||
|
url: z.string(),
|
||||||
|
git_url: z.string(),
|
||||||
|
html_url: z.string(),
|
||||||
|
download_url: z.string().nullable(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const GitHubContentSchema = z.union([
|
||||||
|
GitHubFileContentSchema,
|
||||||
|
z.array(GitHubDirectoryContentSchema),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const GitHubTreeEntrySchema = z.object({
|
||||||
|
path: z.string(),
|
||||||
|
mode: z.enum(["100644", "100755", "040000", "160000", "120000"]),
|
||||||
|
type: z.enum(["blob", "tree", "commit"]),
|
||||||
|
size: z.number().optional(),
|
||||||
|
sha: z.string(),
|
||||||
|
url: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const GitHubTreeSchema = z.object({
|
||||||
|
sha: z.string(),
|
||||||
|
url: z.string(),
|
||||||
|
tree: z.array(GitHubTreeEntrySchema),
|
||||||
|
truncated: z.boolean(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const GitHubCommitSchema = z.object({
|
||||||
|
sha: z.string(),
|
||||||
|
node_id: z.string(),
|
||||||
|
url: z.string(),
|
||||||
|
author: GitHubAuthorSchema,
|
||||||
|
committer: GitHubAuthorSchema,
|
||||||
|
message: z.string(),
|
||||||
|
tree: z.object({
|
||||||
|
sha: z.string(),
|
||||||
|
url: z.string(),
|
||||||
|
}),
|
||||||
|
parents: z.array(
|
||||||
|
z.object({
|
||||||
|
sha: z.string(),
|
||||||
|
url: z.string(),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const GitHubReferenceSchema = z.object({
|
||||||
|
ref: z.string(),
|
||||||
|
node_id: z.string(),
|
||||||
|
url: z.string(),
|
||||||
|
object: z.object({
|
||||||
|
sha: z.string(),
|
||||||
|
type: z.string(),
|
||||||
|
url: z.string(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Export types
|
||||||
|
export type GitHubAuthor = z.infer<typeof GitHubAuthorSchema>;
|
||||||
|
export type GitHubRepository = z.infer<typeof GitHubRepositorySchema>;
|
||||||
|
export type GitHubFileContent = z.infer<typeof GitHubFileContentSchema>;
|
||||||
|
export type GitHubDirectoryContent = z.infer<typeof GitHubDirectoryContentSchema>;
|
||||||
|
export type GitHubContent = z.infer<typeof GitHubContentSchema>;
|
||||||
|
export type GitHubTree = z.infer<typeof GitHubTreeSchema>;
|
||||||
|
export type GitHubCommit = z.infer<typeof GitHubCommitSchema>;
|
||||||
|
export type GitHubReference = z.infer<typeof GitHubReferenceSchema>;
|
||||||
Loading…
Reference in a new issue