Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Commitlint on GitHub Pull Request Message & Description

Tags:

github

How do I run commitlint on a GitHub pull request message and description? https://github.com/conventional-changelog/commitlint

enter image description here

We currently run commitlint in our CI. However, this is too late in the process i.e. the invalid commit message is already in the branch.

The only approach I've been able to find is with GitHub apps. Below are the apps I've found/tried. Maybe the only solution is to build our own/custom GitHub app? However, linting a GitHub PR seems like a common request and I get the feeling I'm missing something fundamental here.

This GitHub app looks perfect but doesn't currently work: https://github.com/apps/commitlint

This GitHub app allows commit message/description via custom regex. However, I can't find any information as to whether commitlint can be expressed as a single regex statement. https://github.com/marketplace/commit-message-lint

This GitHub app is available for public repos only -- our repo is private. https://github.com/marketplace/commit-lint/plan/MDIyOk1hcmtldHBsYWNlTGlzdGluZ1BsYW4xMjUz#pricing-and-setup

This GitHub app supports multiple regex expressions. https://github.com/ewolfe/prlint

like image 725
Aydus-Matthew Avatar asked Nov 06 '22 16:11

Aydus-Matthew


1 Answers

If GitHub apps are not working, you can fallback to a webhook approach, which means having a listener which will respond to a JSON payload sent by GitHub on each push.

That listener could:

  • apply a commit linter
  • if said linter fails, can:
    • force-push the same branch on HEAD~1 to effectively cancel (refuse) the push
    • send an email to notify the push just got refused.

At least, a webhook would be run immediately, and not during a CI pipeline.

like image 58
VonC Avatar answered Nov 15 '22 11:11

VonC