X-Git-Url: https://git.ctpug.org.za/?p=gitolite-hooks.git;a=blobdiff_plain;f=slack;h=a8055eb6fb5a8ad2682408bee76d66682e45c018;hp=e83153cdc9c4cd3dbab1a963f65c43630a63cc05;hb=HEAD;hpb=4ffd5e46ac227a7bfec52537ad8213b0c3ba4471 diff --git a/slack b/slack old mode 100644 new mode 100755 index e83153c..a8055eb --- a/slack +++ b/slack @@ -8,20 +8,13 @@ # Based on post-receive.irc by Mikael Fridh https://gist.github.com/1821358 # -function help() { +function help_slack() { echo "Required config settings:" echo " git config hooks.slack.webhook-url 'https://hooks.slack.com/services/...'" 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() { @@ -164,30 +157,9 @@ 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 @@ -235,8 +207,6 @@ function notify_slack() { 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" @@ -250,12 +220,6 @@ function notify_slack() { 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 @@ -269,16 +233,3 @@ function notify_slack() { "$webhook_url" \ >/dev/null } - -webhook_url=$(git config --get hooks.slack.webhook-url) - -while read line; do - set -- $line - if [ -n "$webhook_url" ]; then - notify_slack $* - fi - - RET=$? -done - -exit $RET