🌐
GitHub
github.com › conventional-changelog › commitlint
GitHub - conventional-changelog/commitlint: 📓 Lint commit messages
📓 Lint commit messages. Contribute to conventional-changelog/commitlint development by creating an account on GitHub.
Starred by 18.5K users
Forked by 965 users
Languages   TypeScript 92.1% | JavaScript 7.9%
🌐
GitHub
github.com › topics › python-commitlint
python-commitlint · GitHub Topics · GitHub
python git hooks pr pre-commit actions pull-requests commit commit-message conventional commitlint github-actions commit-lint pre-commit-hook conventional-commit semantic-commit python-commitlint
🌐
GitHub
github.com › topics › commitlint
commitlint · GitHub Topics · GitHub
Python module that will lint commit messages according to the conventional commit scheme. ... Add a description, image, and links to the commitlint topic page so that developers can more easily learn about it.
🌐
PyPI
pypi.org › project › commitlint
commitlint
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
GitHub
github.com › jorisroovers › gitlint
GitHub - jorisroovers/gitlint: Linting for your git commit messages · GitHub
Git commit message linter written in python, checks your commit messages for style.
Starred by 957 users
Forked by 113 users
Languages   Python 98.5% | Shell 1.1%
🌐
PyPI
pypi.org › project › gitlint
gitlint · PyPI
Git commit message linter written in python, checks your commit messages for style. See jorisroovers.github.io/gitlint for full documentation.
      » pip install gitlint
    
Published   Mar 10, 2023
Version   0.19.1
🌐
freeCodeCamp
freecodecamp.org › news › how-to-use-commitlint-to-write-good-commit-messages
How to Write Good Commit Messages with Commitlint
November 12, 2021 - This workflow will run every time code is pushed to GitHub and every time a pull request is opened. To test it, let's commit and push our code. git add -A git commit -m "ci(commitlint,workflow): added GitHub action workflow to run commitlint on push and pr" git push origin master
🌐
GitHub
github.com › conventionalcommit › commitlint
GitHub - conventionalcommit/commitlint: commitlint checks if your commit messages meets the conventional commit format · GitHub
February 22, 2026 - echo "fear: do not fear for commit message" | commitlint lint # ❌ type-enum: type 'fear' is not allowed, you can use one of [build chore ci docs feat fix merge perf refactor revert style test]
Starred by 87 users
Forked by 9 users
Languages   Go 91.4% | Shell 8.6%
🌐
Conventional Commits
conventionalcommits.org › en › about
Tooling for Conventional Commits
commitlint: A linter to check that your commit messages meet the Conventional Commits format. gitlint: Git commit message linter written in Python, which can be configured to enforce Conventional Commits format.
Find elsewhere
🌐
Commitlint
commitlint.js.org
commitlint
To get the most out of commitlint you'll want to automate it in your project lifecycle.
🌐
GitHub
github.com › alessandrojcm › commitlint-pre-commit-hook
GitHub - alessandrojcm/commitlint-pre-commit-hook: A pre-commit hook for commitlint · GitHub
A pre-commit hook for commitlint. Contribute to alessandrojcm/commitlint-pre-commit-hook development by creating an account on GitHub.
Starred by 182 users
Forked by 18 users
🌐
Sneawo
blog.sneawo.com › blog › 2024 › 01 › 27 › essential-python-tools-for-writing-quality-code
Essential Python tools for writing quality code - Andrey Zhukov's Tech Blog
January 27, 2024 - repos: - repo: https://github.com/PyCQA/flake8 rev: 7.0.0 hooks: - id: flake8 stages: [commit] - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.8.0 hooks: - id: mypy stages: [commit] - repo: https://github.com/psf/black rev: 24.1.1 hooks: - id: black args: [--line-length=120] stages: [commit] - repo: https://github.com/PyCQA/isort rev: 5.13.2 hooks: - id: isort args: [--line-length=120] stages: [commit] - repo: https://github.com/PyCQA/bandit rev: 1.7.7 hooks: - id: bandit stages: [commit] - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook rev: v9.11.0 hooks: - id: commitlint additional_dependencies: ['@commitlint/config-conventional'] stages: [commit-msg]
🌐
GitHub
github.com › wagoid › commitlint-github-action
GitHub - wagoid/commitlint-github-action: Lints Pull Request commits with commitlint · GitHub
Lints Pull Request commits with commitlint. Contribute to wagoid/commitlint-github-action development by creating an account on GitHub.
Starred by 395 users
Forked by 64 users
Languages   JavaScript 97.5% | Shell 1.6% | Dockerfile 0.9%
🌐
PyPI
pypi.org › project › commit-linter
commit-linter · PyPI
commit-linter is a Python tool that helps you standardize your commit messages to a known commit conventions.
      » pip install commit-linter
    
