Skip to content

Commit 525c1f7

Browse files
authored
Batch fetching associated PR information (#160)
Batch fetching associated PR information
2 parents a1ef7fb + fafb657 commit 525c1f7

File tree

4 files changed

+94
-51
lines changed

4 files changed

+94
-51
lines changed

Diff for: .github/workflows/check-dist.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
id: diff
4747

4848
# If index.js was different than expected, upload the expected version as an artifact
49-
- uses: actions/upload-artifact@v2
49+
- uses: actions/upload-artifact@v4
5050
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
5151
with:
5252
name: dist

Diff for: dist/index.js

+44-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/generate-changelog.ts

+48-25
Original file line numberDiff line numberDiff line change
@@ -125,43 +125,66 @@ function branchFromVersion(version: string, channel: string): string {
125125
)}`
126126
}
127127

128+
function chunkArray(originalArray: string[], chunkSize: number): string[][] {
129+
const arrayChunks: string[][] = []
130+
let currentChunk: string[] = []
131+
for (const item of originalArray) {
132+
currentChunk.push(item)
133+
if (currentChunk.length >= chunkSize) {
134+
arrayChunks.push(currentChunk)
135+
currentChunk = []
136+
}
137+
}
138+
if (currentChunk.length > 0) {
139+
arrayChunks.push(currentChunk)
140+
}
141+
return arrayChunks
142+
}
143+
128144
// Fetches PR body text from a series of commits.
129145
async function fetchPullRequestBodyFromCommits(
130146
commits: string[],
131147
graphqlWithAuth: Function
132148
): Promise<string[]> {
133149
let commitsSubQuery = ''
134-
for (const oid of commits) {
135-
commitsSubQuery += `
136-
commit_${oid}: object(oid: "${oid}") {
137-
... on Commit {
138-
oid
139-
author {
140-
name
141-
}
142-
associatedPullRequests(first: 1) {
143-
nodes {
144-
body
150+
151+
// Split the list of commits into batches of 25,
152+
// then request one batch at a time.
153+
const commitBatches = chunkArray(commits, 25)
154+
const commitsInfo: string[] = []
155+
156+
for (const commitBatch of commitBatches) {
157+
for (const oid of commitBatch) {
158+
commitsSubQuery += `
159+
commit_${oid}: object(oid: "${oid}") {
160+
... on Commit {
161+
oid
162+
author {
163+
name
164+
}
165+
associatedPullRequests(first: 1) {
166+
nodes {
167+
body
168+
}
145169
}
146170
}
147171
}
148-
}
149-
`
150-
}
172+
`
173+
}
151174

152-
const response = await graphqlWithAuth(`
153-
{
154-
repository(owner: "warpdotdev", name: "warp-internal") {
155-
${commitsSubQuery}
175+
const response = await graphqlWithAuth(`
176+
{
177+
repository(owner: "warpdotdev", name: "warp-internal") {
178+
${commitsSubQuery}
179+
}
156180
}
157-
}
158-
`)
181+
`)
159182

160-
const commitsInfo: string[] = []
161-
for (const oid of commits) {
162-
const commitResponse = response.repository[`commit_${oid}`]
163-
if (commitResponse.associatedPullRequests.nodes.length > 0) {
164-
commitsInfo.push(commitResponse.associatedPullRequests.nodes[0].body)
183+
for (const oid of commitBatch) {
184+
const commitResponse = response.repository[`commit_${oid}`]
185+
if (commitResponse.associatedPullRequests.nodes.length > 0) {
186+
commitsInfo.push(commitResponse.associatedPullRequests.nodes[0].body)
187+
}
165188
}
166189
}
167190
return commitsInfo

0 commit comments

Comments
 (0)