Skip to content

Commit

Permalink
fix: Consider merge commits for single commit validation (#127)
Browse files Browse the repository at this point in the history
* 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 <jan@amann.me>
  • Loading branch information
julianpoy and amannn committed Oct 26, 2021
1 parent 25e3275 commit 1b347f7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1b347f7

Please sign in to comment.