Skip to content

Commit

Permalink
Testing commit batching
Browse files Browse the repository at this point in the history
  • Loading branch information
lucieleblanc committed Nov 12, 2024
1 parent a1ef7fb commit 8015f89
Showing 1 changed file with 45 additions and 25 deletions.
70 changes: 45 additions & 25 deletions src/generate-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,43 +125,63 @@ function branchFromVersion(version: string, channel: string): string {
)}`
}

function chunkArray(originalArray: string[], chunkSize: number): string[][] {
let arrayChunks: string[][] = []
let currentChunk: string[] = []
for (const item in originalArray) {
currentChunk.push(item)
if (currentChunk.length >= chunkSize) {
arrayChunks.push(currentChunk)

Check failure on line 134 in src/generate-changelog.ts

View workflow job for this annotation

GitHub Actions / build

'arrayChunks' is never reassigned. Use 'const' instead
currentChunk = []
}

Check failure on line 136 in src/generate-changelog.ts

View workflow job for this annotation

GitHub Actions / build

For-in loops over arrays are forbidden. Use for-of or array.forEach instead
}
return arrayChunks
}

// Fetches PR body text from a series of commits.
async function fetchPullRequestBodyFromCommits(
commits: string[],
graphqlWithAuth: Function
): Promise<string[]> {
let commitsSubQuery = ''
for (const oid of commits) {
commitsSubQuery += `
commit_${oid}: object(oid: "${oid}") {
... on Commit {
oid
author {
name
}
associatedPullRequests(first: 1) {
nodes {
body

// Split the list of commits into batches of 25,
// then request one batch at a time.
const commitBatches = chunkArray(commits, 25)
const commitsInfo: string[] = []

for (const commitBatch of commitBatches) {
for (const oid of commitBatch) {
commitsSubQuery += `
commit_${oid}: object(oid: "${oid}") {
... on Commit {
oid
author {
name
}
associatedPullRequests(first: 1) {
nodes {
body
}
}
}
}
}
`
}
`
}

const response = await graphqlWithAuth(`
{
repository(owner: "warpdotdev", name: "warp-internal") {
${commitsSubQuery}
const response = await graphqlWithAuth(`
{
repository(owner: "warpdotdev", name: "warp-internal") {
${commitsSubQuery}
}
}
}
`)
`)

const commitsInfo: string[] = []
for (const oid of commits) {
const commitResponse = response.repository[`commit_${oid}`]
if (commitResponse.associatedPullRequests.nodes.length > 0) {
commitsInfo.push(commitResponse.associatedPullRequests.nodes[0].body)
for (const oid of commitBatch) {
const commitResponse = response.repository[`commit_${oid}`]
if (commitResponse.associatedPullRequests.nodes.length > 0) {
commitsInfo.push(commitResponse.associatedPullRequests.nodes[0].body)
}
}
}
return commitsInfo
Expand Down

0 comments on commit 8015f89

Please sign in to comment.