From d326435fe7f874db6e016edadb17340fef5c04f7 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 19 Sep 2018 14:31:25 +0300 Subject: [PATCH] Split pull request query into chunks Otherwise github api chokes when asking about too many pull requests at once --- scripts/changelog.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/changelog.js b/scripts/changelog.js index 01b8aefe..5e1d8b41 100644 --- a/scripts/changelog.js +++ b/scripts/changelog.js @@ -340,13 +340,25 @@ class RepositoryFetcher { return data.repository.milestones.nodes.find(({title}) => title === targetVersion); } + async fetchChunkedPullRequests(numbers) { + const chunks = _.chunk(numbers, 100); + let result = {}; + + for (const chunk of chunks) { + const data = await this.fetchPullRequests(chunk); + result = _.merge(result, data); + } + + return result; + } + // Given a list of PR numbers, retrieve information for all those PRs. They // are returned as a hash whose keys are `PR`. // This is a bit wonky (generating a dynamic GraphQL query) but the GitHub API // does not have a way to retrieve multiple PRs given a list of IDs. async fetchPullRequests(numbers) { if (numbers.length === 0) { - return []; + return {}; } const prQuery = `query fetchPullRequests($repositoryName: String!) { @@ -386,7 +398,7 @@ class RepositoryFetcher { const taggedCommit = await this.fetchTaggedCommit(tag); const commits = await this.fetchCommitsSince(taggedCommit); const pullRequestIds = pullRequestNumbersInCommits(commits); - const pullRequests = await this.fetchPullRequests(pullRequestIds); + const pullRequests = await this.fetchChunkedPullRequests(pullRequestIds); return combine(commits, pullRequests); } }