ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - antham/gommit: Enforce git message commit consistency
Enforce git message commit consistency. Contribute to antham/gommit development by creating an account on GitHub.
Visit Site

GitHub - antham/gommit: Enforce git message commit consistency

GitHub - antham/gommit: Enforce git message commit consistency

Gommit codecov Go Report Card GitHub tag

Gommit analyze commits messages to ensure they follow defined pattern.

asciicast

Summary

Setup

Download from release page according to your architecture gommit binary : https://github.com/antham/gommit/releases

Define a file .gommit.toml

Create a file .gommit.toml at the root of your project, for instance :

[config]
exclude-merge-commits=true
check-summary-length=true
summary-length=50

[matchers]
all="(?:ref|feat|test|fix|style)\\(.*?\\) : .*?\n(?:\n?(?:\\* |  ).*?\n)*"

[examples]
a_simple_commit="""
[feat|test|ref|fix|style](module) : A commit message
"""
an_extended_commit="""
[feat|test|ref|fix|style](module) : A commit message

* first line
* second line
* and so on...
"""

Config

  • exclude-merge-commits : if set to true, will not check commit message for merge commit
  • check-summary-length : if set to true, check commit summary length, default is 50 characters
  • summary-length : you can override the default value summary length, which is 50 characters, this config is used only if check-summary-length is true

Matchers

You can define as many matchers you want using regexp, naming is up to you, they will all be compared against a commit message till one match. Regexps used support comments, possessive match, positive lookahead, negative lookahead, positive lookbehind, negative lookbehind, back reference, named back referenc and conditionals.

Examples

Provided to help user to understand where is the problem, like matchers you can define as many examples as you want, they all will be displayed to the user if an error occured.

If you defined for instance :

a_simple_commit="""
[feat|test|ref|fix|style](module) : A commit message
"""

this example will be displayed to the user like that :

A simple commit :

[feat|test|ref|fix|style](module) : A commit message

key is used as a title, underscore are replaced with withespaces.

Usage

Ensure your commit messages are consistent

Usage:
  gommit [command]

Available Commands:
  check       Check ensure a message follows defined patterns
  version     App version

Flags:
      --config string    (default ".gommit.toml")
  -h, --help            help for gommit

Use "gommit [command] --help" for more information about a command.

check

Check ensure a message follows defined patterns

Usage:
  gommit check [flags]
  gommit check [command]

Available Commands:
  commit      Check commit message
  message     Check message
  range       Check messages in commit range

Flags:
  -h, --help   help for check

Global Flags:
      --config string    (default ".gommit.toml")

Use "gommit check [command] --help" for more information about a command.


You need to provide two commit references to run matching for instance :

check commit

Check commit message

Usage:
  gommit check commit [id] [&path] [flags]

Flags:
  -h, --help   help for commit

Global Flags:
      --config string    (default ".gommit.toml")

Check one comit from its commit ID, doesn't support short ID currently :

gommit check commit aeb603ba83614fae682337bdce9ee1bad1da6d6e

check message

Check message

Usage:
  gommit check message [message] [flags]

Flags:
  -h, --help   help for message

Global Flags:
      --config string    (default ".gommit.toml")

Check a message, useful for script for instance when you want to use it with git hooks :

gommit check message "Hello"

check range

Check messages in range

Usage:
  gommit check range [revisionfrom] [revisionTo] [&path] [flags]

Flags:
  -h, --help   help for range

Global Flags:
      --config string    (default ".gommit.toml")

Check a commit range, useful if you want to use it with a CI to ensure all commits in branch are following your conventions :

  • with relative references : gommit check range master~2^ master
  • with absolute references : gommit check range dev test
  • with commit ids (doesn't support short ID currently) : gommit check range 7bbb37ade3ff36e362d7e20bf34a1325a15b 09f25db7971c100a8c0cfc2b22ab7f872ff0c18d

Practical usage

If your system isn't described here and you find a way to have gommit working on it, please improve this documentation by doing a PR for the next who would like to do the same.

Git hook

It's possible to use gommit to validate each commit when you are creating them. To do so, you need to use the commit-msg hook, you can replace default script with this one :

#!/bin/sh

gommit check message "$(cat "$1")";

Travis

In travis, all history isn't cloned, default depth is 50 commits, you can change it : https://docs.travis-ci.com/user/customizing-the-build#Git-Clone-Depth.

First, we download the binary from the release page according to the version we want and we add in .travis.yml :

before_install:
  - wget -O /tmp/gommit https://github.com/antham/gommit/releases/download/v2.0.0/gommit_linux_386 && chmod 777 /tmp/gommit

We can add a perl script in our repository to analyze the commit range against master for instance (master reference needs to be part of cloned history):

#!/bin/perl

`git ls-remote origin master` =~ /([a-f0-9]{40})/;

my $refHead = `git rev-parse HEAD`;
my $refTail = $1;

chomp($refHead);
chomp($refTail);

if ($refHead eq $refTail) {
    exit 0;
}

system "gommit check range $refTail $refHead";

if ($? > 0) {
    exit 1;
}

And finally in .travis.yml, make it crashs when an error occured :

script: perl test-branch-commit-messages-in-travis.pl

CircleCI

In CircleCI (2.0), there is an environment variable that describe current branch : CIRCLE_BRANCH (https://circleci.com/docs/2.0/env-vars/#circleci-environment-variable-descriptions).

First, we download the binary from the release page according to the version we want and we add in .circleci/config.yml :

- run:
    name: Get gommit binary
    command: |
      mkdir /home/circleci/bin
      wget -O ~/bin/gommit https://github.com/antham/gommit/releases/download/v2.0.0/gommit_linux_386 && chmod 777 ~/bin/gommit

And we can run gommit against master for instance :

- run:
    name: Run gommit
    command: |
      if [ $CIRCLE_BRANCH != 'master' ]; then ~/bin/gommit check range $(git rev-parse origin/master) $CIRCLE_BRANCH ; fi

Third Part Libraries

Nodejs

  • gommitjs : A Nodejs wrapper for gommit

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory