@@ -96,7 +96,7 @@ const program = new Command()
9696program
9797 . command ( 'repo' )
9898 . argument ( '<owner/repo>' , 'Repository in owner/name form' )
99- . description ( 'Run RepoSnapshot query to fetch issues, PRs, and latest release' )
99+ . description ( 'Run RepoSnapshot query to fetch issues, PRs, and latest stable release' )
100100 . action ( async ( slug : string , opts : Record < string , unknown > , cmd : Command ) => {
101101 const spinner = ora ( 'Fetching repo snapshot' ) . start ( ) ;
102102 try {
@@ -113,7 +113,17 @@ program
113113 const { data, rateLimitReset } = await fetchGraphQL < {
114114 repository : {
115115 name : string ;
116- releases : { nodes ?: { name ?: string | null ; tagName : string ; publishedAt : string ; url : string } [ ] } ;
116+ releases : {
117+ nodes ?: {
118+ name ?: string | null ;
119+ tagName : string ;
120+ publishedAt ?: string | null ;
121+ createdAt ?: string | null ;
122+ url : string ;
123+ isDraft : boolean ;
124+ isPrerelease : boolean ;
125+ } [ ] ;
126+ } ;
117127 issues : { totalCount : number } ;
118128 pullRequests : { totalCount : number } ;
119129 } | null ;
@@ -131,17 +141,23 @@ program
131141
132142 const repo = data . repository ;
133143 if ( ! repo ) throw new Error ( 'Repository not found' ) ;
134- const release = repo . releases . nodes ?. [ 0 ] ;
144+ const release = repo . releases . nodes
145+ ?. filter ( ( node ) => ! node . isDraft && ! node . isPrerelease )
146+ . sort ( ( lhs , rhs ) => {
147+ const lhsDate = lhs . publishedAt ?? lhs . createdAt ?? '0001-01-01T00:00:00Z' ;
148+ const rhsDate = rhs . publishedAt ?? rhs . createdAt ?? '0001-01-01T00:00:00Z' ;
149+ return rhsDate . localeCompare ( lhsDate ) ;
150+ } ) [ 0 ] ;
135151 const releaseLine = release
136- ? `${ release . name ?? release . tagName } (${ new Date ( release . publishedAt ) . toLocaleDateString ( ) } )`
152+ ? `${ release . name ?? release . tagName } (${ new Date ( release . publishedAt ?? release . createdAt ?? 0 ) . toLocaleDateString ( ) } )`
137153 : 'none' ;
138154
139155 console . log (
140156 [
141157 chalk . bold ( `${ owner } /${ name } ` ) ,
142158 `Issues: ${ repo . issues . totalCount } ` ,
143159 `PRs: ${ repo . pullRequests . totalCount } ` ,
144- `Latest release: ${ releaseLine } ` ,
160+ `Latest stable release: ${ releaseLine } ` ,
145161 ] . join ( '\n' )
146162 ) ;
147163 const rl = formatRateLimit ( rateLimitReset ) ;
0 commit comments