11import { Octokit } from '@octokit/core'
22import type { GraphQlQueryResponseData } from '@octokit/graphql' ;
33import { gt } from 'semver'
4- import { CheckOptions , ReleaseDescriptor , TagDescriptor } from '@github-version-checker/api'
4+ import { CheckFunction , CheckOptions , CheckResult } from '@github-version-checker/api'
55import { releases , tags } from '../util/graphql'
66
77/**
@@ -12,7 +12,7 @@ import { releases, tags } from '../util/graphql'
1212 *
1313 * @param options The options for the version check.
1414 */
15- export default async function graphql ( options : CheckOptions ) : Promise < ReleaseDescriptor | TagDescriptor | undefined > {
15+ const graphql : CheckFunction = async function ( options : CheckOptions ) : Promise < CheckResult > {
1616 const theQuery = options . fetchTags ? tags : releases
1717
1818 const octokit = new Octokit ( {
@@ -31,35 +31,44 @@ export default async function graphql(options: CheckOptions): Promise<ReleaseDes
3131 return repository
3232 }
3333
34+ const result : CheckResult = {
35+ src : 'graphql' ,
36+ type : options . fetchTags ? 'tags' : 'releases' ,
37+ update : undefined
38+ }
39+
3440 let cursor : string | undefined = undefined
35- const found = false
41+ let found = false
3642 while ( ! found ) {
3743 const repository : any = await fetch ( cursor )
3844 const entries : any [ ] = options . fetchTags ? repository . refs . nodes : repository . releases . nodes
3945
4046 if ( entries . length == 0 ) {
41- return undefined
47+ return result
4248 }
4349
44- const skip = ( ! options . fetchTags && entries [ 0 ] . isDraft ) || ( options . excludePrereleases && entries [ 0 ] . isPrerelease )
45- if ( skip ) {
50+ const skip = entries [ 0 ] . isDraft || ( options . excludePrereleases && entries [ 0 ] . isPrerelease )
51+ if ( ! options . fetchTags && skip ) {
4652 if ( repository . releases . pageInfo . hasNextPage ) {
4753 cursor = repository . releases . pageInfo . endCursor
4854 continue
4955 } else {
50- return undefined
56+ return result
5157 }
5258 }
5359
5460 // Retrieve newer version name
5561 const newer = entries [ 0 ]
56- const fetchedVersion = options . fetchTags ? newer . name : newer . tagName
62+ const fetchedVersion = options . fetchTags ? newer . name : newer . tag . name
5763 if ( gt ( fetchedVersion , options . currentVersion ) ) {
58- return newer
64+ result . update = newer
65+ found = true
5966 } else {
60- return undefined
67+ return result
6168 }
6269 }
6370
64- return undefined
71+ return result
6572}
73+
74+ export default graphql
0 commit comments