Created
June 12, 2014 00:30
-
-
Save caiosba/d69be6e7e343e27a9e62 to your computer and use it in GitHub Desktop.
Git hook to run tests after commit and notify a Slack channel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run tests after commit and notify a Slack channel | |
webhook_url="https://<your subdomain>.slack.com/services/hooks/incoming-webhook?token=<your token>" | |
channel="#<your channel>" | |
root=$(git rev-parse --show-toplevel) | |
cd $root | |
repo=$(basename $root) | |
user=$(git config --global --get user.name) | |
output=$(bundle exec rake test) | |
output=$(echo $output | sed 's/.*\(Finished tests in [0-9.]\+s, [0-9.]\+ tests\/s, [0-9.]\+ assertions\/s\.\).*[^0-9]\([0-9]\+ tests, .*\)/\1 \2/g' | sed 's/Finished tests/executed tests/g') | |
rev=$(git log -1 --format=format:%h) | |
ref=$(git rev-parse --abbrev-ref HEAD) | |
cd - >/dev/null | |
msg=$(echo "Build $rev of $repo/$ref by $user $output") | |
curl -X POST --data-urlencode "payload={\"channel\": \"$channel\", \"username\": \"Git CI\", \"text\": \"$msg\"}" $webhook_url | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just copy this file to .git/hooks on the root of your repository and set the variables $webhook_url and $channel.