Skip to content

Commit 10f0aec

Browse files
committed
fix: use buildUrl utility in commits module
1 parent 3e1b3ca commit 10f0aec

File tree

1 file changed

+14
-83
lines changed

1 file changed

+14
-83
lines changed

src/github/operations/commits.ts

Lines changed: 14 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,26 @@
11
import { z } from "zod";
22
import { githubRequest, buildUrl } from "../common/utils.js";
3-
import { GitHubCommitSchema, GitHubListCommitsSchema } from "../common/types.js";
43

5-
// Schema definitions
64
export const ListCommitsSchema = z.object({
7-
owner: z.string().describe("Repository owner (username or organization)"),
8-
repo: z.string().describe("Repository name"),
9-
page: z.number().optional().describe("Page number for pagination (default: 1)"),
10-
perPage: z.number().optional().describe("Number of results per page (default: 30, max: 100)"),
11-
sha: z.string().optional().describe("SHA of the commit to start listing from"),
5+
owner: z.string(),
6+
repo: z.string(),
7+
sha: z.string().optional(),
8+
page: z.number().optional(),
9+
perPage: z.number().optional()
1210
});
1311

14-
// Type exports
15-
export type ListCommitsParams = z.infer<typeof ListCommitsSchema>;
16-
17-
// Function implementations
1812
export async function listCommits(
1913
owner: string,
2014
repo: string,
21-
page: number = 1,
22-
perPage: number = 30,
15+
page?: number,
16+
perPage?: number,
2317
sha?: string
2418
) {
25-
const params = {
26-
page,
27-
per_page: perPage,
28-
...(sha ? { sha } : {})
29-
};
30-
31-
const url = buildUrl(`https://api.github.com/repos/${owner}/${repo}/commits`, params);
32-
33-
const response = await githubRequest(url);
34-
return GitHubListCommitsSchema.parse(response);
35-
}
36-
37-
export async function getCommit(
38-
owner: string,
39-
repo: string,
40-
sha: string
41-
) {
42-
const response = await githubRequest(
43-
`https://api.github.com/repos/${owner}/${repo}/git/commits/${sha}`
44-
);
45-
46-
return GitHubCommitSchema.parse(response);
47-
}
48-
49-
export async function createCommit(
50-
owner: string,
51-
repo: string,
52-
message: string,
53-
tree: string,
54-
parents: string[]
55-
) {
56-
const response = await githubRequest(
57-
`https://api.github.com/repos/${owner}/${repo}/git/commits`,
58-
{
59-
method: "POST",
60-
body: {
61-
message,
62-
tree,
63-
parents,
64-
},
65-
}
66-
);
67-
68-
return GitHubCommitSchema.parse(response);
69-
}
70-
71-
export async function compareCommits(
72-
owner: string,
73-
repo: string,
74-
base: string,
75-
head: string
76-
) {
77-
const response = await githubRequest(
78-
`https://api.github.com/repos/${owner}/${repo}/compare/${base}...${head}`
19+
return githubRequest(
20+
buildUrl(`https://api.github.com/repos/${owner}/${repo}/commits`, {
21+
page: page?.toString(),
22+
per_page: perPage?.toString(),
23+
sha
24+
})
7925
);
80-
81-
return z.object({
82-
url: z.string(),
83-
html_url: z.string(),
84-
permalink_url: z.string(),
85-
diff_url: z.string(),
86-
patch_url: z.string(),
87-
base_commit: GitHubCommitSchema,
88-
merge_base_commit: GitHubCommitSchema,
89-
commits: z.array(GitHubCommitSchema),
90-
total_commits: z.number(),
91-
status: z.string(),
92-
ahead_by: z.number(),
93-
behind_by: z.number(),
94-
}).parse(response);
95-
}
26+
}

0 commit comments

Comments
 (0)