Skip to content

Instantly share code, notes, and snippets.

@sanmai
Last active April 12, 2016 01:58
Show Gist options
  • Save sanmai/ef0c2dd609ae72db03af to your computer and use it in GitHub Desktop.
Save sanmai/ef0c2dd609ae72db03af to your computer and use it in GitHub Desktop.
Chained hook with Slack
mv --no-clobber .git/hooks/post-receive .git/hooks/post-receive-make
curl https://gist.githubusercontent.com/sanmai/ef0c2dd609ae72db03af/raw/chained-hook.sh > .git/hooks/post-receive
curl https://raw.githubusercontent.com/chriseldredge/git-slack-hook/master/git-slack-hook > .git/hooks/post-receive-slack
chmod +x .git/hooks/post-receive-* .git/hooks/post-receive

Configuration:

git config hooks.slack.webhook-url 'https://hooks.slack.com/services/...'
git config hooks.slack.repo-nice-name 'My Awesome Repository'
git config hooks.slack.show-only-last-commit false
#!/bin/bash
# Runs all executable hookname-* hooks and exits after,
# if any of them was not successful.
#
# Based on
# http://osdir.com/ml/git/2009-01/msg00308.html
data=$(cat)
exitcodes=()
hookname=$(basename $0)
# Run each hook, passing through STDIN and storing the exit code.
# We don't want to bail at the first failure, as the user might
# then bypass the hooks without knowing about additional issues.
for hook in $GIT_DIR/hooks/$hookname-*; do
test -x "$hook" || continue
echo "$data" | "$hook"
exitcodes+=($?)
done
# If any exit code isn't 0, bail.
for i in "${exitcodes[@]}"; do
[ "$i" == 0 ] || exit $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment