Checking in CI
Check commit messages and PR titles, and the GitHub Action.
gitmit check checks the commit messages on your branch, and optionally a pull request title, against the same rules gitmit writes with:
$ gitmit check --suggest
Checking 3 commits since origin/main.
✗ 4f1c2ab Fixed the login bug.
- not in "type(scope): description" form, e.g. "fix(auth): handle expired tokens"
Suggested: fix(auth): reject empty passwords on login
✗ 1 of 3 messages needs changes.
- The rules are your gitmit config (types, scopes, header length, required tickets). If the repository has a commitlint config, its rules are used instead, exactly as your commit-msg hook would apply them.
- Merge commits and git's own
Revert "..."messages are skipped.fixup!andsquash!commits are flagged, so they get squashed before merging. - The exit code is 1 when anything needs changes, so it can fail a CI job.
- Options:
--range <a..b>checks specific commits,--title "<text>"checks a pull request title (--no-commitschecks the title alone),--suggestproposes a fixed message for each problem from that commit's diff, and--jsonprints machine-readable results.
The GitHub Action
Add .github/workflows/gitmit.yml:
name: Commit messages
on:
pull_request:
types: [opened, edited, synchronize, reopened]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: sammy440/gitmit@v0.8.0
Each problem shows up as an annotation on the run and in the job summary, with a suggested fix. Notes:
fetch-depth: 0is needed so the pull request's commits can be read.- Squash merging? The pull request title becomes the commit, so check only the title:
with: { commits: false }. - Better suggestions: suggestions use offline rules unless you pass a key, e.g.
env: { OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} }. Turn them off withsuggest: false. - commitlint presets (
extends: ["@commitlint/config-conventional"]) must be installed, so run your package manager's install step before the check. - Inputs:
commits,title,suggest(alltrueby default),provider, andversion(the gitmit version, defaultlatest).