Skip to content

Enforce good commit messages using Danger

Yorick Peterse requested to merge enforce-good-commit-messages into master

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:

  1. Subject lines must consist out of at least 3 words, mostly to guard against messages such as "fixed typo"
  2. The subject line must contain at most 50 characters
  3. The subject line must start with a capital letter
  4. The subject line must not end with a period
  5. The second line must be empty if a commit body is provided
  6. The lines of the commit body must be at most 72 characters long
  7. If a commit changes more than 20 lines, a commit body is required
  8. 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
  9. Short references such as !123 and gitlab-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.
  10. Merge requests can contain at most 10 commits

Resources these rules are based on:

  1. https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
  2. https://github.com/erlang/otp/wiki/writing-good-commit-messages
  3. https://chris.beams.io/posts/git-commit/
  4. https://robots.thoughtbot.com/write-good-commit-messages-by-blaming-others
  5. 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

Screenshot_from_2018-09-05_16-05-35

What are the relevant issue numbers?

https://gitlab.com/gitlab-org/gitlab-ce/issues/50003

Does this MR meet the acceptance criteria?

Edited by Yorick Peterse

Merge request reports