@@ -22,16 +22,17 @@ export function createGitHubIssueProvider(config: GitHubProviderConfig): IssuePr
2222 return stdout
2323 }
2424
25- function mapIssue ( raw : Record < string , unknown > ) : Issue {
25+ function mapIssue ( raw : Record < string , unknown > , kind : 'issue' | 'pr' = 'issue' ) : Issue {
2626 return {
2727 id : String ( raw . number ) ,
28+ kind,
2829 projectId : config . projectId ,
2930 orgId : config . orgId ,
3031 remote : config . remote ,
3132 provider : 'github' ,
3233 title : String ( raw . title ?? '' ) ,
3334 body : String ( raw . body ?? '' ) ,
34- state : raw . state === 'CLOSED' ? 'closed' : 'open' ,
35+ state : raw . state === 'CLOSED' || raw . state === 'MERGED' ? 'closed' : 'open' ,
3536 labels : Array . isArray ( raw . labels )
3637 ? ( raw . labels as Array < { name : string } > ) . map ( ( l ) => ( typeof l === 'string' ? l : l . name ) )
3738 : [ ] ,
@@ -66,38 +67,60 @@ export function createGitHubIssueProvider(config: GitHubProviderConfig): IssuePr
6667
6768 return {
6869 async list ( _repoPath : string , filter ?: IssueFilter ) : Promise < Issue [ ] > {
69- const args = [
70+ // Fetch issues
71+ const issueArgs = [
7072 'issue' ,
7173 'list' ,
7274 '-R' ,
7375 config . repo ,
7476 '--json' ,
7577 'number,title,body,state,labels,assignees,author,createdAt,updatedAt,url,comments'
7678 ]
77- if ( filter ?. state ) args . push ( '--state' , filter . state === 'closed' ? 'closed' : 'open' )
78- if ( filter ?. label ) args . push ( '--label' , filter . label )
79- if ( filter ?. assignee ) args . push ( '--assignee' , filter . assignee )
80- if ( filter ?. q ) args . push ( '--search' , filter . q )
81- if ( filter ?. limit ) args . push ( '--limit' , String ( filter . limit ) )
79+ if ( filter ?. state ) issueArgs . push ( '--state' , filter . state === 'closed' ? 'closed' : 'open' )
80+ if ( filter ?. label ) issueArgs . push ( '--label' , filter . label )
81+ if ( filter ?. assignee ) issueArgs . push ( '--assignee' , filter . assignee )
82+ if ( filter ?. q ) issueArgs . push ( '--search' , filter . q )
83+ if ( filter ?. limit ) issueArgs . push ( '--limit' , String ( filter . limit ) )
84+
85+ const issueOutput = await gh ( issueArgs )
86+ const issues = ( JSON . parse ( issueOutput ) as Array < Record < string , unknown > > ) . map ( ( i ) => mapIssue ( i , 'issue' ) )
87+
88+ // Fetch PRs
89+ const prArgs = [
90+ 'pr' ,
91+ 'list' ,
92+ '-R' ,
93+ config . repo ,
94+ '--json' ,
95+ 'number,title,body,state,labels,assignees,author,createdAt,updatedAt,url,comments'
96+ ]
97+ if ( filter ?. state ) prArgs . push ( '--state' , filter . state === 'closed' ? 'closed' : 'open' )
98+ if ( filter ?. label ) prArgs . push ( '--label' , filter . label )
99+ if ( filter ?. assignee ) prArgs . push ( '--assignee' , filter . assignee )
100+ if ( filter ?. q ) prArgs . push ( '--search' , filter . q )
101+ if ( filter ?. limit ) prArgs . push ( '--limit' , String ( filter . limit ) )
82102
83- const output = await gh ( args )
84- const items = JSON . parse ( output ) as Array < Record < string , unknown > >
85- return items . map ( ( i ) => mapIssue ( i ) )
103+ const prOutput = await gh ( prArgs )
104+ const prs = ( JSON . parse ( prOutput ) as Array < Record < string , unknown > > ) . map ( ( i ) => mapIssue ( i , 'pr' ) )
105+
106+ return [ ...issues , ...prs ]
86107 } ,
87108
88109 async get ( _repoPath : string , issueId : string ) : Promise < Issue | undefined > {
110+ const fields = 'number,title,body,state,labels,assignees,author,createdAt,updatedAt,url,comments'
111+ // Try as issue first
112+ try {
113+ const output = await gh ( [ 'issue' , 'view' , issueId , '-R' , config . repo , '--json' , fields ] )
114+ const raw = JSON . parse ( output ) as Record < string , unknown >
115+ return mapIssue ( raw , 'issue' )
116+ } catch {
117+ // Fall through to try as PR
118+ }
119+ // Try as PR
89120 try {
90- const output = await gh ( [
91- 'issue' ,
92- 'view' ,
93- issueId ,
94- '-R' ,
95- config . repo ,
96- '--json' ,
97- 'number,title,body,state,labels,assignees,author,createdAt,updatedAt,url,comments'
98- ] )
121+ const output = await gh ( [ 'pr' , 'view' , issueId , '-R' , config . repo , '--json' , fields ] )
99122 const raw = JSON . parse ( output ) as Record < string , unknown >
100- return mapIssue ( raw )
123+ return mapIssue ( raw , 'pr' )
101124 } catch {
102125 return undefined
103126 }
@@ -115,7 +138,7 @@ export function createGitHubIssueProvider(config: GitHubProviderConfig): IssuePr
115138
116139 const output = await gh ( args )
117140 const raw = JSON . parse ( output ) as Record < string , unknown >
118- return mapIssue ( raw )
141+ return mapIssue ( raw , 'issue' )
119142 } ,
120143
121144 async update (
0 commit comments