@semantic-release/github
Advanced tools
Comparing version 10.1.5 to 10.1.6
@@ -70,10 +70,41 @@ import { isNil, uniqBy, template, flatten, isEmpty } from "lodash-es"; | ||
const { repository } = await octokit.graphql( | ||
buildAssociatedPRsQuery(shas), | ||
{ owner, repo }, | ||
); | ||
const associatedPRs = Object.values(repository).map( | ||
(item) => item.associatedPullRequests.nodes, | ||
); | ||
const associatedPRs = []; | ||
// Split commit shas into chunks of 100 shas | ||
const chunkSize = 100; | ||
const shasChunks = []; | ||
for (let i = 0; i < shas.length; i += chunkSize) { | ||
const chunk = shas.slice(i, i + chunkSize); | ||
shasChunks.push(chunk); | ||
} | ||
for (const chunk of shasChunks) { | ||
const { repository } = await octokit.graphql( | ||
buildAssociatedPRsQuery(chunk), | ||
{ owner, repo }, | ||
); | ||
const responseAssociatedPRs = Object.values(repository).map( | ||
(item) => item.associatedPullRequests, | ||
); | ||
for (const { nodes, pageInfo } of responseAssociatedPRs) { | ||
associatedPRs.push(nodes); | ||
if (pageInfo.hasNextPage) { | ||
let cursor = pageInfo.endCursor; | ||
let hasNextPage = true; | ||
while (hasNextPage) { | ||
const { repository } = await octokit.graphql( | ||
loadSingleCommitAssociatedPRs, | ||
{ owner, repo, sha: response.commit.oid, cursor }, | ||
); | ||
const { associatedPullRequests } = repository.commit; | ||
associatedPRs.push(associatedPullRequests.nodes); | ||
if (associatedPullRequests.pageInfo.hasNextPage) { | ||
cursor = associatedPullRequests.pageInfo.endCursor; | ||
} else { | ||
hasNextPage = false; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
const uniqueAssociatedPRs = uniqBy(flatten(associatedPRs), "number"); | ||
@@ -256,3 +287,3 @@ | ||
*/ | ||
export function buildAssociatedPRsQuery(shas) { | ||
function buildAssociatedPRsQuery(shas) { | ||
return `#graphql | ||
@@ -265,3 +296,8 @@ query getAssociatedPRs($owner: String!, $repo: String!) { | ||
...on Commit { | ||
oid | ||
associatedPullRequests(first: 100) { | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
nodes { | ||
@@ -281,1 +317,26 @@ url | ||
} | ||
/** | ||
* GraphQL Query to fetch additional associatedPR for commits that has more than 100 associatedPRs | ||
*/ | ||
const loadSingleCommitAssociatedPRs = `#graphql | ||
query getCommitAssociatedPRs($owner: String!, $repo: String!, $sha: String!, $cursor: String) { | ||
repository(owner: $owner, name: $repo) { | ||
commit: object(oid: $sha) { | ||
...on Commit { | ||
associatedPullRequests(after: $cursor, first: 100) { | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
nodes { | ||
url | ||
number | ||
body | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; |
{ | ||
"name": "@semantic-release/github", | ||
"description": "semantic-release plugin to publish a GitHub release and comment on released Pull Requests/Issues", | ||
"version": "10.1.5", | ||
"version": "10.1.6", | ||
"type": "module", | ||
@@ -52,3 +52,3 @@ "author": "Pierre Vanduynslager (https://twitter.com/@pvdlg_)", | ||
"prettier": "3.3.3", | ||
"publint": "0.2.9", | ||
"publint": "0.2.10", | ||
"semantic-release": "24.0.0", | ||
@@ -55,0 +55,0 @@ "sinon": "18.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79984
1396