DEV Community

Harish Aravindan
Harish Aravindan

Posted on

GitHub Action for Commit Message Validation

What is it about

Have you been in a situation where commit message does not convey the detail of what the code is intended for?
well we can have a validation for that at the repository itself.

Using GitHub actions we can validate commit messages if they have relevant details like story numbers for which the code is being added and so on.

How it works

have published a GitHub Action that helps in validating https://github.com/marketplace/actions/commit-meessage-check

use this in your workflow as step, with your regex of required validation

here is a sample to check if the message has Jira story id

on: [push]

jobs:
  hello_world_job:
    runs-on: ubuntu-latest
    name: commit-message-validation
    steps:
      - uses: actions/checkout@v3
      - id: foo
        uses: uptownaravi/verify-commit-message-action@v2
        with:
          regex: '(?i)jira-[0-9]{3,}'
Enter fullscreen mode Exit fullscreen mode

commit message success

if not then the job fails with exit code 1

commit check failure

The validation happens on the python file https://github.com/uptownaravi/verify-commit-message-action/blob/main/commitcheck.py

Top comments (0)