Simple git hooks manager
npm install @arkweid/hookah-jsHookah its a simple manager of git hooks.

Add Hookah to your system or build it from sources.
bash
go get github.com/Arkweid/hookah
`$3
`bash
npm i @arkweid/hookah-js --save-dev
or yarn:
yarn add -D @arkweid/hookah-jsNow you can call it:
npx hookah -h
`
NOTE: if you install it this way you should call it with npx for all listed examples below.$3
`bash
sudo snap install --devmode hookah
`$3
`bash
brew install Arkweid/hookah/hookah
`Or take it from binaries and install manualy
Scenarios
$3
Go to your project directory and run:
`bash
hookah install
`It add for you configuration file
hookah.yml with default directories for hooks sources.
Now we ready to add hooks! For example we want to add pre commit hooks. Lets do that:
`bash
hookah add pre-commit
`It will add a hook
.git/hooks/pre-commit. So every time when you run git commit this file will be executed.
That directories also will be created .hookah and .hookah-local.
Use first one for project/team hooks. Second one for you personal hooks. Add it to .gitignoreNext fill the directory
.hookah/pre-commit with executables you like`
├───.hookah
│ └───pre-commit
│ ├─── fail_script
│ └─── ok_script
`Example:
`bash
cat > .hookah/pre-commit/fail_script#!/bin/sh
exit 1
cat > .hookah/pre-commit/ok_script
#!/bin/sh
exit 0
Now we can commit:
git commit -am "It fail"
`Done! Pretty simple, huh?
$3
hookah.yml
`yml
pre-commit:
commands:
eslint:
glob: "*.{js,ts}"
runner: yarn eslint {staged_files} # hookah run it like "yarn eslint App.js Model.js ..."
rubocop:
tags: backend style
glob: "*.{rb}"
exclude: "application.rb|routes.rb" # simple regexp for more flexibility
runner: bundle exec rubocop {all_files}
govet:
tags: backend style
files: git ls-files -m # we can explicity define scope of files
glob: "*.{go}"
runner: go vet {files} # {files} will be replaced by matched files as arguments # If you have script files, you can specify parameters for them
scripts:
"hello.js":
runner: node # hookah run it like "node hello.js"
"any.go":
runner: go run # hookah run it like "go run any.go"
# Not enough speed? Run all of them in parallel!
# Default: false
parallel: true
`
If your team have backend and frontend developers, you can skip unnsecesary hooks this way:
hookah-local.yml
`yml
pre-commit:
# I am fronted developer. Skip all this backend stuff!
exclude_tags:
- backend scripts:
"any.go":
runner: docker exec -it --rm {cmd} # Wrap command from hookah.yml in docker
commands:
govet:
skip: true # You can also skip command with this option
`$3
No problem, hookah have command for that:
`bash
hookah run pre-commitYou will see the summary:
[ FAIL ] fail_script
[ OK ] ok_script
`$3
Ok! For example you have
any.go script. We can run it in this way:Add
hookah-local.ymlAdd it to
.gitignore. It your personal settings.Next customize the
any.go script:`yaml
pre-commit:
"any.go":
runner: "go run"
`Done! Now our script will be executed like this:
`bash
go run any.go
`$3
We suppose repo already have the hookah structure. So all of you need it run install:
`bash
hookah install
`
Hookah wiil read existed hook groups and reproduce hooks in .git/hooks directory.$3
We have env HOOKAH=0 for that
`bash
HOOKAH=0 git commit -am "Hookah skipped"
`$3
We have env HOOKAH_EXCLUDE=tag,tag for that
`bash
HOOKAH_EXCLUDE=ruby,security git commit -am "Skip some tag checks"
`$3
No problem. Lets take
rubocop linter for ruby as example:`bash
#!/bin/shgit ls-files -m | xargs rubocop
`$3
Ok-ok! This is how
any.go may looks like:`go
package mainimport (
"fmt"
"os"
"os/exec"
"strings"
"github.com/Arkweid/hookah/context"
)
func main() {
files, _ := context.StagedFiles()
files = context.FilterByExt(files, ".rb")
cmd := exec.Command("rubocop", strings.Join(files, " "))
outputBytes, err := cmd.CombinedOutput()
fmt.Println(string(outputBytes))
if err != nil {
os.Exit(1)
}
}
`
We include context package only for convenience. Its just few useful functions.Example for prepare-commit-msg hook:
``bash
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3
$3
Yes. You can do this through this config keys:
hookah.yml
`yml
source_dir: ".hookah"
source_dir_local: ".hookah-local"
`$3
`bash
hookah uninstall
``