@@ -7,113 +7,112 @@ import plainTextPlugin from "markdown-it-plain-text";
7
7
import { validatePOST } from "./validators" ;
8
8
9
9
interface MarkdownItWithPlainText extends markdownit {
10
- plainText : string ;
11
- }
12
-
10
+ plainText : string ;
11
+ }
12
+
13
13
interface IssueMetadata {
14
- nodeId : string ;
15
- number : number ;
16
- title : string ;
17
- body : string ;
18
- state : string ;
19
- repositoryName : string ;
20
- repositoryId : number ;
21
- assignees : string [ ] ;
22
- authorId : number ;
23
- createdAt : string ;
24
- closedAt : string | null ;
25
- stateReason : string | null ;
26
- updatedAt : string ;
27
- }
28
-
29
- interface IssueNode {
14
+ nodeId : string ;
15
+ number : number ;
16
+ title : string ;
17
+ body : string ;
18
+ state : string ;
19
+ repositoryName : string ;
20
+ repositoryId : number ;
21
+ assignees : string [ ] ;
22
+ authorId : number ;
23
+ createdAt : string ;
24
+ closedAt : string | null ;
25
+ stateReason : string | null ;
26
+ updatedAt : string ;
27
+ }
28
+
29
+ interface IssueNode {
30
+ id : string ;
31
+ number : number ;
32
+ title : string ;
33
+ body : string ;
34
+ state : string ;
35
+ stateReason : string | null ;
36
+ createdAt : string ;
37
+ updatedAt : string ;
38
+ closedAt : string | null ;
39
+ author : {
40
+ login : string ;
41
+ } | null ;
42
+ assignees : {
43
+ nodes : Array < {
44
+ login : string ;
45
+ } > ;
46
+ } ;
47
+ repository : {
30
48
id : string ;
31
- number : number ;
32
- title : string ;
33
- body : string ;
34
- state : string ;
35
- stateReason : string | null ;
36
- createdAt : string ;
37
- updatedAt : string ;
38
- closedAt : string | null ;
39
- author : {
49
+ name : string ;
50
+ owner : {
40
51
login : string ;
41
- } | null ;
42
- assignees : {
43
- nodes : Array < {
44
- login : string ;
45
- } > ;
46
52
} ;
47
- repository : {
48
- id : string ;
49
- name : string ;
50
- owner : {
51
- login : string ;
52
- } ;
53
- } ;
54
- }
55
-
56
- interface GraphQlSearchResponse {
57
- search : {
58
- pageInfo : {
59
- hasNextPage : boolean ;
60
- endCursor : string | null ;
61
- } ;
62
- nodes : Array < IssueNode > ;
53
+ } ;
54
+ }
55
+
56
+ interface GraphQlSearchResponse {
57
+ search : {
58
+ pageInfo : {
59
+ hasNextPage : boolean ;
60
+ endCursor : string | null ;
63
61
} ;
64
- }
62
+ nodes : Array < IssueNode > ;
63
+ } ;
64
+ }
65
65
66
66
export const corsHeaders = {
67
- "Access-Control-Allow-Origin" : "*" ,
68
- "Access-Control-Allow-Methods" : "GET" ,
69
- "Access-Control-Allow-Headers" : "Content-Type" ,
67
+ "Access-Control-Allow-Origin" : "*" ,
68
+ "Access-Control-Allow-Methods" : "GET" ,
69
+ "Access-Control-Allow-Headers" : "Content-Type" ,
70
70
} ;
71
71
72
72
export async function onRequest ( ctx : Context ) : Promise < Response > {
73
- const { request, env } = ctx ;
73
+ const { request, env } = ctx ;
74
74
75
- try {
76
- switch ( request . method ) {
77
- case "POST" : {
78
- const result = await validatePOST ( request ) ;
79
- if ( ! result . isValid || ! result . gitHubUserId ) {
80
- return new Response ( "Unauthorized" , {
81
- headers : corsHeaders ,
82
- status : 400 ,
83
- } ) ;
84
- }
85
- try {
86
- const supabase = new SupabaseClient ( env . SUPABASE_URL , env . SUPABASE_ANON_KEY ) ;
87
- const response = await issueScraper ( result . gitHubUserId , supabase , env . VOYAGEAI_API_KEY , result . authToken ) ;
88
- return new Response ( response , {
89
- headers : corsHeaders ,
90
- status : 200 ,
91
- } ) ;
92
- } catch ( error ) {
93
- console . error ( "Error processing request:" , error ) ;
94
- return new Response ( "Internal Server Error" , {
95
- headers : corsHeaders ,
96
- status : 500 ,
97
- } ) ;
98
- }
99
- }
100
-
101
- default :
102
- return new Response ( "Method Not Allowed" , {
103
- headers : corsHeaders ,
104
- status : 405 ,
105
- } ) ;
75
+ try {
76
+ switch ( request . method ) {
77
+ case "POST" : {
78
+ const result = await validatePOST ( request ) ;
79
+ if ( ! result . isValid || ! result . gitHubUserId ) {
80
+ return new Response ( "Unauthorized" , {
81
+ headers : corsHeaders ,
82
+ status : 400 ,
83
+ } ) ;
106
84
}
107
- } catch ( error ) {
108
- console . error ( "Error processing request:" , error ) ;
109
- return new Response ( "Internal Server Error" , {
85
+ try {
86
+ const supabase = new SupabaseClient ( env . SUPABASE_URL , env . SUPABASE_ANON_KEY ) ;
87
+ const response = await issueScraper ( result . gitHubUserId , supabase , env . VOYAGEAI_API_KEY , result . authToken ) ;
88
+ return new Response ( response , {
89
+ headers : corsHeaders ,
90
+ status : 200 ,
91
+ } ) ;
92
+ } catch ( error ) {
93
+ console . error ( "Error processing request:" , error ) ;
94
+ return new Response ( "Internal Server Error" , {
110
95
headers : corsHeaders ,
111
96
status : 500 ,
97
+ } ) ;
98
+ }
99
+ }
100
+
101
+ default :
102
+ return new Response ( "Method Not Allowed" , {
103
+ headers : corsHeaders ,
104
+ status : 405 ,
112
105
} ) ;
113
106
}
107
+ } catch ( error ) {
108
+ console . error ( "Error processing request:" , error ) ;
109
+ return new Response ( "Internal Server Error" , {
110
+ headers : corsHeaders ,
111
+ status : 500 ,
112
+ } ) ;
113
+ }
114
114
}
115
115
116
-
117
116
function markdownToPlainText ( markdown : string | null ) : string | null {
118
117
if ( ! markdown ) return markdown ;
119
118
const md = markdownit ( ) as MarkdownItWithPlainText ;
@@ -122,7 +121,6 @@ function markdownToPlainText(markdown: string | null): string | null {
122
121
return md . plainText ;
123
122
}
124
123
125
-
126
124
const SEARCH_ISSUES_QUERY = `
127
125
query SearchIssues($searchText: String!, $after: String) {
128
126
search(
@@ -209,7 +207,6 @@ async function fetchUserIssues(octokit: InstanceType<typeof Octokit>, username:
209
207
// Pulls issues from GitHub and stores them in Supabase
210
208
async function issueScraper ( username : string , supabase : SupabaseClient , voyageApiKey : string , token ?: string ) : Promise < string > {
211
209
try {
212
-
213
210
if ( ! username ) {
214
211
throw new Error ( "Username is required" ) ;
215
212
}
0 commit comments