GithubHelp home page GithubHelp logo

swellaby / captain-githook Goto Github PK

View Code? Open in Web Editor NEW
30.0 3.0 2.0 279 KB

git hook utility for Go codebases

License: MIT License

Go 99.77% Shell 0.23%
go golang git githook githooks-plugin hooks hook-manager git-hooks

captain-githook's Introduction

captain-githook

Cross-platform, configurable, git hook utility geared for Go codebases.

****** Functional, but still in Beta ******

Linux CI Badge Mac CI Badge Windows CI Badge

Test Results Badge Coverage Badge Sonar Quality Gate Badge

Contents

About

Git hooks are scripts/commands that git can execute on certain events which helps you automate tasks, enforce quality and consistency in your code, and more. captain-githook allows you to utilize any and all git hooks in your repository (commit-msg, pre-commit, pre-push, etc.) via a simple configuration file.

Yes, there are other git hook utilities out there (in fact we love, recommend, and use husky in our JavaScript/TypeScript projects that use npm). However, we made captain-githook because we wanted a git hook utility for our Go codebases that was cross-platform, easily configurable, and that wasn't dependent on another, non-Go framework/runtime.

Installation

We'll be adding binary releases shortly, but for now you'll need to have your Go environment setup and use go get i.e.:

go get -u github.com/swellaby/captain-githook

Note that the latest captain-githook version requires Go 1.12 or higher. If you need to use captain-githook on Go 1.11 and earlier, make sure you use the v0.0.7 tag:

go get -u github.com/swellaby/[email protected]

This will ensure that the captain-githook executable is available on your system for initializing your repositories (creating git hook and config files) as well as for executing your defined hook scripts.

Getting Started

Run the init sub-command within a git repository to create the git hook files and create the captain-githook config file:

captain-githook init

If you'd prefer to use a different name for the config file, you can specify your desired config file name as a flag (--config-filename or --f) on the init command. For example:

captain-githook init --config-filename .captain-githookrc.json

See allowed config file names below for info on what config file names you can use.

Configure

You specify which scripts/commands you want to run for each git hook in the captain-githook configuration file included in your repository.

The captain-githook config is a json formatted file (we'll consider supporting other formats like yaml or toml if there's enough interest) and must be named with one of the allowed file names.

Just ensure there's a hooks object key, and then for every git hook you want to run, add a key with the hook name (see supported hooks for allowed hook names) and the script/command you want to run.

// captaingithook.json
{
    "hooks": {
        "pre-commit": "golint ./...",
        "pre-push": "go test ./..."
    }
}

Supported Hooks

captain-githook supports all the below git hooks:

  • applypatch-msg
  • pre-applypatch
  • post-applypatch
  • pre-commit
  • prepare-commit-msg
  • commit-msg
  • post-commit
  • pre-rebase
  • post-checkout
  • post-merge
  • pre-receive
  • update
  • post-receive
  • post-update
  • pre-auto-gc
  • post-rewrite
  • pre-push

Config File Names

There are several supported names you can use for your config file:

  • captaingithook.json
  • .captaingithook.json
  • captaingithookrc
  • .captaingithookrc
  • captaingithookrc.json
  • .captaingithookrc.json
  • captain-githook.json
  • .captain-githook.json
  • captain-githookrc
  • .captain-githookrc
  • captain-githookrc.json
  • .captain-githookrc.json

Remove

Not yet implemented


Back to top

captain-githook's People

Contributors

calebcartwright avatar renovate-bot 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

Watchers

 avatar  avatar  avatar

captain-githook's Issues

Add Goreleaser

Incorporate Goreleaser to simplify and facilitate the compilation/packaging/etc. process of the release artifacts

Release Pipeline

Need to setup a release pipeline to build various platform binaries, validate, and publish them to GitHub releases

Support skipping hook installs

We should add support for skipping the installation of hooks, as this is very helpful in many circumstances and also a commonly supported feature in other git hook utils.

Switch to Task

Switch from Mage to Task now that we know about gotestsum.

While Mage is a decent solution for running tasks in Go projects, we were only using it here due to our need to generate multiple test result format files (for Sonar, Azure DevOps, etc.) which needs to be done programmatically. gotestsum however provides a great CLI for handling all that work which means we no longer need our own Go code using exec.Command from the os package.

Task allows us to utilize a configuration file (yaml) to define scripts, much like npm scripts defined in the package.json file, and allows to avoid some of the challenges mage creates with *-on-save features and placing *.go source files in the root of the repo.

Setup VSTS/ADO

Configure builds in the newly dubbed "Azure DevOps" pipelines

Configure Renovate

Renovate support for Go modules has just landed, so we can now configure this repo accordingly.

Update PR/CI

Can disable AppVeyor and need to incorporate Coverage publishing step into AZP now that duplicative Circle job has been disabled

Setup linting

Pretty self-explanatory, need to figure out how we should best use golint in conjunction with a revive and/or golangci-lint

Dev setup

Add various scripts, utils, etc. for contributors to get set up to work in this repo

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.