Enforce good commit messages using Danger
What does this MR do?
This adds a bunch of Danger checks to enforce good commit messages, as discussed in https://gitlab.com/gitlab-org/gitlab-ce/issues/50003. Specifically, the following rules are enforced:
- Subject lines must consist out of at least 3 words, mostly to guard against messages such as "fixed typo"
- The subject line must contain at most 50 characters
- The subject line must start with a capital letter
- The subject line must not end with a period
- The second line must be empty if a commit body is provided
- The lines of the commit body must be at most 72 characters long
- If a commit changes more than 20 lines, a commit body is required
- Text emoji such as
:+1
and Unicode emoji such as😃 are not allowed anywhere, as these don't always display properly and add no value - Short references such as
!123
andgitlab-org/gitlab-ce#123
are not allowed in favour of regular URLs. This allows developers to just click the URL from the terminal and go straight to the mentioned resource. - Merge requests can contain at most 10 commits
Resources these rules are based on:
- https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
- https://github.com/erlang/otp/wiki/writing-good-commit-messages
- https://chris.beams.io/posts/git-commit/
- https://robots.thoughtbot.com/write-good-commit-messages-by-blaming-others
- https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#commit-your-changes
When one or more rules are violated, some additional details are included, such as an example of a good commit message.
We are not using https://github.com/jonallured/danger-commit_lint, since the messages it produces are not very helpful, and it only provides a few basic checks.
Screenshot
What are the relevant issue numbers?
https://gitlab.com/gitlab-org/gitlab-ce/issues/50003
Does this MR meet the acceptance criteria?
-
Tests added for this feature/bug -
Conforms to the code review guidelines -
Conforms to the style guides
Edited by Yorick Peterse