Validating merge commit messages

We are looking at options for validating squash & merge commit messages, to ensure they begin with a JIRA ticket ID. Minimally, we will do a regular expression check, and we’re considering a JIRA API query to verify the ticket is valid.

To this point I haven’t found a solution for where to run this check. Initially I planned on a GitHub Action, but I don’t believe there are any events which could intercept the merge. I also looked at using a pre-receive hook, but we have GitHub Enterprise Cloud, not Server, and pre-receive hooks are apparently Enterprise Server only.

Does anyone have suggestions on how we could validate merge commit messages?

1 Like

Create a Git hook that launches a custom script to validate the messages before merging. This is a native Git feature, so it doesn’t rely on third party services and will run anywhere.

If the script exits with an error code, the operation will abort.

Since hooks are part of a repository settings, they are available to anyone who clones and forks the repository too. They are easy to setup and script, and you can basically do whatever you need with them, including executing the checks based on the current branch name, etc.