[go: up one dir, main page]

Skip to content

llorllale/go-gitlint

Repository files navigation

Release Build Status codecov Go Report Card codebeat badge Powered By: GoReleaser Go Doc PDD status License

go-gitlint

Lint your git!

Usage

$ ./gitlint --help
usage: gitlint [<flags>]

Flags:
  --help                       Show context-sensitive help (also try --help-long and --help-man).
  --path="."                   Path to the git repo (default: ".").
  --subject-regex=".*"         Commit subject line must conform to this regular expression (default: ".*").
  --subject-maxlen=2147483646  Max length for commit subject line (default: math.MaxInt32 - 1).
  --subject-minlen=0           Min length for commit subject line (default: 0).
  --body-regex=".*"            Commit message body must conform to this regular expression (default: ".*").
  --body-maxlen=2147483646     Max length for commit body (default: math.MaxInt32 - 1)
  --since="1970-01-01"         A date in "yyyy-MM-dd" format starting from which commits will be analyzed (default: "1970-01-01").
  --msg-file=""                Only analyze the commit message found in this file (default: "").
  --max-parents=1              Max number of parents a commit can have in order to be analyzed (default: 1). Useful for excluding merge commits.
  --excl-author-names="$a"     Don't lint commits with authors whose names match these comma-separated regular expressions (default: '$a').
  --excl-author-emails="$a"    Don't lint commits with authors whose emails match these comma-separated regular expressions (default: '$a').

Additionally, it will look for configurations in a file .gitlint in the current directory if it exists. This file's format is just the same command line flags but each on a separate line. Flags passed through the command line take precedence.

Integration

With Git

Lint your commit message when committing to your local branch.

Add a commit-msg hook to your Git repo:

  1. Create hook: echo 'gitlint --msg-file=$1' > .git/hooks/commit-msg
  2. Make it executable: chmod +x .git/hooks/commit-msg

Now your commits will be validated after saving and closing the commit message in your text editor.

With GitHub Actions

To integrate it as GitHub action into CI pipeline use gitlint-action.

With any CI pipeline

Use download-gitlint.sh:

  1. curl https://raw.githubusercontent.com/llorllale/go-gitlint/master/download-gitlint.sh > download-gitlint.sh
  2. chmod +x download-gitlint.sh

Usage:

$ ./download-gitlint.sh -h
./download-gitlint.sh: download go binaries for llorllale/go-gitlint

Usage: ./download-gitlint.sh [-b] bindir [-d] [tag]
  -b sets bindir or installation directory, Defaults to ./bin
  -d turns on debug logging
   [tag] is a tag from
   https://github.com/llorllale/go-gitlint/releases
   If tag is missing, then the latest will be used.

 Generated by godownloader
  https://github.com/goreleaser/godownloader

Exit codes

gitlint's exit code will equal the number of issues found with your commit(s).

Motivation

  • Validate format of commit message subject and body
  • Lint commit msgs on varios development platforms (Windows, Linux, Mac)
  • Configuration from file with cli args taking precedence
  • commit-msg hook to validate my commit's msg
  • Performance (because a slow pre-commit hook would render the git workflow unmanageable)
  • My first Go project :)

Contributing

Fork this repo, make sure make checks works, and then open a PR.

Build dependencies

To run make checks you will need Go 1.16.x and Ruby 2.x (for pdd - see below). Ruby Version Manager is highly recommended.

The make dependencies recipe attempts to download and install the following: