Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/llorllale/go-gitlint
Go lint your commit messages!
https://github.com/llorllale/go-gitlint
git go golang lint linter
Last synced: 4 months ago
JSON representation
Go lint your commit messages!
- Host: GitHub
- URL: https://github.com/llorllale/go-gitlint
- Owner: llorllale
- License: apache-2.0
- Created: 2019-01-15T03:59:54.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-30T05:24:13.000Z (about 1 year ago)
- Last Synced: 2024-06-18T17:00:37.793Z (8 months ago)
- Topics: git, go, golang, lint, linter
- Language: Go
- Size: 89.8 KB
- Stars: 77
- Watchers: 3
- Forks: 13
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/llorllale/go-gitlint/releases/latest)
[](https://travis-ci.com/llorllale/go-gitlint)
[](https://codecov.io/gh/llorllale/go-gitlint)
[](https://goreportcard.com/report/github.com/llorllale/go-gitlint)
[](https://codebeat.co/projects/github-com-llorllale-go-gitlint-master)
[](https://github.com/goreleaser)
[](http://godoc.org/github.com/llorllale/go-gitlint)
[](http://www.0pdd.com/p?name=llorllale/go-gitlint)
[](https://raw.githubusercontent.com/llorllale/go-gitlint/master/LICENSE)# go-gitlint
Lint your git!## Usage
```
$ ./gitlint --help
usage: gitlint []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](https://github.com/g4s8/gitlint-action).#### With any CI pipeline
Use [`download-gitlint.sh`](https://raw.githubusercontent.com/llorllale/go-gitlint/master/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-gitlintUsage: ./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
- [X] Validate format of commit message subject and body
- [X] Lint commit msgs on varios development platforms (Windows, Linux, Mac)
- [X] Configuration from file with cli args taking precedence
- [X] [`commit-msg`](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) hook to validate my commit's msg
- [X] Performance (because a slow pre-commit hook would render the git workflow unmanageable)
- [X] 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](https://rvm.io/) is highly recommended.The `make dependencies` recipe attempts to download and install the following:
* [pdd](https://github.com/yegor256/pdd)
* [golangci-lint](https://github.com/golangci/golangci-lint) v1.29.0
* [weasel](https://github.com/comcast/weasel)