From 82df9ba71cef731ff38b4856438d2405ca07c99a Mon Sep 17 00:00:00 2001 From: Julian Poyourow Date: Fri, 22 Oct 2021 08:52:24 -0700 Subject: [PATCH 1/6] 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. --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index cc821fd47..866afc3ee 100644 --- a/src/index.js +++ b/src/index.js @@ -58,7 +58,9 @@ module.exports = async function run() { per_page: 2 }); - if (commits.length === 1) { + const nonMergeCommits = commits.filter(commit => !commit.message.startsWith("Merge branch")); + + if (nonMergeCommits.length === 1) { try { await validatePrTitle(commits[0].commit.message, { types, From 195c1cf105a9c5a62843e41c40f0ef0d2d56999f Mon Sep 17 00:00:00 2001 From: Julian Poyourow Date: Mon, 25 Oct 2021 09:51:29 -0700 Subject: [PATCH 2/6] chore: Lint fix --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 866afc3ee..6f5938648 100644 --- a/src/index.js +++ b/src/index.js @@ -58,7 +58,7 @@ module.exports = async function run() { per_page: 2 }); - const nonMergeCommits = commits.filter(commit => !commit.message.startsWith("Merge branch")); + const nonMergeCommits = commits.filter((commit) => !commit.message.startsWith("Merge branch")); if (nonMergeCommits.length === 1) { try { From 62a47fb8cb0de7e1322efe92fafdd474b5920400 Mon Sep 17 00:00:00 2001 From: Julian Poyourow Date: Mon, 25 Oct 2021 09:56:15 -0700 Subject: [PATCH 3/6] chore: Add comments to explain logic --- src/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.js b/src/index.js index 6f5938648..1664088b3 100644 --- a/src/index.js +++ b/src/index.js @@ -58,8 +58,12 @@ module.exports = async function run() { per_page: 2 }); + // GitHub does not count merge commits when deciding whether squash commit title should + // follow PR title vs use a single commit in the PR. const nonMergeCommits = commits.filter((commit) => !commit.message.startsWith("Merge branch")); + // If there is only 1 (non merge) commit present, GitHub will use that commit rather + // than use the PR title. Here we validate that the PR title is semantic. if (nonMergeCommits.length === 1) { try { await validatePrTitle(commits[0].commit.message, { From 4c746ad8dfefb00ab08ad674802c82a7f07d7a8f Mon Sep 17 00:00:00 2001 From: Julian Poyourow Date: Mon, 25 Oct 2021 09:57:36 -0700 Subject: [PATCH 4/6] chore: Fix typo --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 1664088b3..196756a58 100644 --- a/src/index.js +++ b/src/index.js @@ -63,7 +63,7 @@ module.exports = async function run() { const nonMergeCommits = commits.filter((commit) => !commit.message.startsWith("Merge branch")); // If there is only 1 (non merge) commit present, GitHub will use that commit rather - // than use the PR title. Here we validate that the PR title is semantic. + // than use the PR title. Here we validate that the single commit title is semantic. if (nonMergeCommits.length === 1) { try { await validatePrTitle(commits[0].commit.message, { From eca93702be6fbdcfe1264869915a01eb64f1a301 Mon Sep 17 00:00:00 2001 From: Jan Amann Date: Tue, 26 Oct 2021 10:48:51 +0200 Subject: [PATCH 5/6] Minor rephrasing of comments --- src/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 196756a58..2be6c977d 100644 --- a/src/index.js +++ b/src/index.js @@ -58,12 +58,13 @@ module.exports = async function run() { per_page: 2 }); - // GitHub does not count merge commits when deciding whether squash commit title should - // follow PR title vs use a single commit in the PR. + // 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 1 (non merge) commit present, GitHub will use that commit rather - // than use the PR title. Here we validate that the single commit title is semantic. + // 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, { From 38165d47340d5fe552547747fed1320ba894d783 Mon Sep 17 00:00:00 2001 From: Jan Amann Date: Tue, 26 Oct 2021 10:55:49 +0200 Subject: [PATCH 6/6] Fix lint --- src/index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 2be6c977d..cf1590a51 100644 --- a/src/index.js +++ b/src/index.js @@ -58,13 +58,16 @@ module.exports = async function run() { per_page: 2 }); - // GitHub does not count merge commits when deciding whether to use + // 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")); + 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 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, {