echo " git config hooks.slack.channel 'general'"
echo " git config hooks.slack.show-only-last-commit 'true' #optional"
echo " git config hooks.slack.username 'git' #optional"
- echo " git config hooks.slack.icon-url 'http://imgur/icon.png' #optional"
- echo " git config hooks.slack.icon-emoji ':twisted_rightwards_arrows:' #optional"
echo " git config hooks.slack.repo-nice-name 'MyRepo' #optional"
- echo " git config hooks.slack.repos-root '/path/to/repos' #optional"
- echo " git config hooks.slack.changeset-url-pattern 'http://yourserver/%repo_path%/changeset/%rev_hash
-%' #optional"
- echo " git config hooks.slack.compare-url-pattern 'http://yourserver/%repo_path%/changeset/%old_rev_ha
-sh%..%new_rev_hash%' #optional"
}
function notify_slack() {
if [[ "${change_type}" != "delete" && "${refname_type}" == "branch" ]]; then
- changeseturlpattern=`git config --get hooks.slack.changeset-url-pattern`
- compareurlpattern=`git config --get hooks.slack.compare-url-pattern`
reporoot=`git config --get hooks.slack.repos-root`
urlformat=
- if [ -n "$changeseturlpattern" -a -n "$reporoot" ]; then
- if [[ $PWD == ${reporoot}* ]]; then
- repopath=$PWD
- base=`basename $PWD`
- if [ "$base" == ".git" ]; then
- repopath=`dirname $repopath`
- fi
- idx=`echo $reporoot | wc -c | tr -d ' '`
- repopath=`echo $repopath | cut -c$idx-`
- urlformat=`echo $changeseturlpattern | sed "s|%repo_path%|$repopath|g" | sed "s/%rev_hash%/%H/g"`
-
- if [ -n "$compareurlpattern" ]; then
- comparelink=`echo $compareurlpattern | sed "s|%repo_path%|$repopath|g" | sed "s|%old_rev_hash%|$oldrev|g" | sed "s|%new_rev_hash%|$newrev|g"`
- header=`echo $header | sed -e "s|\([a-zA-Z0-9]\{1,\} new commit[s]\{0,1\}\)|\<$comparelink\|\\1\>|"`
- fi
- else
- echo >&2 "$PWD is not in $reporoot. Not creating hyperlinks."
- fi
- fi
formattedurl=""
if [ -n "$urlformat" ]; then
webhook_url=$(git config --get hooks.slack.webhook-url)
channel=$(git config --get hooks.slack.channel)
username=$(git config --get hooks.slack.username)
- iconurl=$(git config --get hooks.slack.icon-url)
- iconemoji=$(git config --get hooks.slack.icon-emoji)
if [ -z "$webhook_url" ] || [ -z "$channel" ]; then
echo "ERROR: config settings not found"
payload="$payload, \"username\": \"$username\""
fi
- if [ -n "$iconurl" ]; then
- payload="$payload, \"icon_url\": \"$iconurl\""
- elif [ -n "$iconemoji" ]; then
- payload="$payload, \"icon_emoji\": \"$iconemoji\""
- fi
-
payload="$payload}"
if [ -n "$DEBUG" ]; then