Skip to content

Commit 144958e

Browse files
committed
Optimize fetching data to run in paralel
1 parent 670bedf commit 144958e

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

scripts/utils.js

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -193,47 +193,45 @@ async function hasLabel(name, owner, repo, issueNumber, github, core) {
193193
* Fetches issues assigned to an assignee in given repositories.
194194
*/
195195
async function getIssues(assignee, state, owner, repos, github, core) {
196-
const allIssues = [];
197-
198-
for (const repo of repos) {
199-
try {
200-
const response = await github.rest.issues.listForRepo({
196+
const promises = repos.map(repo =>
197+
github.rest.issues
198+
.listForRepo({
201199
owner,
202200
repo,
203201
assignee,
204202
state,
205-
});
206-
const issues = response.data.filter(issue => !issue.pull_request);
207-
allIssues.push(...issues);
208-
} catch (error) {
209-
core.warning(`Failed to fetch issues from ${repo}: ${error.message}`);
210-
}
211-
}
203+
})
204+
.then(response => response.data.filter(issue => !issue.pull_request))
205+
.catch(error => {
206+
core.warning(`Failed to fetch issues from ${repo}: ${error.message}`);
207+
return [];
208+
}),
209+
);
212210

213-
return allIssues;
211+
const results = await Promise.all(promises);
212+
return results.flat();
214213
}
215214

216215
/**
217216
* Fetches pull requests by an author in given repositories.
218217
*/
219218
async function getPullRequests(author, state, owner, repos, github, core) {
220-
const allPRs = [];
221-
222-
for (const repo of repos) {
223-
try {
224-
const response = await github.rest.pulls.list({
219+
const promises = repos.map(repo =>
220+
github.rest.pulls
221+
.list({
225222
owner,
226223
repo,
227224
state,
228-
});
229-
const prs = response.data.filter(pr => pr.user.login === author);
230-
allPRs.push(...prs);
231-
} catch (error) {
232-
core.warning(`Failed to fetch pull requests from ${repo}: ${error.message}`);
233-
}
234-
}
225+
})
226+
.then(response => response.data.filter(pr => pr.user.login === author))
227+
.catch(error => {
228+
core.warning(`Failed to fetch pull requests from ${repo}: ${error.message}`);
229+
return [];
230+
}),
231+
);
235232

236-
return allPRs;
233+
const results = await Promise.all(promises);
234+
return results.flat();
237235
}
238236

239237
module.exports = {

0 commit comments

Comments
 (0)