#!/bin/bash # This script is designed to be called from a git post-update hook # Typical usage # In your post-update hook, the first parameter is the branch ref. So in post-update, you would # invoke this script something like this: # /usr/local/bin/post-update-slack $1 # The script will only post to slack if the branch being updated matches the one listed as # Use "any" to match any branch (hopefully you don't have a branch called "any") # Example: # /usr/local/bin/post-update-slack $1 any my_token git-commits # /usr/local/bin/post-update-slack $1 master my_token releases ref=$1 matchbranch=$2 token=$3 channel=$4 if [ $(git rev-parse --is-bare-repository) = true ] then repo=$(basename "$PWD") repo=${repo%.git} else repo=$(basename $(readlink -nf "$PWD"/..)) fi branch=$(git rev-parse --symbolic --abbrev-ref $ref) if [[ $matchbranch == "any" ]] || [[ $branch == $matchbranch ]] then message=$(git log -1 $ref "--pretty=format:%ci %cn %h %s") text="[$repo:$branch] $message" /usr/local/bin/slackpost $token $channel $text 2>&1 fi