Skip to content

Commit dac0b7c

Browse files
committed
fix: use buildUrl utility in issues module
1 parent 10f0aec commit dac0b7c

File tree

1 file changed

+55
-98
lines changed

1 file changed

+55
-98
lines changed

src/github/operations/issues.ts

Lines changed: 55 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
11
import { z } from "zod";
22
import { githubRequest, buildUrl } from "../common/utils.js";
3-
import {
4-
GitHubIssueSchema,
5-
GitHubLabelSchema,
6-
GitHubIssueAssigneeSchema,
7-
GitHubMilestoneSchema,
8-
} from "../common/types.js";
93

10-
// Schema definitions
4+
export const GetIssueSchema = z.object({
5+
owner: z.string(),
6+
repo: z.string(),
7+
issue_number: z.number(),
8+
});
9+
10+
export const IssueCommentSchema = z.object({
11+
owner: z.string(),
12+
repo: z.string(),
13+
issue_number: z.number(),
14+
body: z.string(),
15+
});
16+
1117
export const CreateIssueOptionsSchema = z.object({
12-
title: z.string().describe("Issue title"),
13-
body: z.string().optional().describe("Issue body/description"),
14-
assignees: z.array(z.string()).optional().describe("Array of usernames to assign"),
15-
milestone: z.number().optional().describe("Milestone number to assign"),
16-
labels: z.array(z.string()).optional().describe("Array of label names"),
18+
title: z.string(),
19+
body: z.string().optional(),
20+
assignees: z.array(z.string()).optional(),
21+
milestone: z.number().optional(),
22+
labels: z.array(z.string()).optional(),
1723
});
1824

1925
export const CreateIssueSchema = z.object({
20-
owner: z.string().describe("Repository owner (username or organization)"),
21-
repo: z.string().describe("Repository name"),
22-
title: z.string().describe("Issue title"),
23-
body: z.string().optional().describe("Issue body/description"),
24-
assignees: z.array(z.string()).optional().describe("Array of usernames to assign"),
25-
labels: z.array(z.string()).optional().describe("Array of label names"),
26-
milestone: z.number().optional().describe("Milestone number to assign"),
26+
owner: z.string(),
27+
repo: z.string(),
28+
...CreateIssueOptionsSchema.shape,
2729
});
2830

2931
export const ListIssuesOptionsSchema = z.object({
3032
owner: z.string(),
3133
repo: z.string(),
32-
state: z.enum(['open', 'closed', 'all']).optional(),
34+
direction: z.enum(["asc", "desc"]).optional(),
3335
labels: z.array(z.string()).optional(),
34-
sort: z.enum(['created', 'updated', 'comments']).optional(),
35-
direction: z.enum(['asc', 'desc']).optional(),
36-
since: z.string().optional(), // ISO 8601 timestamp
3736
page: z.number().optional(),
38-
per_page: z.number().optional()
37+
per_page: z.number().optional(),
38+
since: z.string().optional(),
39+
sort: z.enum(["created", "updated", "comments"]).optional(),
40+
state: z.enum(["open", "closed", "all"]).optional(),
3941
});
4042

4143
export const UpdateIssueOptionsSchema = z.object({
@@ -44,108 +46,63 @@ export const UpdateIssueOptionsSchema = z.object({
4446
issue_number: z.number(),
4547
title: z.string().optional(),
4648
body: z.string().optional(),
47-
state: z.enum(['open', 'closed']).optional(),
48-
labels: z.array(z.string()).optional(),
4949
assignees: z.array(z.string()).optional(),
50-
milestone: z.number().optional()
51-
});
52-
53-
export const IssueCommentSchema = z.object({
54-
owner: z.string(),
55-
repo: z.string(),
56-
issue_number: z.number(),
57-
body: z.string()
50+
milestone: z.number().optional(),
51+
labels: z.array(z.string()).optional(),
52+
state: z.enum(["open", "closed"]).optional(),
5853
});
5954

60-
export const GetIssueSchema = z.object({
61-
owner: z.string().describe("Repository owner (username or organization)"),
62-
repo: z.string().describe("Repository name"),
63-
issue_number: z.number().describe("Issue number")
64-
});
55+
export async function getIssue(owner: string, repo: string, issue_number: number) {
56+
return githubRequest(`https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}`);
57+
}
6558

66-
// Type exports
67-
export type CreateIssueOptions = z.infer<typeof CreateIssueOptionsSchema>;
68-
export type ListIssuesOptions = z.infer<typeof ListIssuesOptionsSchema>;
69-
export type UpdateIssueOptions = z.infer<typeof UpdateIssueOptionsSchema>;
59+
export async function addIssueComment(
60+
owner: string,
61+
repo: string,
62+
issue_number: number,
63+
body: string
64+
) {
65+
return githubRequest(`https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}/comments`, {
66+
method: "POST",
67+
body: { body },
68+
});
69+
}
7070

71-
// Function implementations
7271
export async function createIssue(
7372
owner: string,
7473
repo: string,
75-
options: CreateIssueOptions
74+
options: z.infer<typeof CreateIssueOptionsSchema>
7675
) {
77-
const response = await githubRequest(
76+
return githubRequest(
7877
`https://api.github.com/repos/${owner}/${repo}/issues`,
7978
{
8079
method: "POST",
8180
body: options,
8281
}
8382
);
84-
85-
return GitHubIssueSchema.parse(response);
8683
}
8784

8885
export async function listIssues(
8986
owner: string,
9087
repo: string,
91-
options: Omit<ListIssuesOptions, 'owner' | 'repo'>
88+
options: Omit<z.infer<typeof ListIssuesOptionsSchema>, "owner" | "repo">
9289
) {
93-
const url = buildUrl(`https://api.github.com/repos/${owner}/${repo}/issues`, options);
94-
const response = await githubRequest(url);
95-
return z.array(GitHubIssueSchema).parse(response);
90+
return githubRequest(
91+
buildUrl(`https://api.github.com/repos/${owner}/${repo}/issues`, options)
92+
);
9693
}
9794

9895
export async function updateIssue(
9996
owner: string,
10097
repo: string,
101-
issueNumber: number,
102-
options: Omit<UpdateIssueOptions, 'owner' | 'repo' | 'issue_number'>
98+
issue_number: number,
99+
options: Omit<z.infer<typeof UpdateIssueOptionsSchema>, "owner" | "repo" | "issue_number">
103100
) {
104-
const response = await githubRequest(
105-
`https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}`,
101+
return githubRequest(
102+
`https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}`,
106103
{
107104
method: "PATCH",
108-
body: options
109-
}
110-
);
111-
112-
return GitHubIssueSchema.parse(response);
113-
}
114-
115-
export async function addIssueComment(
116-
owner: string,
117-
repo: string,
118-
issueNumber: number,
119-
body: string
120-
) {
121-
const response = await githubRequest(
122-
`https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}/comments`,
123-
{
124-
method: "POST",
125-
body: { body }
105+
body: options,
126106
}
127107
);
128-
129-
return z.object({
130-
id: z.number(),
131-
node_id: z.string(),
132-
url: z.string(),
133-
html_url: z.string(),
134-
body: z.string(),
135-
user: GitHubIssueAssigneeSchema,
136-
created_at: z.string(),
137-
updated_at: z.string(),
138-
}).parse(response);
139-
}
140-
141-
export async function getIssue(
142-
owner: string,
143-
repo: string,
144-
issueNumber: number
145-
) {
146-
const response = await githubRequest(
147-
`https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}`
148-
);
149-
150-
return GitHubIssueSchema.parse(response);
151-
}
108+
}

0 commit comments

Comments
 (0)