- 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
Generated Vendored
+12 -10
View File
@@ -26272,13 +26272,15 @@ class Commits {
commitInfo: commits commitInfo: commits
.filter(commit => commit.sha) .filter(commit => commit.sha)
.map(commit => { .map(commit => {
var _a, _b; var _a, _b, _c, _d;
return ({ return ({
sha: commit.sha || '', sha: commit.sha || '',
summary: commit.commit.message.split('\n')[0], summary: commit.commit.message.split('\n')[0],
message: commit.commit.message, message: commit.commit.message,
date: (0, moment_1.default)((_a = commit.commit.committer) === null || _a === void 0 ? void 0 : _a.date), author: ((_a = commit.commit.author) === null || _a === void 0 ? void 0 : _a.name) || '',
author: ((_b = commit.commit.author) === null || _b === void 0 ? void 0 : _b.name) || '', authorDate: (0, moment_1.default)((_b = commit.commit.author) === null || _b === void 0 ? void 0 : _b.date),
committer: ((_c = commit.commit.committer) === null || _c === void 0 ? void 0 : _c.name) || '',
commitDate: (0, moment_1.default)((_d = commit.commit.committer) === null || _d === void 0 ? void 0 : _d.date),
prNumber: undefined prNumber: undefined
}); });
}) })
@@ -26296,10 +26298,10 @@ class Commits {
commitsResult.push(commit); commitsResult.push(commit);
} }
commitsResult.sort((a, b) => { commitsResult.sort((a, b) => {
if (a.date.isBefore(b.date)) { if (a.commitDate.isBefore(b.commitDate)) {
return -1; return -1;
} }
else if (b.date.isBefore(a.date)) { else if (b.commitDate.isBefore(a.commitDate)) {
return 1; return 1;
} }
return 0; return 0;
@@ -26342,8 +26344,8 @@ class Commits {
title: commit.summary, title: commit.summary,
htmlURL: '', htmlURL: '',
baseBranch: '', baseBranch: '',
createdAt: commit.date, createdAt: commit.commitDate,
mergedAt: commit.date, mergedAt: commit.commitDate,
mergeCommitSha: commit.sha, mergeCommitSha: commit.sha,
author: commit.author || '', author: commit.author || '',
repoName: '', repoName: '',
@@ -26780,7 +26782,7 @@ class PullRequests {
owner, owner,
repo, repo,
state: 'closed', state: 'closed',
sort: 'merged', sort: 'updated',
per_page: `${Math.min(100, maxPullRequests)}`, per_page: `${Math.min(100, maxPullRequests)}`,
direction: 'desc' direction: 'desc'
}); });
@@ -26898,8 +26900,8 @@ class PullRequests {
} }
const firstCommit = commits[0]; const firstCommit = commits[0];
const lastCommit = commits[commits.length - 1]; const lastCommit = commits[commits.length - 1];
let fromDate = firstCommit.date; let fromDate = moment_1.default.min(lastCommit.authorDate, lastCommit.commitDate); // get the lower date (e.g. if commits are modified)
const toDate = lastCommit.date; const toDate = moment_1.default.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 maxDays = configuration.max_back_track_time_days;
const maxFromDate = toDate.clone().subtract(maxDays, 'days'); const maxFromDate = toDate.clone().subtract(maxDays, 'days');
if (maxFromDate.isAfter(fromDate)) { if (maxFromDate.isAfter(fromDate)) {
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+10 -6
View File
@@ -28,7 +28,9 @@ export interface CommitInfo {
summary: string summary: string
message: string message: string
author: string author: string
date: moment.Moment authorDate: moment.Moment
committer: string
commitDate: moment.Moment
} }
export class Commits { export class Commits {
@@ -90,8 +92,10 @@ export class Commits {
sha: commit.sha || '', sha: commit.sha || '',
summary: commit.commit.message.split('\n')[0], summary: commit.commit.message.split('\n')[0],
message: commit.commit.message, message: commit.commit.message,
date: moment(commit.commit.committer?.date),
author: commit.commit.author?.name || '', author: commit.commit.author?.name || '',
authorDate: moment(commit.commit.author?.date),
committer: commit.commit.committer?.name || '',
commitDate: moment(commit.commit.committer?.date),
prNumber: undefined prNumber: undefined
})) }))
} }
@@ -110,9 +114,9 @@ export class Commits {
} }
commitsResult.sort((a, b) => { commitsResult.sort((a, b) => {
if (a.date.isBefore(b.date)) { if (a.commitDate.isBefore(b.commitDate)) {
return -1 return -1
} else if (b.date.isBefore(a.date)) { } else if (b.commitDate.isBefore(a.commitDate)) {
return 1 return 1
} }
return 0 return 0
@@ -160,8 +164,8 @@ export class Commits {
title: commit.summary, title: commit.summary,
htmlURL: '', htmlURL: '',
baseBranch: '', baseBranch: '',
createdAt: commit.date, createdAt: commit.commitDate,
mergedAt: commit.date, mergedAt: commit.commitDate,
mergeCommitSha: commit.sha, mergeCommitSha: commit.sha,
author: commit.author || '', author: commit.author || '',
repoName: '', repoName: '',
+3 -3
View File
@@ -103,7 +103,7 @@ export class PullRequests {
owner, owner,
repo, repo,
state: 'closed', state: 'closed',
sort: 'merged', sort: 'updated',
per_page: `${Math.min(100, maxPullRequests)}`, per_page: `${Math.min(100, maxPullRequests)}`,
direction: 'desc' direction: 'desc'
}) })
@@ -195,8 +195,8 @@ export class PullRequests {
const firstCommit = commits[0] const firstCommit = commits[0]
const lastCommit = commits[commits.length - 1] const lastCommit = commits[commits.length - 1]
let fromDate = firstCommit.date let fromDate = moment.min(lastCommit.authorDate, lastCommit.commitDate) // get the lower date (e.g. if commits are modified)
const toDate = lastCommit.date 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 maxDays = configuration.max_back_track_time_days
const maxFromDate = toDate.clone().subtract(maxDays, 'days') const maxFromDate = toDate.clone().subtract(maxDays, 'days')