Giter Site home page Giter Site logo

go-gitlint's Introduction

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:

go-gitlint's People

Contributors

g4s8 avatar jeremy-ebler-vineti avatar llorllale avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-gitlint's Issues

main.go:10-12: The path should be passed in as a command...

The puzzle 4-2f6700f4 from #4 has to be resolved:

// @todo #4 The path should be passed in as a command line
// flag instead of being hard coded. All other configuration
// options should be passed in through CLI as well.

The puzzle was created by @llorllale on 18-Feb-19.

If you have any technical questions, don't ask me, submit new tickets instead. The task will be "done" when the problem is fixed and the text of the puzzle is removed from the source code. Here is more about PDD and about me.

filters.go:37-40: Function issues.Filters() can be...

The puzzle 31-07b6963e from #31 has to be resolved:

// @todo #31 Function issues.Filters() can be removed by providing
// default values for each filter that will effectively render them
// disabled. For example, OfSubjectRegex() can be effectively disabled
// by using ".*" as regex.

The puzzle was created by @llorllale on 03-Mar-19.

If you have any technical questions, don't ask me, submit new tickets instead. The task will be "done" when the problem is fixed and the text of the puzzle is removed from the source code. Here is more about PDD and about me.

update

  • go version 1.14
  • linter version 1.29.0
  • auto-download build dependencies
  • remove golangci-lint from build pipeline because the service has stopped working
  • update README

commits.go:48-50: Figure out how to split the commit's...

The puzzle 4-03485093 from #4 has to be resolved:

// @todo #4 Figure out how to split the commit's message into a subject
// and a body. I believe the separator is the first instance of the
// CRLFCRLF sequence.

The puzzle was created by @llorllale on 18-Feb-19.

If you have any technical questions, don't ask me, submit new tickets instead. The task will be "done" when the problem is fixed and the text of the puzzle is removed from the source code. Here is more about PDD and about me.

main.go:26-29: Global variables are a code smell...

The puzzle 9-05e94b28 from #9 has to be resolved:

// @todo #9 Global variables are a code smell (especially those in filterse.go).
// They promote coupling across different components inside the same package.
// Figure out a way to remove these global variables. Whatever command line
// parser we choose should be able to auto-generate usage.

The puzzle was created by @llorllale on 02-Mar-19.

If you have any technical questions, don't ask me, submit new tickets instead. The task will be "done" when the problem is fixed and the text of the puzzle is removed from the source code. Here is more about PDD and about me.

Not install under git-bash environment

I've tried install go-gitlint in my environment (Windows 10, git-bash) and received this error message:

fbc@hades MINGW64 ~/Downloads
$ ./download-gitlint.sh
llorllale/go-gitlint crit uname_os_check 'MINGW64_NT-10.0' got converted to 'mingw64_nt-10.0' which is not a GOOS value. Please file bug at https://github.com/client9/shlib

commits.go:13-17: Figure out how to disable the golint...

The puzzle 4-dc893088 from #4 has to be resolved:

// @todo #4 Figure out how to disable the golint check that
// forces us to write redundant comments of the form
// 'comment on exported type Commits should be of the form
// "Commits ..." (with optional leading article)' and rewrite
// all comments.

The puzzle was created by @llorllale on 18-Feb-19.

If you have any technical questions, don't ask me, submit new tickets instead. The task will be "done" when the problem is fixed and the text of the puzzle is removed from the source code. Here is more about PDD and about me.

go-gitlint: command not found

报错信息:
.git/hooks/commit-msg: line 12: go-gitlint: command not found

目前已经执行过go get xx,但是还是报错是什么原因呢?commit-msg也是符合的

Enable go modules support in Travis build

As per Travis docs, the project's source is checked out into $GOPATH/src/{repo-source}. The GO111MODULE env variable is not set however.

The default for GO111MODULE is to disable module support if the project's source is in the $GOPATH. We need to enable it explicitly.

check_coverage.sh:22-24: The coverage script is ignoring...

The puzzle 16-e0d2cf8f from #16 has to be resolved:

