diff --git a/CHANGELOG.md b/CHANGELOG.md index eafdc72a3..d366de99b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### [3.4.5](https://github.com/amannn/action-semantic-pull-request/compare/v3.4.4...v3.4.5) (2021-10-28) + + +### Bug Fixes + +* Consider merge commits for single commit validation ([#131](https://github.com/amannn/action-semantic-pull-request/issues/131)) ([5265383](https://github.com/amannn/action-semantic-pull-request/commit/526538350f2e4eaaac841e586a197de6b019af1f)), closes [#108](https://github.com/amannn/action-semantic-pull-request/issues/108) + ### [3.4.4](https://github.com/amannn/action-semantic-pull-request/compare/v3.4.3...v3.4.4) (2021-10-26) diff --git a/dist/index.js b/dist/index.js index 5ed2f0263..5ff5dc42e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -33338,16 +33338,37 @@ module.exports = async function run() { }); if (validateSingleCommit) { - const {data: commits} = await client.pulls.listCommits({ - owner, - repo, - pull_number: contextPullRequest.number, - per_page: 2 - }); + const commits = []; + let nonMergeCommits = []; + + for await (const response of client.paginate.iterator( + client.pulls.listCommits, + { + owner, + repo, + pull_number: contextPullRequest.number + } + )) { + commits.push(...response.data); + + // GitHub does not count merge commits when deciding whether to use + // the PR title or a commit message for the squash commit message. + nonMergeCommits = commits.filter( + (commit) => !commit.commit.message.startsWith('Merge branch') + ); + + // We only need two non-merge commits to know that the PR + // title won't be used. + if (nonMergeCommits.length >= 2) break; + } - if (commits.length === 1) { + // If there is only one (non merge) commit present, GitHub will use + // that commit rather than the PR title for the title of a squash + // commit. To make sure a semantic title is used for the squash + // commit, we need to validate the commit title. + if (nonMergeCommits.length === 1) { try { - await validatePrTitle(commits[0].commit.message, { + await validatePrTitle(nonMergeCommits[0].commit.message, { types, scopes, requireScope,