@@ -2,20 +2,70 @@ import * as https from "https";
22import { URL } from "url" ;
33import { maskSecret , normalizeBaseUrl } from "./util" ;
44
5+ export interface IssueActionItem {
6+ id : string ;
7+ issue_id : string ;
8+ title : string ;
9+ description : string | null ;
10+ severity : number ;
11+ is_done : boolean ;
12+ done_by : number | null ;
13+ done_at : string | null ;
14+ created_at : string ;
15+ updated_at : string ;
16+ }
17+
18+ export interface Issue {
19+ id : string ;
20+ title : string ;
21+ description : string | null ;
22+ created_at : string ;
23+ updated_at : string ;
24+ status : number ;
25+ url_main : string | null ;
26+ urls_extra : string [ ] | null ;
27+ data : unknown | null ;
28+ author_id : number ;
29+ org_id : number ;
30+ project_id : number | null ;
31+ is_ai_generated : boolean ;
32+ assigned_to : number [ ] | null ;
33+ labels : string [ ] | null ;
34+ is_edited : boolean ;
35+ author_display_name : string ;
36+ comment_count : number ;
37+ action_items : IssueActionItem [ ] ;
38+ }
39+
40+ export interface IssueComment {
41+ id : string ;
42+ issue_id : string ;
43+ author_id : number ;
44+ parent_comment_id : string | null ;
45+ content : string ;
46+ created_at : string ;
47+ updated_at : string ;
48+ data : unknown | null ;
49+ }
50+
51+ export type IssueListItem = Pick < Issue , "id" | "title" | "status" | "created_at" > ;
52+
53+ export type IssueDetail = Pick < Issue , "id" | "title" | "description" | "status" | "created_at" | "author_display_name" > ;
554export interface FetchIssuesParams {
655 apiKey : string ;
756 apiBaseUrl : string ;
857 debug ?: boolean ;
958}
1059
11- export async function fetchIssues ( params : FetchIssuesParams ) : Promise < unknown > {
60+ export async function fetchIssues ( params : FetchIssuesParams ) : Promise < IssueListItem [ ] > {
1261 const { apiKey, apiBaseUrl, debug } = params ;
1362 if ( ! apiKey ) {
1463 throw new Error ( "API key is required" ) ;
1564 }
1665
1766 const base = normalizeBaseUrl ( apiBaseUrl ) ;
1867 const url = new URL ( `${ base } /issues` ) ;
68+ url . searchParams . set ( "select" , "id,title,status,created_at" ) ;
1969
2070 const headers : Record < string , string > = {
2171 "access-token" : apiKey ,
@@ -54,10 +104,10 @@ export async function fetchIssues(params: FetchIssuesParams): Promise<unknown> {
54104 }
55105 if ( res . statusCode && res . statusCode >= 200 && res . statusCode < 300 ) {
56106 try {
57- const parsed = JSON . parse ( data ) ;
107+ const parsed = JSON . parse ( data ) as IssueListItem [ ] ;
58108 resolve ( parsed ) ;
59109 } catch {
60- resolve ( data ) ;
110+ reject ( new Error ( `Failed to parse issues response: ${ data } ` ) ) ;
61111 }
62112 } else {
63113 let errMsg = `Failed to fetch issues: HTTP ${ res . statusCode } ` ;
@@ -88,7 +138,7 @@ export interface FetchIssueCommentsParams {
88138 debug ?: boolean ;
89139}
90140
91- export async function fetchIssueComments ( params : FetchIssueCommentsParams ) : Promise < unknown > {
141+ export async function fetchIssueComments ( params : FetchIssueCommentsParams ) : Promise < IssueComment [ ] > {
92142 const { apiKey, apiBaseUrl, issueId, debug } = params ;
93143 if ( ! apiKey ) {
94144 throw new Error ( "API key is required" ) ;
@@ -137,10 +187,10 @@ export async function fetchIssueComments(params: FetchIssueCommentsParams): Prom
137187 }
138188 if ( res . statusCode && res . statusCode >= 200 && res . statusCode < 300 ) {
139189 try {
140- const parsed = JSON . parse ( data ) ;
190+ const parsed = JSON . parse ( data ) as IssueComment [ ] ;
141191 resolve ( parsed ) ;
142192 } catch {
143- resolve ( data ) ;
193+ reject ( new Error ( `Failed to parse issue comments response: ${ data } ` ) ) ;
144194 }
145195 } else {
146196 let errMsg = `Failed to fetch issue comments: HTTP ${ res . statusCode } ` ;
@@ -170,7 +220,7 @@ export interface FetchIssueParams {
170220 debug ?: boolean ;
171221}
172222
173- export async function fetchIssue ( params : FetchIssueParams ) : Promise < unknown > {
223+ export async function fetchIssue ( params : FetchIssueParams ) : Promise < IssueDetail | null > {
174224 const { apiKey, apiBaseUrl, issueId, debug } = params ;
175225 if ( ! apiKey ) {
176226 throw new Error ( "API key is required" ) ;
@@ -181,6 +231,7 @@ export async function fetchIssue(params: FetchIssueParams): Promise<unknown> {
181231
182232 const base = normalizeBaseUrl ( apiBaseUrl ) ;
183233 const url = new URL ( `${ base } /issues` ) ;
234+ url . searchParams . set ( "select" , "id,title,description,status,created_at,author_display_name" ) ;
184235 url . searchParams . set ( "id" , `eq.${ issueId } ` ) ;
185236 url . searchParams . set ( "limit" , "1" ) ;
186237
@@ -223,12 +274,12 @@ export async function fetchIssue(params: FetchIssueParams): Promise<unknown> {
223274 try {
224275 const parsed = JSON . parse ( data ) ;
225276 if ( Array . isArray ( parsed ) ) {
226- resolve ( parsed [ 0 ] ?? null ) ;
277+ resolve ( ( parsed [ 0 ] as IssueDetail ) ?? null ) ;
227278 } else {
228- resolve ( parsed ) ;
279+ resolve ( parsed as IssueDetail ) ;
229280 }
230281 } catch {
231- resolve ( data ) ;
282+ reject ( new Error ( `Failed to parse issue response: ${ data } ` ) ) ;
232283 }
233284 } else {
234285 let errMsg = `Failed to fetch issue: HTTP ${ res . statusCode } ` ;
@@ -260,7 +311,7 @@ export interface CreateIssueCommentParams {
260311 debug ?: boolean ;
261312}
262313
263- export async function createIssueComment ( params : CreateIssueCommentParams ) : Promise < unknown > {
314+ export async function createIssueComment ( params : CreateIssueCommentParams ) : Promise < IssueComment > {
264315 const { apiKey, apiBaseUrl, issueId, content, parentCommentId, debug } = params ;
265316 if ( ! apiKey ) {
266317 throw new Error ( "API key is required" ) ;
@@ -324,10 +375,10 @@ export async function createIssueComment(params: CreateIssueCommentParams): Prom
324375 }
325376 if ( res . statusCode && res . statusCode >= 200 && res . statusCode < 300 ) {
326377 try {
327- const parsed = JSON . parse ( data ) ;
378+ const parsed = JSON . parse ( data ) as IssueComment ;
328379 resolve ( parsed ) ;
329380 } catch {
330- resolve ( data ) ;
381+ reject ( new Error ( `Failed to parse create comment response: ${ data } ` ) ) ;
331382 }
332383 } else {
333384 let errMsg = `Failed to create issue comment: HTTP ${ res . statusCode } ` ;
0 commit comments