@@ -7,9 +7,12 @@ import {
77 DEFAULT_BRANCH ,
88 PACKAGE_VERSION_TO_FOLLOW ,
99 AWAITING_RELEASE_LABEL ,
10+ IS_NIGHTLY_RELEASE ,
11+ IS_STABLE_RELEASE ,
1012} from "./constants" ;
1113import { gql , graphqlWithAuth , octokit } from "./octokit" ;
1214import type { MinimalTag } from "./utils" ;
15+ import { isNightly , isStable } from "./utils" ;
1316import { cleanupTagName } from "./utils" ;
1417import { checkIfStringStartsWith } from "./utils" ;
1518
@@ -140,34 +143,32 @@ function getPreviousTagFromCurrentTag(
140143
141144 return { tag : tagName , date, isPrerelease } ;
142145 } )
143- . filter ( ( v : any ) : v is MinimalTag => typeof v !== "undefined" ) ;
146+ . filter ( ( v : any ) : v is MinimalTag => typeof v !== "undefined" )
147+ . filter ( ( tag ) => {
148+ if ( IS_STABLE_RELEASE ) return isStable ( tag . tag ) ;
149+ let isNightlyTag = isNightly ( tag . tag ) ;
150+ if ( IS_NIGHTLY_RELEASE ) return isNightlyTag ;
151+ return ! isNightlyTag ;
152+ } )
153+ . sort ( ( a , b ) => {
154+ if ( IS_NIGHTLY_RELEASE ) {
155+ return b . date . getTime ( ) - a . date . getTime ( ) ;
156+ }
157+
158+ return semver . rcompare ( a . tag , b . tag ) ;
159+ } ) ;
144160
145161 let currentTagIndex = validTags . findIndex ( ( tag ) => tag . tag === currentTag ) ;
146162 let currentTagInfo : MinimalTag | undefined = validTags . at ( currentTagIndex ) ;
147163 let previousTagInfo : MinimalTag | undefined ;
148164
149165 if ( ! currentTagInfo ) {
150- throw new Error ( `Could not find last tag ${ currentTag } ` ) ;
151- }
152-
153- // if the currentTag was a stable tag, then we want to find the previous stable tag
154- if ( ! currentTagInfo . isPrerelease ) {
155- validTags = validTags
156- . filter ( ( tag ) => ! tag . isPrerelease )
157- . sort ( ( a , b ) => semver . rcompare ( a . tag , b . tag ) ) ;
158-
159- currentTagIndex = validTags . findIndex ( ( tag ) => tag . tag === currentTag ) ;
160- currentTagInfo = validTags . at ( currentTagIndex ) ;
161- if ( ! currentTagInfo ) {
162- throw new Error ( `Could not find last stable tag ${ currentTag } ` ) ;
163- }
166+ throw new Error ( `Could not find tag ${ currentTag } ` ) ;
164167 }
165168
166169 previousTagInfo = validTags . at ( currentTagIndex + 1 ) ;
167170 if ( ! previousTagInfo ) {
168- throw new Error (
169- `Could not find previous prerelease tag from ${ currentTag } `
170- ) ;
171+ throw new Error ( `Could not find previous tag from ${ currentTag } ` ) ;
171172 }
172173
173174 return {
@@ -232,21 +233,35 @@ interface GitHubGraphqlTag {
232233interface GitHubGraphqlTagResponse {
233234 repository : {
234235 refs : {
236+ pageInfo : {
237+ hasNextPage : boolean ;
238+ endCursor : string ;
239+ } ;
235240 nodes : Array < GitHubGraphqlTag > ;
236241 } ;
237242 } ;
238243}
239244
240- async function getTags ( owner : string , repo : string ) {
245+ async function getTags (
246+ owner : string ,
247+ repo : string ,
248+ endCursor ?: string ,
249+ nodes : Array < GitHubGraphqlTag > = [ ]
250+ ) : Promise < GitHubGraphqlTag [ ] > {
241251 let response : GitHubGraphqlTagResponse = await graphqlWithAuth (
242252 gql `
243- query GET_TAGS($owner: String!, $repo: String!) {
253+ query GET_TAGS($owner: String!, $repo: String!, $endCursor: String ) {
244254 repository(owner: $owner, name: $repo) {
245255 refs(
246256 refPrefix: "refs/tags/"
247257 first: 100
248258 orderBy: { field: TAG_COMMIT_DATE, direction: DESC }
259+ after: $endCursor
249260 ) {
261+ pageInfo {
262+ hasNextPage
263+ endCursor
264+ }
250265 nodes {
251266 name
252267 target {
@@ -267,15 +282,26 @@ async function getTags(owner: string, repo: string) {
267282 }
268283 }
269284 ` ,
270- { owner, repo }
285+ { owner, repo, endCursor }
271286 ) ;
272287
273- return response . repository . refs . nodes . filter ( ( node ) => {
288+ let filtered = response . repository . refs . nodes . filter ( ( node ) => {
274289 return (
275290 node . name . startsWith ( PACKAGE_VERSION_TO_FOLLOW ) ||
276291 node . name . startsWith ( "v0.0.0-nightly-" )
277292 ) ;
278293 } ) ;
294+
295+ if ( response . repository . refs . pageInfo . hasNextPage ) {
296+ console . log ( "has next page" , response . repository . refs . pageInfo . endCursor ) ;
297+
298+ return getTags ( owner , repo , response . repository . refs . pageInfo . endCursor , [
299+ ...nodes ,
300+ ...filtered ,
301+ ] ) ;
302+ }
303+
304+ return [ ...nodes , ...filtered ] ;
279305}
280306
281307export async function getIssuesClosedByPullRequests (
0 commit comments