8000 Merge branch 'master' into check-token-perms · jedwards1211/github@c229165 · GitHub
[go: up one dir, main page]

Skip to content

Commit c229165

Browse files
authored
Merge branch 'master' into check-token-perms
2 parents e6111bc + dfe47e9 commit c229165

File tree

5 files changed

+445
-13
lines changed

5 files changed

+445
-13
lines changed

lib/success.js

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,44 @@ export default async function success(pluginConfig, context, { Octokit }) {
6767
const releaseInfos = releases.filter((release) => Boolean(release.name));
6868
const shas = commits.map(({ hash }) => hash);
6969

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+
}
77108

78109
const uniqueAssociatedPRs = uniqBy(flatten(associatedPRs), "number");
79110

@@ -252,15 +283,20 @@ export default async function success(pluginConfig, context, { Octokit }) {
252283
* @param {Array<string>} shas
253284
* @returns {string}
254285
*/
255-
export function buildAssociatedPRsQuery(shas) {
286+
function buildAssociatedPRsQuery(shas) {
256287
return `#graphql
257288
query getAssociatedPRs($owner: String!, $repo: String!) {
258289
repository(owner: $owner, name: $repo) {
259290
${shas
260291
.map((sha) => {
261292
return `commit${sha.slice(0, 6)}: object(oid: "${sha}") {
262293
...on Commit {
294+
oid
263295
associatedPullRequests(first: 100) {
296+
pageInfo {
297+
endCursor
298+
hasNextPage
299+
}
264300
nodes {
265301
url
266302
number
@@ -275,3 +311,28 @@ export function buildAssociatedPRsQuery(shas) {
275311
}
276312
`;
277313
}
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+
`;

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"ls-engines": "0.9.3",
5050
"npm-run-all2": "6.2.2",
5151
"prettier": "3.3.3",
52-
"publint": "0.2.9",
52+
"publint": "0.2.10",
5353
"semantic-release": "24.0.0",
5454
"sinon": "18.0.0",
5555
"tempy": "3.1.0"

test/integration.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,12 @@ test("Comment and add labels on PR included in the releases", async (t) => {
463463
data: {
464464
repository: {
465465
commit123: {
466+
oid: "123",
466467
associatedPullRequests: {
468+
pageInfo: {
469+
endCursor: "NI",
470+
hasNextPage: false,
471+
},
467472
nodes: [prs[0]],
468473
},
469474
},
@@ -689,7 +694,12 @@ test("Verify, release and notify success", async (t) => {
689694
data: {
690695
repository: {
691696
commit123: {
697+
oid: "123",
692698
associatedPullRequests: {
699+
pageInfo: {
700+
endCursor: "NI",
701+
hasNextPage: false,
702+
},
693703
nodes: [prs[0]],
694704
},
695705
},
@@ -846,7 +856,12 @@ test("Verify, update release and notify success", async (t) => {
846856
data: {
847857
repository: {
848858
commit123: {
859+
oid: "123",
849860
associatedPullRequests: {
861+
pageInfo: {
862+
endCursor: "NI",
863+
hasNextPage: false,
864+
},
850865
nodes: [prs[0]],
851866
},
852867
},

0 commit comments

Comments
 (0)
0