@@ -67,13 +67,44 @@ export default async function success(pluginConfig, context, { Octokit }) {
67
67
const releaseInfos = releases . filter ( ( release ) => Boolean ( release . name ) ) ;
68
68
const shas = commits . map ( ( { hash } ) => hash ) ;
69
69
70
- const { repository } = await octokit . graphql (
71
- buildAssociatedPRsQuery ( shas ) ,
72
- { owner, repo } ,
73
- ) ;
74
- const associatedPRs = Object . values ( repository ) . map (
75
- ( item ) => item . associatedPullRequests . nodes ,
76
- ) ;
70
+ const associatedPRs = [ ] ;
71
+
72
+ // Split commit shas into chunks of 100 shas
73
+ const chunkSize = 100 ;
74
+ const shasChunks = [ ] ;
75
+ for ( let i = 0 ; i < shas . length ; i += chunkSize ) {
76
+ const chunk = shas . slice ( i , i + chunkSize ) ;
77
+ shasChunks . push ( chunk ) ;
78
+ }
79
+ for ( const chunk of shasChunks ) {
80
+ const { repository } = await octokit . graphql (
81
+ buildAssociatedPRsQuery ( chunk ) ,
82
+ { owner, repo } ,
83
+ ) ;
84
+ const responseAssociatedPRs = Object . values ( repository ) . map (
85
+ ( item ) => item . associatedPullRequests ,
86
+ ) ;
87
+ for ( const { nodes, pageInfo } of responseAssociatedPRs ) {
88
+ associatedPRs . push ( nodes ) ;
89
+ if ( pageInfo . hasNextPage ) {
90
+ let cursor = pageInfo . endCursor ;
91
+ let hasNextPage = true ;
92
+ while ( hasNextPage ) {
93
+ const { repository } = await octokit . graphql (
94
+ loadSingleCommitAssociatedPRs ,
95
+ { owner, repo, sha : response . commit . oid , cursor } ,
96
+ ) ;
97
+ const { associatedPullRequests } = repository . commit ;
98
+ associatedPRs . push ( associatedPullRequests . nodes ) ;
99
+ if ( associatedPullRequests . pageInfo . hasNextPage ) {
100
+ cursor = associatedPullRequests . pageInfo . endCursor ;
101
+ } else {
102
+ hasNextPage = false ;
103
+ }
104
+ }
105
+ }
106
+ }
107
+ }
77
108
78
109
const uniqueAssociatedPRs = uniqBy ( flatten ( associatedPRs ) , "number" ) ;
79
110
@@ -252,15 +283,20 @@ export default async function success(pluginConfig, context, { Octokit }) {
252
283
* @param {Array<string> } shas
253
284
* @returns {string }
254
285
*/
255
- export function buildAssociatedPRsQuery ( shas ) {
286
+ function buildAssociatedPRsQuery ( shas ) {
256
287
return `#graphql
257
288
query getAssociatedPRs($owner: String!, $repo: String!) {
258
289
repository(owner: $owner, name: $repo) {
259
290
${ shas
260
291
. map ( ( sha ) => {
261
292
return `commit${ sha . slice ( 0 , 6 ) } : object(oid: "${ sha } ") {
262
293
...on Commit {
294
+ oid
263
295
associatedPullRequests(first: 100) {
296
+ pageInfo {
297
+ endCursor
298
+ hasNextPage
299
+ }
264
300
nodes {
265
301
url
266
302
number
@@ -275,3 +311,28 @@ export function buildAssociatedPRsQuery(shas) {
275
311
}
276
312
` ;
277
313
}
314
+
315
+ /**
316
+ * GraphQL Query to fetch additional associatedPR for commits that has more than 100 associatedPRs
317
+ */
318
+ const loadSingleCommitAssociatedPRs = `#graphql
319
+ query getCommitAssociatedPRs($owner: String!, $repo: String!, $sha: String!, $cursor: String) {
320
+ repository(owner: $owner, name: $repo) {
321
+ commit: object(oid: $sha) {
322
+ ...on Commit {
323
+ associatedPullRequests(after: $cursor, first: 100) {
324
+ pageInfo {
325
+ endCursor
326
+ hasNextPage
327
+ }
328
+ nodes {
329
+ url
330
+ number
331
+ body
332
+ }
333
+ }
334
+ }
335
+ }
336
+ }
337
+ }
338
+ ` ;
0 commit comments