Published   Aug 17, 2023
Version   1.0.3
🌐
Pydigger
pydigger.com › pypi › commitlint
commitlint
To get started please see our [contribution guide](./CONTRIBUTING.md).\n", "bugtrack_url": null, "license": "GPL-3.0", "summary": "commitlint is is a pre-commit hook designed to lint your commit messages according to the Conventional Commits standard.", "version": "1.3.0", "project_urls": { ...
Top answer
1 of 3
14

Solution

The straight-forward solution is to use the --to and --from arguments of commitlint with the SHA-1 values instead of the branch names or relative references. On the one hand, this reliably solves the problem of unknown revisions or paths in the working tree. On the other hand, only commits in scope of the PR will be checked. As a sidenote: GitHub uses the same references (SHA-1) for the ad-hoc merge that is being checked-out.

We need the base-SHA as well as the head-SHA. In a GitHub action those values are available in the pull-request object of the event in the github-context.

Therefore, you can use the following line which is tested and works as expected:

npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose

Demo

Here is a POC repository on GitHub with 3 test cases (pull-requests).

Complete workflow

name: Run Commitlint on PR

on:
  pull_request:

jobs:

  run-commitlint-on-pr:
    runs-on: ubuntu-latest

    steps:

      - uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Setup Node
        uses: actions/setup-node@v2
        with:
          node-version: 14.x

      - name: Install dependencies
        run: npm install

      - name: Validate all commits from PR
        run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
2 of 3
3

git rev-list is considered because the commit of the pull request (PR) seems invalid. No loop should be required.

This issue hints to checkout the PR branch which seems simpler than fetching the PR commits. From the question, testing on default branch does not seem required.

- uses: actions/checkout@v2
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.base.sha }}

The lint instruction would be:

npx commitlint --from ${{ github.event.pull_request.base.sha }} --verbose

Documentation of pull-request payload does not offer the list of commits right away.

🌐
Socket
socket.dev › pypi › package › commitlint
commitlint - PyPI Package Security Analysis - Socket.dev
We found that commitlint demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project. ... Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies.
🌐
Commitlint
commitlint.js.org › guides › ci-setup.html
Guide: CI Setup | commitlint
name: CI on: [push, pull_request] permissions: contents: read jobs: commitlint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup node uses: actions/setup-node@v4 with: node-version: lts/* cache: npm - name: Install commitlint run: npm install -D @commitlint/cli @commitlint/config-conventional - name: Print versions run: | git --version node --version npm --version npx commitlint --version - name: Validate current commit (last commit) with commitlint if: github.event_name == 'push' run: npx commitlint --last --verbose - name: Validate PR commits with commitlint if: github.event_name == 'pull_request' run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
🌐
DEV Community
dev.to › maafaishal › better-git-commits-with-commitlint-g18
Better Git Commits with `@commitlint` - DEV Community
September 12, 2023 - There are many features of commitlint that I can't mention one by one, as well as installation guide. To know the detail you can directly access https://github.com/conventional-changelog/commitlint.