- optimize break condition, if we collected enough PRs

This commit is contained in:
Mike Penz
2023-07-28 13:35:06 +00:00
committed by GitHub
parent 6f4227e903
commit 79ee621728
4 changed files with 48 additions and 24 deletions
Generated Vendored
+23 -7
View File
@@ -26912,14 +26912,16 @@ class PullRequests {
for (const pr of prs.filter(p => !!p.merged_at)) {
mergedPRs.push(mapPullRequest(pr, 'merged'));
}
const firstPR = prs[0];
if (firstPR === undefined ||
(firstPR.merged_at && fromDate.isAfter((0, moment_1.default)(firstPR.merged_at))) ||
mergedPRs.length >= maxPullRequests) {
if (mergedPRs.length >= maxPullRequests) {
core.warning(`⚠️ Reached 'maxPullRequests' count ${maxPullRequests}`);
}
// bail out early to not keep iterating on PRs super old
else if (prs.length > 0) {
if (fetchedEnough(prs, fromDate)) {
return sortPrs(mergedPRs); // bail out early to not keep iterating on PRs super old
}
}
else {
core.debug(`⚠️ No more PRs retrieved from API. Fetched so far: ${mergedPRs.length}`);
break;
}
}
@@ -26960,8 +26962,7 @@ class PullRequests {
if (openPrs.length >= maxPullRequests) {
core.warning(`⚠️ Reached 'maxPullRequests' count ${maxPullRequests}`);
}
// bail out early to not keep iterating on PRs super old
break;
break; // bail out early to not keep iterating forever
}
}
}
@@ -27114,6 +27115,21 @@ class PullRequests {
}
}
exports.PullRequests = PullRequests;
function fetchedEnough(pullRequests, fromDate) {
for (let i = 0; i < Math.min(pullRequests.length, 3); i++) {
const firstPR = pullRequests[i];
if (!firstPR.merged_at) {
continue; // no merged_at timestamp -> look for the next
}
else if (fromDate.isAfter((0, moment_1.default)(firstPR.merged_at))) {
return true;
}
else {
break; // not enough PRs yet, go further
}
}
return false;
}
function sortPrs(pullRequests) {
return sortPullRequests(pullRequests, {
order: 'ASC',
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
-1
View File
@@ -7116,7 +7116,6 @@
}
},
"pr-collector": {
"name": "pr-collector",
"version": "v1.1.0",
"license": "Apache 2.0",
"dependencies": {
+20 -11
View File
@@ -137,17 +137,14 @@ export class PullRequests {
mergedPRs.push(mapPullRequest(pr, 'merged'))
}
const firstPR = prs[0]
if (
firstPR === undefined ||
(firstPR.merged_at && fromDate.isAfter(moment(firstPR.merged_at))) ||
mergedPRs.length >= maxPullRequests
) {
if (mergedPRs.length >= maxPullRequests) {
core.warning(`⚠️ Reached 'maxPullRequests' count ${maxPullRequests}`)
} else if (prs.length > 0) {
if (fetchedEnough(prs, fromDate)) {
return sortPrs(mergedPRs) // bail out early to not keep iterating on PRs super old
}
// bail out early to not keep iterating on PRs super old
} else {
core.debug(`⚠️ No more PRs retrieved from API. Fetched so far: ${mergedPRs.length}`)
break
}
}
@@ -178,9 +175,7 @@ export class PullRequests {
if (openPrs.length >= maxPullRequests) {
core.warning(`⚠️ Reached 'maxPullRequests' count ${maxPullRequests}`)
}
// bail out early to not keep iterating on PRs super old
break
break // bail out early to not keep iterating forever
}
}
@@ -327,6 +322,20 @@ export class PullRequests {
}
}
function fetchedEnough(pullRequests: PullsListData, fromDate: moment.Moment): boolean {
for (let i = 0; i < Math.min(pullRequests.length, 3); i++) {
const firstPR = pullRequests[i]
if (!firstPR.merged_at) {
continue // no merged_at timestamp -> look for the next
} else if (fromDate.isAfter(moment(firstPR.merged_at))) {
return true
} else {
break // not enough PRs yet, go further
}
}
return false
}
function sortPrs(pullRequests: PullRequestInfo[]): PullRequestInfo[] {
return sortPullRequests(pullRequests, {
order: 'ASC',