Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit 4ebd337

Browse files
committed
Use GraphQL cursors
1 parent f11e78f commit 4ebd337

3 files changed

Lines changed: 54 additions & 18 deletions

File tree

packages/core/src/query/graphql.ts

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,42 @@ export default async function graphql(options: CheckOptions): Promise<ReleaseDes
2222
}
2323
})
2424

25-
const { repository } = await octokit.graphql<GraphQlQueryResponseData>(theQuery, {
26-
repo: options.repo,
27-
owner: options.owner
28-
})
25+
async function fetch(cursor: string|undefined = undefined) {
26+
const { repository } = await octokit.graphql<GraphQlQueryResponseData>(theQuery, {
27+
repo: options.repo,
28+
owner: options.owner,
29+
cursor
30+
})
31+
return repository
32+
}
33+
34+
let cursor: string|undefined = undefined
35+
const found = false
36+
while (! found) {
37+
const repository: any = await fetch(cursor)
38+
const entries: any[] = options.fetchTags ? repository.refs.nodes : repository.releases.nodes
39+
40+
if (entries.length == 0) {
41+
return undefined
42+
}
2943

30-
// Retrieve newer version name
31-
const newer = options.fetchTags ? repository.refs.nodes[0] : repository.releases.nodes[0]
44+
// no drafts please
45+
if (! options.fetchTags) {
46+
if (entries[0].isDraft && repository.releases.pageInfo.hasNextPage) {
47+
cursor = repository.releases.pageInfo.endCursor
48+
continue
49+
}
50+
}
3251

33-
// Compare versions
34-
if (gt((options.fetchTags ? newer.name : newer.tag.name), options.currentVersion)) {
35-
return newer
36-
} else {
37-
return undefined
52+
// Retrieve newer version name
53+
const newer = entries[0]
54+
const fetchedVersion = options.fetchTags ? newer.name : newer.tagName
55+
if (gt(fetchedVersion, options.currentVersion)) {
56+
return newer
57+
} else {
58+
return undefined
59+
}
3860
}
61+
62+
return undefined
3963
}

packages/core/src/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="node/http" />
22

3-
import { IncomingMessage } from "http"
3+
import { IncomingMessage } from 'node:http'
44

55
export interface CheckOptions {
66
/**
@@ -73,6 +73,11 @@ export interface ReleaseDescriptor {
7373
*/
7474
isPrerelease: boolean
7575

76+
/**
77+
* Whether this release is a draft.
78+
*/
79+
isDraft: boolean
80+
7681
/**
7782
* A datetime string indicating the time this release was published.
7883
*/

packages/core/src/util/graphql.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
export const releases = `
2-
{
2+
query($repo: String!, $owner: String!, $cursor: String = null) {
33
repository(name: $repo, owner: $owner) {
4-
releases(last: 1, { field: CREATED_AT, direction: ASC }) {
4+
releases(
5+
after: $cursor,
6+
first: 1,
7+
orderBy: { field: CREATED_AT, direction: DESC }
8+
) {
9+
pageInfo {
10+
hasNextPage
11+
endCursor
12+
}
513
nodes {
614
name
7-
tag {
8-
name
9-
}
15+
tagName
1016
isPrerelease
17+
isDraft
1118
publishedAt
1219
url
1320
}
@@ -17,7 +24,7 @@ export const releases = `
1724
`
1825

1926
export const tags = `
20-
{
27+
query($repo: String!, $owner: String!) {
2128
repository(name: $repo, owner: $owner) {
2229
refs(
2330
last: 1

0 commit comments

Comments
 (0)