1
1
import { z } from "zod" ;
2
2
import { githubRequest , buildUrl } from "../common/utils.js" ;
3
- import {
4
- GitHubIssueSchema ,
5
- GitHubLabelSchema ,
6
- GitHubIssueAssigneeSchema ,
7
- GitHubMilestoneSchema ,
8
- } from "../common/types.js" ;
9
3
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
+
11
17
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 ( ) ,
17
23
} ) ;
18
24
19
25
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 ,
27
29
} ) ;
28
30
29
31
export const ListIssuesOptionsSchema = z . object ( {
30
32
owner : z . string ( ) ,
31
33
repo : z . string ( ) ,
32
- state : z . enum ( [ 'open' , 'closed' , 'all' ] ) . optional ( ) ,
34
+ direction : z . enum ( [ "asc" , "desc" ] ) . optional ( ) ,
33
35
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
37
36
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 ( ) ,
39
41
} ) ;
40
42
41
43
export const UpdateIssueOptionsSchema = z . object ( {
@@ -44,108 +46,63 @@ export const UpdateIssueOptionsSchema = z.object({
44
46
issue_number : z . number ( ) ,
45
47
title : z . string ( ) . optional ( ) ,
46
48
body : z . string ( ) . optional ( ) ,
47
- state : z . enum ( [ 'open' , 'closed' ] ) . optional ( ) ,
48
- labels : z . array ( z . string ( ) ) . optional ( ) ,
49
49
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 ( ) ,
58
53
} ) ;
59
54
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
+ }
65
58
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
+ }
70
70
71
- // Function implementations
72
71
export async function createIssue (
73
72
owner : string ,
74
73
repo : string ,
75
- options : CreateIssueOptions
74
+ options : z . infer < typeof CreateIssueOptionsSchema >
76
75
) {
77
- const response = await githubRequest (
76
+ return githubRequest (
78
77
`https://api.github.com/repos/${ owner } /${ repo } /issues` ,
79
78
{
80
79
method : "POST" ,
81
80
body : options ,
82
81
}
83
82
) ;
84
-
85
- return GitHubIssueSchema . parse ( response ) ;
86
83
}
87
84
88
85
export async function listIssues (
89
86
owner : string ,
90
87
repo : string ,
91
- options : Omit < ListIssuesOptions , ' owner' | ' repo' >
88
+ options : Omit < z . infer < typeof ListIssuesOptionsSchema > , " owner" | " repo" >
92
89
) {
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
+ ) ;
96
93
}
97
94
98
95
export async function updateIssue (
99
96
owner : string ,
100
97
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" >
103
100
) {
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 } ` ,
106
103
{
107
104
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 ,
126
106
}
127
107
) ;
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