1
1
import { z } from "zod" ;
2
2
import { githubRequest , buildUrl } from "../common/utils.js" ;
3
3
4
- // Schema definitions
5
- export const SearchCodeSchema = z . object ( {
6
- q : z . string ( ) . describe ( "Search query. See GitHub code search syntax: https://docs.github.com/en/search-github/searching-on-github/searching-code" ) ,
7
- order : z . enum ( [ "asc" , "desc" ] ) . optional ( ) . describe ( "Sort order (asc or desc)" ) ,
8
- per_page : z . number ( ) . min ( 1 ) . max ( 100 ) . optional ( ) . describe ( "Results per page (max 100)" ) ,
9
- page : z . number ( ) . min ( 1 ) . optional ( ) . describe ( "Page number" ) ,
4
+ export const SearchOptions = z . object ( {
5
+ q : z . string ( ) ,
6
+ order : z . enum ( [ "asc" , "desc" ] ) . optional ( ) ,
7
+ page : z . number ( ) . min ( 1 ) . optional ( ) ,
8
+ per_page : z . number ( ) . min ( 1 ) . max ( 100 ) . optional ( ) ,
10
9
} ) ;
11
10
12
- export const SearchIssuesSchema = z . object ( {
13
- q : z . string ( ) . describe ( "Search query. See GitHub issues search syntax: https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests" ) ,
11
+ export const SearchUsersOptions = SearchOptions . extend ( {
12
+ sort : z . enum ( [ "followers" , "repositories" , "joined" ] ) . optional ( ) ,
13
+ } ) ;
14
+
15
+ export const SearchIssuesOptions = SearchOptions . extend ( {
14
16
sort : z . enum ( [
15
17
"comments" ,
16
18
"reactions" ,
@@ -23,82 +25,21 @@ export const SearchIssuesSchema = z.object({
23
25
"interactions" ,
24
26
"created" ,
25
27
"updated" ,
26
- ] ) . optional ( ) . describe ( "Sort field" ) ,
27
- order : z . enum ( [ "asc" , "desc" ] ) . optional ( ) . describe ( "Sort order (asc or desc)" ) ,
28
- per_page : z . number ( ) . min ( 1 ) . max ( 100 ) . optional ( ) . describe ( "Results per page (max 100)" ) ,
29
- page : z . number ( ) . min ( 1 ) . optional ( ) . describe ( "Page number" ) ,
30
- } ) ;
31
-
32
- export const SearchUsersSchema = z . object ( {
33
- q : z . string ( ) . describe ( "Search query. See GitHub users search syntax: https://docs.github.com/en/search-github/searching-on-github/searching-users" ) ,
34
- sort : z . enum ( [ "followers" , "repositories" , "joined" ] ) . optional ( ) . describe ( "Sort field" ) ,
35
- order : z . enum ( [ "asc" , "desc" ] ) . optional ( ) . describe ( "Sort order (asc or desc)" ) ,
36
- per_page : z . number ( ) . min ( 1 ) . max ( 100 ) . optional ( ) . describe ( "Results per page (max 100)" ) ,
37
- page : z . number ( ) . min ( 1 ) . optional ( ) . describe ( "Page number" ) ,
28
+ ] ) . optional ( ) ,
38
29
} ) ;
39
30
40
- // Response schemas
41
- export const SearchCodeItemSchema = z . object ( {
42
- name : z . string ( ) . describe ( "The name of the file" ) ,
43
- path : z . string ( ) . describe ( "The path to the file in the repository" ) ,
44
- sha : z . string ( ) . describe ( "The SHA hash of the file" ) ,
45
- url : z . string ( ) . describe ( "The API URL for this file" ) ,
46
- git_url : z . string ( ) . describe ( "The Git URL for this file" ) ,
47
- html_url : z . string ( ) . describe ( "The HTML URL to view this file on GitHub" ) ,
48
- repository : z . object ( {
49
- full_name : z . string ( ) ,
50
- description : z . string ( ) . nullable ( ) ,
51
- url : z . string ( ) ,
52
- html_url : z . string ( ) ,
53
- } ) . describe ( "The repository where this file was found" ) ,
54
- score : z . number ( ) . describe ( "The search result score" ) ,
55
- } ) ;
31
+ export const SearchCodeSchema = SearchOptions ;
32
+ export const SearchUsersSchema = SearchUsersOptions ;
33
+ export const SearchIssuesSchema = SearchIssuesOptions ;
56
34
57
- export const SearchCodeResponseSchema = z . object ( {
58
- total_count : z . number ( ) . describe ( "Total number of matching results" ) ,
59
- incomplete_results : z . boolean ( ) . describe ( "Whether the results are incomplete" ) ,
60
- items : z . array ( SearchCodeItemSchema ) . describe ( "The search results" ) ,
61
- } ) ;
62
-
63
- export const SearchUsersResponseSchema = z . object ( {
64
- total_count : z . number ( ) . describe ( "Total number of matching results" ) ,
65
- incomplete_results : z . boolean ( ) . describe ( "Whether the results are incomplete" ) ,
66
- items : z . array ( z . object ( {
67
- login : z . string ( ) . describe ( "The username of the user" ) ,
68
- id : z . number ( ) . describe ( "The ID of the user" ) ,
69
- node_id : z . string ( ) . describe ( "The Node ID of the user" ) ,
70
- avatar_url : z . string ( ) . describe ( "The avatar URL of the user" ) ,
71
- gravatar_id : z . string ( ) . describe ( "The Gravatar ID of the user" ) ,
72
- url : z . string ( ) . describe ( "The API URL for this user" ) ,
73
- html_url : z . string ( ) . describe ( "The HTML URL to view this user on GitHub" ) ,
74
- type : z . string ( ) . describe ( "The type of this user" ) ,
75
- site_admin : z . boolean ( ) . describe ( "Whether this user is a site administrator" ) ,
76
- score : z . number ( ) . describe ( "The search result score" ) ,
77
- } ) ) . describe ( "The search results" ) ,
78
- } ) ;
79
-
80
- // Type exports
81
- export type SearchCodeParams = z . infer < typeof SearchCodeSchema > ;
82
- export type SearchIssuesParams = z . infer < typeof SearchIssuesSchema > ;
83
- export type SearchUsersParams = z . infer < typeof SearchUsersSchema > ;
84
- export type SearchCodeResponse = z . infer < typeof SearchCodeResponseSchema > ;
85
- export type SearchUsersResponse = z . infer < typeof SearchUsersResponseSchema > ;
86
-
87
- // Function implementations
88
- export async function searchCode ( params : SearchCodeParams ) : Promise < SearchCodeResponse > {
89
- const url = buildUrl ( "https://api.github.com/search/code" , params ) ;
90
- const response = await githubRequest ( url ) ;
91
- return SearchCodeResponseSchema . parse ( response ) ;
35
+ export async function searchCode ( params : z . infer < typeof SearchCodeSchema > ) {
36
+ return githubRequest ( buildUrl ( "https://api.github.com/search/code" , params ) ) ;
92
37
}
93
38
94
- export async function searchIssues ( params : SearchIssuesParams ) {
95
- const url = buildUrl ( "https://api.github.com/search/issues" , params ) ;
96
- const response = await githubRequest ( url ) ;
97
- return response ;
39
+ export async function searchIssues ( params : z . infer < typeof SearchIssuesSchema > ) {
40
+ return githubRequest ( buildUrl ( "https://api.github.com/search/issues" , params ) ) ;
98
41
}
99
42
100
- export async function searchUsers ( params : SearchUsersParams ) : Promise < SearchUsersResponse > {
101
- const url = buildUrl ( "https://api.github.com/search/users" , params ) ;
102
- const response = await githubRequest ( url ) ;
103
- return SearchUsersResponseSchema . parse ( response ) ;
104
- }
43
+ export async function searchUsers ( params : z . infer < typeof SearchUsersSchema > ) {
44
+ return githubRequest ( buildUrl ( "https://api.github.com/search/users" , params ) ) ;
45
+ }
0 commit comments