Last active
December 19, 2016 16:54
-
-
Save andrioid/9808592 to your computer and use it in GitHub Desktop.
Slack Subversion Post Commit Hook
This file contains 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 | |
# Requires Curl and Subversion Server installed. | |
# Put this file as "post-commit" with 755 permissions on the hooks directory of your repo | |
REPO_PATH=$1 | |
REV=$2 | |
LOOK=/usr/bin/svnlook | |
CURL=/usr/bin/curl | |
CHANNEL="#general" | |
APIKEY="getyourown" | |
SUBDOMAIN="my" | |
URL="https://${SUBDOMAIN}.slack.com/services/hooks/incoming-webhook?token=$APIKEY" | |
RES=`$LOOK info -r $REV $REPO_PATH` | |
COMMIT=`echo "$RES" | awk 'BEGIN{RS="\n\n"; FS="\n"} {print $4}'` | |
USER=`echo "$RES" | awk 'BEGIN{RS="\n\n"; FS="\n"} {print $1}'` | |
MSG="$REV by $USER: $COMMIT" | |
JSON="{ | |
\"channel\": \"$CHANNEL\", | |
\"username\": \"Subversion\", | |
\"icon_emoji\": \":banana:\", | |
\"attachments\": [ | |
{ | |
\"fallback\": \"$MSG\", | |
\"color\": \"#36a64f\", | |
\"fields\": [ | |
{ | |
\"title\": \"Revision\", | |
\"value\": \"$REV\", | |
\"short\": true | |
}, | |
{ | |
\"title\": \"User\", | |
\"value\": \"$USER\", | |
\"short\": true | |
}, | |
{ | |
\"title\": \"Changes\", | |
\"value\": \"$COMMIT\", | |
\"short\": false | |
} | |
] | |
} | |
] | |
}" | |
$CURL -X POST --data "payload=$JSON" $URL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment