Giter Site home page Giter Site logo

go-gitlint's Introduction

Release Build Status codecov Go Report Card codebeat badge GolangCI 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.

Lint your commit msg when committing

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.

Integrate to your CI

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.13.x
  • Ruby 2.x (for pdd)
  • pdd (a ruby gem - gem install pdd)
  • golangci-lint v1.18.0 in your $PATH (curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.18.0)
  • weasel in your $PATH (go get github.com/comcast/weasel)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.