From f1216e9607ae4b476a6584a899c39bbb4f62da6d Mon Sep 17 00:00:00 2001 From: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com> Date: Sat, 5 Feb 2022 01:51:28 +0900 Subject: [PATCH] feat: Check if the PR title matches the commit title when single commits are validated to avoid surprises (#158) --- src/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/index.js b/src/index.js index f87d4f35d..0686bda28 100644 --- a/src/index.js +++ b/src/index.js @@ -97,6 +97,14 @@ module.exports = async function run() { `Pull request has only one commit and it's not semantic; this may lead to a non-semantic commit in the base branch (see https://github.community/t/how-to-change-the-default-squash-merge-commit-message/1155). Amend the commit message to match the pull request title, or add another commit.` ); } + + const commitTitle = + nonMergeCommits[0].commit.message.split('\n')[0]; + if (commitTitle !== pullRequest.title) { + throw new Error( + `The pull request has only one (non-merge) commit and in this case Github will use it as the default commit message when merging. The pull request title doesn't match the commit though ("${pullRequest.title}" vs. "${commitTitle}"). Please update the pull request title accordingly to avoid surprises.` + ); + } } } } catch (error) {