From 1b347f79d6518f5d0190913abf7815286f490f53 Mon Sep 17 00:00:00 2001 From: Julian Poyourow Date: Tue, 26 Oct 2021 01:57:17 -0700 Subject: [PATCH] fix: Consider merge commits for single commit validation (#127) * fix: Single commit validation does not factor in merge commits [#108] Closes #108 With a recent change, GitHub no longer factors in merge commits added by the "update branch" button into whether to use the PR title. If a dev submits a PR with a single commit, then presses the "update branch" button, action-semantic-pull-request will allow the branch to be merged, however GitHub will still use the commit title rather than the PR title. * chore: Lint fix * chore: Add comments to explain logic * chore: Fix typo * Minor rephrasing of comments * Fix lint Co-authored-by: Jan Amann --- src/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index cc821fd47..cf1590a51 100644 --- a/src/index.js +++ b/src/index.js @@ -58,7 +58,17 @@ module.exports = async function run() { per_page: 2 }); - if (commits.length === 1) { + // GitHub does not count merge commits when deciding whether to use + // the PR title or a commit message for the squash commit message. + const nonMergeCommits = commits.filter( + (commit) => !commit.message.startsWith('Merge branch') + ); + + // 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, { types,