From 0ff9bae715bcbd397a2490e09759591a3520f971 Mon Sep 17 00:00:00 2001 From: Julian Poyourow Date: Tue, 26 Oct 2021 14:26:39 -0700 Subject: [PATCH] fix: Single commit validation does not factor in merge commits [#108] --- src/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index cc821fd47..0c5b2df76 100644 --- a/src/index.js +++ b/src/index.js @@ -58,9 +58,19 @@ 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.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, { + await validatePrTitle(nonMergeCommits[0].commit.message, { types, scopes, requireScope,