Merge pull request #1184 from mikepenz/feature/optimize_break_condition

Optimize PR loading break condition
This commit is contained in:
Mike Penz
2023-07-28 16:00:17 +02:00
committed by GitHub
4 changed files with 25120 additions and 9782 deletions
Generated Vendored
+25097 -9767
View File
File diff suppressed because one or more lines are too long
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": { "pr-collector": {
"name": "pr-collector",
"version": "v1.1.0", "version": "v1.1.0",
"license": "Apache 2.0", "license": "Apache 2.0",
"dependencies": { "dependencies": {
+22 -13
View File
@@ -137,17 +137,14 @@ export class PullRequests {
mergedPRs.push(mapPullRequest(pr, 'merged')) mergedPRs.push(mapPullRequest(pr, 'merged'))
} }
const firstPR = prs[0] if (mergedPRs.length >= maxPullRequests) {
if ( core.warning(`⚠️ Reached 'maxPullRequests' count ${maxPullRequests}`)
firstPR === undefined || } else if (prs.length > 0) {
(firstPR.merged_at && fromDate.isAfter(moment(firstPR.merged_at))) || if (fetchedEnough(prs, fromDate)) {
mergedPRs.length >= maxPullRequests return sortPrs(mergedPRs) // bail out early to not keep iterating on PRs super old
) {
if (mergedPRs.length >= maxPullRequests) {
core.warning(`⚠️ Reached 'maxPullRequests' count ${maxPullRequests}`)
} }
} else {
// bail out early to not keep iterating on PRs super old core.debug(`⚠️ No more PRs retrieved from API. Fetched so far: ${mergedPRs.length}`)
break break
} }
} }
@@ -178,9 +175,7 @@ export class PullRequests {
if (openPrs.length >= maxPullRequests) { if (openPrs.length >= maxPullRequests) {
core.warning(`⚠️ Reached 'maxPullRequests' count ${maxPullRequests}`) core.warning(`⚠️ Reached 'maxPullRequests' count ${maxPullRequests}`)
} }
break // bail out early to not keep iterating forever
// bail out early to not keep iterating on PRs super old
break
} }
} }
@@ -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[] { function sortPrs(pullRequests: PullRequestInfo[]): PullRequestInfo[] {
return sortPullRequests(pullRequests, { return sortPullRequests(pullRequests, {
order: 'ASC', order: 'ASC',