- sort PRs from API based on updated (merged is not an option)

- FIX https://github.com/mikepenz/release-changelog-builder-action/issues/1176
- honor authorDate and commitDate seperatly when detecting the PR date range to consider
This commit is contained in:
Mike Penz
2023-07-28 07:44:27 +00:00
committed by GitHub
parent e0c6294ad2
commit b1ec88d831
4 changed files with 26 additions and 20 deletions
+10 -6
View File
@@ -28,7 +28,9 @@ export interface CommitInfo {
summary: string
message: string
author: string
date: moment.Moment
authorDate: moment.Moment
committer: string
commitDate: moment.Moment
}
export class Commits {
@@ -90,8 +92,10 @@ export class Commits {
sha: commit.sha || '',
summary: commit.commit.message.split('\n')[0],
message: commit.commit.message,
date: moment(commit.commit.committer?.date),
author: commit.commit.author?.name || '',
authorDate: moment(commit.commit.author?.date),
committer: commit.commit.committer?.name || '',
commitDate: moment(commit.commit.committer?.date),
prNumber: undefined
}))
}
@@ -110,9 +114,9 @@ export class Commits {
}
commitsResult.sort((a, b) => {
if (a.date.isBefore(b.date)) {
if (a.commitDate.isBefore(b.commitDate)) {
return -1
} else if (b.date.isBefore(a.date)) {
} else if (b.commitDate.isBefore(a.commitDate)) {
return 1
}
return 0
@@ -160,8 +164,8 @@ export class Commits {
title: commit.summary,
htmlURL: '',
baseBranch: '',
createdAt: commit.date,
mergedAt: commit.date,
createdAt: commit.commitDate,
mergedAt: commit.commitDate,
mergeCommitSha: commit.sha,
author: commit.author || '',
repoName: '',
+3 -3
View File
@@ -103,7 +103,7 @@ export class PullRequests {
owner,
repo,
state: 'closed',
sort: 'merged',
sort: 'updated',
per_page: `${Math.min(100, maxPullRequests)}`,
direction: 'desc'
})
@@ -195,8 +195,8 @@ export class PullRequests {
const firstCommit = commits[0]
const lastCommit = commits[commits.length - 1]
let fromDate = firstCommit.date
const toDate = lastCommit.date
let fromDate = moment.min(lastCommit.authorDate, lastCommit.commitDate) // get the lower date (e.g. if commits are modified)
const toDate = moment.max(lastCommit.authorDate, lastCommit.commitDate) // ensure we get the higher date (e.g. in case of rebases)
const maxDays = configuration.max_back_track_time_days
const maxFromDate = toDate.clone().subtract(maxDays, 'days')