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
+25095 -9765
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": {
"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',