@@ -8,6 +8,112 @@ const { execFileSync } = require('child_process')
88
99const { fetchFromGithub, replacePrivateImage } = require ( './github-source' )
1010
11+ function makeRepositoryQuery ( name ) {
12+ return gql `
13+ {
14+ repository(owner: "Xposed-Modules-Repo", name: "${ name } ") {
15+ name
16+ description
17+ url
18+ homepageUrl
19+ collaborators(affiliation: DIRECT, first: 100) {
20+ edges {
21+ node {
22+ login
23+ name
24+ }
25+ }
26+ }
27+ readme: object(expression: "HEAD:README.md") {
28+ ... on Blob {
29+ text
30+ }
31+ }
32+ summary: object(expression: "HEAD:SUMMARY") {
33+ ... on Blob {
34+ text
35+ }
36+ }
37+ scope: object(expression: "HEAD:SCOPE") {
38+ ... on Blob {
39+ text
40+ }
41+ }
42+ sourceUrl: object(expression: "HEAD:SOURCE_URL") {
43+ ... on Blob {
44+ text
45+ }
46+ }
47+ hide: object(expression: "HEAD:HIDE") {
48+ ... on Blob {
49+ text
50+ }
51+ }
52+ additionalAuthors: object(expression: "HEAD:ADDITIONAL_AUTHORS") {
53+ ... on Blob {
54+ text
55+ }
56+ }
57+ latestRelease {
58+ name
59+ url
60+ isDraft
61+ description
62+ descriptionHTML
63+ createdAt
64+ publishedAt
65+ updatedAt
66+ tagName
67+ isPrerelease
68+ releaseAssets(first: 50) {
69+ edges {
70+ node {
71+ name
72+ contentType
73+ downloadUrl
74+ downloadCount
75+ size
76+ }
77+ }
78+ }
79+ }
80+ releases(first: 20) {
81+ edges {
82+ node {
83+ name
84+ url
85+ isDraft
86+ description
87+ descriptionHTML
88+ createdAt
89+ publishedAt
90+ updatedAt
91+ tagName
92+ isPrerelease
93+ isLatest
94+ releaseAssets(first: 50) {
95+ edges {
96+ node {
97+ name
98+ contentType
99+ downloadUrl
100+ downloadCount
101+ size
102+ }
103+ }
104+ }
105+ }
106+ }
107+ }
108+ updatedAt
109+ createdAt
110+ stargazerCount
111+ }
112+ }
113+ `
114+ }
115+
116+
11117const PAGINATION = 10
12118function makeRepositoriesQuery ( cursor ) {
13119 const arg = cursor ? `, after: "${ cursor } "` : ''
@@ -292,7 +398,7 @@ exports.sourceNodes = async (
292398 let cursor = null
293399 let page = 1
294400 let total
295- const mergedResult = {
401+ let mergedResult = {
296402 data : {
297403 organization : {
298404 repositories : {
@@ -301,23 +407,43 @@ exports.sourceNodes = async (
301407 }
302408 }
303409 }
304- while ( true ) {
305- console . log ( `Querying GitHub API, page ${ page } , total ${ Math . ceil ( total / PAGINATION ) || 'unknown' } , cursor: ${ cursor } ` )
306- const result = await fetchFromGithub ( makeRepositoriesQuery ( cursor ) )
410+ const repo_name = process . env . REPO ? process . env . REPO . split ( '/' ) [ 1 ] : null
411+ if ( repo_name && fs . existsSync ( './cached_graphql.json' ) ) {
412+ const data = fs . readFileSync ( './cached_graphql.json' )
413+ mergedResult = JSON . parse ( data )
414+ mergedResult . data . organization . repositories . edges . forEach ( ( value , index , array ) => {
415+ if ( value . node . name === repo_name ) {
416+ array . splice ( index , 1 )
417+ }
418+ } )
419+ console . log ( `Fetching ${ repo_name } from GitHub API` )
420+ const result = await fetchFromGithub ( makeRepositoryQuery ( repo_name ) )
307421 if ( result . errors || ! result . data ) {
308422 const errMsg = result . errors || 'result.data is null'
309423 console . error ( errMsg )
310424 throw errMsg
311425 }
312- mergedResult . data . organization . repositories . edges =
313- mergedResult . data . organization . repositories . edges . concat ( result . data . organization . repositories . edges )
314- if ( ! result . data . organization . repositories . pageInfo . hasNextPage ) {
315- break
426+ mergedResult . data . organization . repositories . edges . unshift ( { 'node' : result . data . repository } )
427+ } else {
428+ while ( true ) {
429+ console . log ( `Querying GitHub API, page ${ page } , total ${ Math . ceil ( total / PAGINATION ) || 'unknown' } , cursor: ${ cursor } ` )
430+ const result = await fetchFromGithub ( makeRepositoriesQuery ( cursor ) )
431+ if ( result . errors || ! result . data ) {
432+ const errMsg = result . errors || 'result.data is null'
433+ console . error ( errMsg )
434+ throw errMsg
435+ }
436+ mergedResult . data . organization . repositories . edges =
437+ mergedResult . data . organization . repositories . edges . concat ( result . data . organization . repositories . edges )
438+ if ( ! result . data . organization . repositories . pageInfo . hasNextPage ) {
439+ break
440+ }
441+ cursor = result . data . organization . repositories . pageInfo . endCursor
442+ total = result . data . organization . repositories . totalCount
443+ page ++
316444 }
317- cursor = result . data . organization . repositories . pageInfo . endCursor
318- total = result . data . organization . repositories . totalCount
319- page ++
320445 }
446+ fs . writeFileSync ( './cached_graphql.json' , JSON . stringify ( mergedResult ) )
321447 generateGatsbyNode ( mergedResult , createNode )
322448}
323449
0 commit comments