# @todo #16 The coverage script is ignoring packages that are not tested
# at all (0% coverage). It should be fixed so that all packages are
# tested (except for main).

The puzzle was created by @llorllale on 24-Feb-19.

If you have any technical questions, don't ask me, submit new tickets instead. The task will be "done" when the problem is fixed and the text of the puzzle is removed from the source code. Here is more about PDD and about me.

Can't download with script

When I'm trying to download with download script I'm getting checksum error:

> curl https://raw.githubusercontent.com/llorllale/go-gitlint/master/download-gitlint.sh > download-gitlint.sh
> chmod +x download-gitlint.sh
> ./download-gitlint.sh
llorllale/go-gitlint info checking GitHub for latest tag
llorllale/go-gitlint info found version: 1.0.0 for 1.0.0/Linux/x86_64
llorllale/go-gitlint err hash_sha256_verify unable to find checksum for '/tmp/tmp.h7Ee8qtCrC/go-gitlint_1.0.0_Linux_x86_64.tar.gz' in '/tmp/tmp.h7Ee8qtCrC/go-gitlint_1.0.0_checksums.txt'

Filters

Let's add filters to detect violations on commit subjects and bodies by using regular expressions.

Darwin/arm64 is not supported by default

Device: Apple M1

After trying to execute download-gitlint.sh file

llorllale/go-gitlint crit platform darwin/arm64 is not supported.  Make sure this script is up-to-date and file request at https://github.com/llorllale/go-gitlint/issues/new

.golangci.yml:53-56: Enable this configuration after this...

The puzzle 1-919cdc44 from #1 has to be resolved:

go-gitlint/.golangci.yml

Lines 53 to 56 in 948ed35

# @todo #1 Enable this configuration after this golangci-lint issue is
# fixed: https://github.com/golangci/golangci-lint/issues/397. According
# to the golangci-lint docs, this config is desirable since the CI build
# should not be required to update go.mod.

The puzzle was created by @llorllale on 16-Feb-19.

If you have any technical questions, don't ask me, submit new tickets instead. The task will be "done" when the problem is fixed and the text of the puzzle is removed from the source code. Here is more about PDD and about me.

Ignore user from gitlint

We should be able to ignore users from gitlink, to avoid problems when ARC or even rultor needs make a commit to repository.

Commit message always failed

I integrated go-gitlint in my cactoos fork, I tried to commit a few times with some commit message variants, but always I got

fakehsh: subject does not match regex [^\(#[0-9]+\) [^\s].{13,50}]

I suppose, that maybe regex has the wrong signature. Because of the simplest commit message, like

(yegor256#1141) Code review: fix gitlint errors for merge with rutor

is not passing through regular expression. I tried some previous commits messages, but they are not passing too.

.golangci.yml:3-5: upgrade golangci-lint-version to...

The puzzle 53-2f5f2d13 from #53 has to be resolved:

# @todo #53 upgrade golangci-lint-version to 1.18.x once their docker image is ready
# - see https://github.com/golangci/golangci-lint/issues/682. For now, linting on
# local is against 1.18.x vs their service on 1.17.x.

The puzzle was created by @llorllale on 14-Sep-19.

role: DEV.

If you have any technical questions, don't ask me, submit new tickets instead. The task will be "done" when the problem is fixed and the text of the puzzle is removed from the source code. Here is more about PDD and about me.

commits.go:28-30: These err checks are extremely...

The puzzle 4-faa799fb from #4 has to be resolved:

// @todo #4 These err checks are extremely annoying. Figure out
// how to handle them elegantly and reduce the cyclo complexity
// of this function (currently at 4).

The puzzle was created by @llorllale on 18-Feb-19.

If you have any technical questions, don't ask me, submit new tickets instead. The task will be "done" when the problem is fixed and the text of the puzzle is removed from the source code. Here is more about PDD and about me.

Release build is broken

See this travis log.

We need to tell that goreleaser docker image that go modules are enabled, and we also need to add a hook to perform go mod download

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.