mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-23 14:25:15 +02:00
fix: use buildUrl utility in commits module
This commit is contained in:
@@ -1,95 +1,26 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { githubRequest, buildUrl } from "../common/utils.js";
|
import { githubRequest, buildUrl } from "../common/utils.js";
|
||||||
import { GitHubCommitSchema, GitHubListCommitsSchema } from "../common/types.js";
|
|
||||||
|
|
||||||
// Schema definitions
|
|
||||||
export const ListCommitsSchema = z.object({
|
export const ListCommitsSchema = z.object({
|
||||||
owner: z.string().describe("Repository owner (username or organization)"),
|
owner: z.string(),
|
||||||
repo: z.string().describe("Repository name"),
|
repo: z.string(),
|
||||||
page: z.number().optional().describe("Page number for pagination (default: 1)"),
|
sha: z.string().optional(),
|
||||||
perPage: z.number().optional().describe("Number of results per page (default: 30, max: 100)"),
|
page: z.number().optional(),
|
||||||
sha: z.string().optional().describe("SHA of the commit to start listing from"),
|
perPage: z.number().optional()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Type exports
|
|
||||||
export type ListCommitsParams = z.infer<typeof ListCommitsSchema>;
|
|
||||||
|
|
||||||
// Function implementations
|
|
||||||
export async function listCommits(
|
export async function listCommits(
|
||||||
owner: string,
|
owner: string,
|
||||||
repo: string,
|
repo: string,
|
||||||
page: number = 1,
|
page?: number,
|
||||||
perPage: number = 30,
|
perPage?: number,
|
||||||
sha?: string
|
sha?: string
|
||||||
) {
|
) {
|
||||||
const params = {
|
return githubRequest(
|
||||||
page,
|
buildUrl(`https://api.github.com/repos/${owner}/${repo}/commits`, {
|
||||||
per_page: perPage,
|
page: page?.toString(),
|
||||||
...(sha ? { sha } : {})
|
per_page: perPage?.toString(),
|
||||||
};
|
sha
|
||||||
|
})
|
||||||
const url = buildUrl(`https://api.github.com/repos/${owner}/${repo}/commits`, params);
|
|
||||||
|
|
||||||
const response = await githubRequest(url);
|
|
||||||
return GitHubListCommitsSchema.parse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getCommit(
|
|
||||||
owner: string,
|
|
||||||
repo: string,
|
|
||||||
sha: string
|
|
||||||
) {
|
|
||||||
const response = await githubRequest(
|
|
||||||
`https://api.github.com/repos/${owner}/${repo}/git/commits/${sha}`
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return GitHubCommitSchema.parse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createCommit(
|
|
||||||
owner: string,
|
|
||||||
repo: string,
|
|
||||||
message: string,
|
|
||||||
tree: string,
|
|
||||||
parents: string[]
|
|
||||||
) {
|
|
||||||
const response = await githubRequest(
|
|
||||||
`https://api.github.com/repos/${owner}/${repo}/git/commits`,
|
|
||||||
{
|
|
||||||
method: "POST",
|
|
||||||
body: {
|
|
||||||
message,
|
|
||||||
tree,
|
|
||||||
parents,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return GitHubCommitSchema.parse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function compareCommits(
|
|
||||||
owner: string,
|
|
||||||
repo: string,
|
|
||||||
base: string,
|
|
||||||
head: string
|
|
||||||
) {
|
|
||||||
const response = await githubRequest(
|
|
||||||
`https://api.github.com/repos/${owner}/${repo}/compare/${base}...${head}`
|
|
||||||
);
|
|
||||||
|
|
||||||
return z.object({
|
|
||||||
url: z.string(),
|
|
||||||
html_url: z.string(),
|
|
||||||
permalink_url: z.string(),
|
|
||||||
diff_url: z.string(),
|
|
||||||
patch_url: z.string(),
|
|
||||||
base_commit: GitHubCommitSchema,
|
|
||||||
merge_base_commit: GitHubCommitSchema,
|
|
||||||
commits: z.array(GitHubCommitSchema),
|
|
||||||
total_commits: z.number(),
|
|
||||||
status: z.string(),
|
|
||||||
ahead_by: z.number(),
|
|
||||||
behind_by: z.number(),
|
|
||||||
}).parse(response);
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user