Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enforce a commit message policy when doing squash merge via GitHub Web UI?

Tags:

git

github

We do have a commit hook to enforce messages that follow config-conventional:

package.json

"husky": {
    "hooks": {
        "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
        "pre-commit": "yarn format:check",
        "pre-push": "yarn run test"
    }
},
"commitlint": {
    "extends": [
        "@commitlint/config-conventional"
    ],
    "rules": {
        "scope-case": [
        0,
        "always",
        "pascal-case"
        ]
    }
},

However, if me merge a PR with the squash strategy (via github web ui) then it is possible that a commit message is being sneaked in as the policy is not being enforced here:

feat: [TICKET-209] add completion tests
Added build instructions to README.md <-- Added via squash
feat: [TICKET-208] improve tests

This part of the GitHub history is the result of the 2nd line being added through a squash and therefore not being checked/rejected.

Is there a solution to reject invalid commit messages which are added via squash on github web ui?

like image 932
Timo Ernst Avatar asked Nov 24 '25 12:11

Timo Ernst


1 Answers

If your priority is making sure no commits enter the main branch without the right format, then "Merge queue + Github Action to check commit msg" might solve this problem: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue (note this feature is in public beta)

like image 193
pachewise Avatar answered Nov 26 '25 09:11

pachewise