Skip to content

Commit c31f00f

Browse files
fix contract
1 parent 44f68ef commit c31f00f

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/github/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
GitHubSearchResponseSchema,
1919
GitHubTreeSchema,
2020
GitHubCommitSchema,
21+
GitHubListCommitsSchema,
2122
CreateRepositoryOptionsSchema,
2223
CreateIssueOptionsSchema,
2324
CreatePullRequestOptionsSchema,
@@ -42,7 +43,8 @@ import {
4243
CreatePullRequestSchema,
4344
ForkRepositorySchema,
4445
CreateBranchSchema,
45-
ListCommitsSchema
46+
ListCommitsSchema,
47+
GitHubListCommits
4648
} from './schemas.js';
4749
import { z } from 'zod';
4850
import { zodToJsonSchema } from 'zod-to-json-schema';
@@ -474,7 +476,7 @@ async function listCommits(
474476
page: number = 1,
475477
perPage: number = 30,
476478
sha?: string,
477-
): Promise<GitHubCommit[]> {
479+
): Promise<GitHubListCommits> {
478480
const url = new URL(`https://api.github.com/repos/${owner}/${repo}/commits`);
479481
url.searchParams.append("page", page.toString());
480482
url.searchParams.append("per_page", perPage.toString());
@@ -499,7 +501,7 @@ async function listCommits(
499501
throw new Error(`GitHub API error: ${response.statusText}`);
500502
}
501503

502-
return GitHubCommitSchema.array().parse(await response.json());
504+
return GitHubListCommitsSchema.parse(await response.json());
503505
}
504506

505507
server.setRequestHandler(ListToolsRequestSchema, async () => {

src/github/schemas.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ export const GitHubTreeSchema = z.object({
9393
truncated: z.boolean()
9494
});
9595

96+
export const GitHubListCommitsSchema = z.array(z.object({
97+
sha: z.string(),
98+
node_id: z.string(),
99+
commit: z.object({
100+
author: GitHubAuthorSchema,
101+
committer: GitHubAuthorSchema,
102+
message: z.string(),
103+
tree: z.object({
104+
sha: z.string(),
105+
url: z.string()
106+
}),
107+
url: z.string(),
108+
comment_count: z.number(),
109+
}),
110+
url: z.string(),
111+
html_url: z.string(),
112+
comments_url: z.string()
113+
}));
114+
96115
export const GitHubCommitSchema = z.object({
97116
sha: z.string(),
98117
node_id: z.string(),
@@ -378,6 +397,7 @@ export type GitHubContent = z.infer<typeof GitHubContentSchema>;
378397
export type FileOperation = z.infer<typeof FileOperationSchema>;
379398
export type GitHubTree = z.infer<typeof GitHubTreeSchema>;
380399
export type GitHubCommit = z.infer<typeof GitHubCommitSchema>;
400+
export type GitHubListCommits = z.infer<typeof GitHubListCommitsSchema>;
381401
export type GitHubReference = z.infer<typeof GitHubReferenceSchema>;
382402
export type CreateRepositoryOptions = z.infer<typeof CreateRepositoryOptionsSchema>;
383403
export type CreateIssueOptions = z.infer<typeof CreateIssueOptionsSchema>;

0 commit comments

Comments
 (0)