@@ -7,9 +7,12 @@ import {
7
7
DEFAULT_BRANCH ,
8
8
PACKAGE_VERSION_TO_FOLLOW ,
9
9
AWAITING_RELEASE_LABEL ,
10
+ IS_NIGHTLY_RELEASE ,
11
+ IS_STABLE_RELEASE ,
10
12
} from "./constants" ;
11
13
import { gql , graphqlWithAuth , octokit } from "./octokit" ;
12
14
import type { MinimalTag } from "./utils" ;
15
+ import { isNightly , isStable } from "./utils" ;
13
16
import { cleanupTagName } from "./utils" ;
14
17
import { checkIfStringStartsWith } from "./utils" ;
15
18
@@ -140,34 +143,32 @@ function getPreviousTagFromCurrentTag(
140
143
141
144
return { tag : tagName , date, isPrerelease } ;
142
145
} )
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
+ } ) ;
144
160
145
161
let currentTagIndex = validTags . findIndex ( ( tag ) => tag . tag === currentTag ) ;
146
162
let currentTagInfo : MinimalTag | undefined = validTags . at ( currentTagIndex ) ;
147
163
let previousTagInfo : MinimalTag | undefined ;
148
164
149
165
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 } ` ) ;
164
167
}
165
168
166
169
previousTagInfo = validTags . at ( currentTagIndex + 1 ) ;
167
170
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 } ` ) ;
171
172
}
172
173
173
174
return {
@@ -232,21 +233,35 @@ interface GitHubGraphqlTag {
232
233
interface GitHubGraphqlTagResponse {
233
234
repository : {
234
235
refs : {
236
+ pageInfo : {
237
+ hasNextPage : boolean ;
238
+ endCursor : string ;
239
+ } ;
235
240
nodes : Array < GitHubGraphqlTag > ;
236
241
} ;
237
242
} ;
238
243
}
239
244
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 [ ] > {
241
251
let response : GitHubGraphqlTagResponse = await graphqlWithAuth (
242
252
gql `
243
- query GET_TAGS($owner: String!, $repo: String!) {
253
+ query GET_TAGS($owner: String!, $repo: String!, $endCursor: String ) {
244
254
repository(owner: $owner, name: $repo) {
245
255
refs(
246
256
refPrefix: "refs/tags/"
247
257
first: 100
248
258
orderBy: { field: TAG_COMMIT_DATE, direction: DESC }
259
+ after: $endCursor
249
260
) {
261
+ pageInfo {
262
+ hasNextPage
263
+ endCursor
264
+ }
250
265
nodes {
251
266
name
252
267
target {
@@ -267,15 +282,26 @@ async function getTags(owner: string, repo: string) {
267
282
}
268
283
}
269
284
` ,
270
- { owner, repo }
285
+ { owner, repo, endCursor }
271
286
) ;
272
287
273
- return response . repository . refs . nodes . filter ( ( node ) => {
288
+ let filtered = response . repository . refs . nodes . filter ( ( node ) => {
274
289
return (
275
290
node . name . startsWith ( PACKAGE_VERSION_TO_FOLLOW ) ||
276
291
node . name . startsWith ( "v0.0.0-nightly-" )
277
292
) ;
278
293
} ) ;
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 ] ;
279
305
}
280
306
281
307
export async function getIssuesClosedByPullRequests (
0 commit comments