Skip to content

Instantly share code, notes, and snippets.

@andrioid
Last active December 19, 2016 16:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrioid/9808592 to your computer and use it in GitHub Desktop.
Save andrioid/9808592 to your computer and use it in GitHub Desktop.
Slack Subversion Post Commit Hook
#!/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