Last active
August 29, 2015 14:12
-
-
Save dnsang/45925c666628f43bd92c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
######################################################################################### | |
# Bash script for Subversion integration with Slack # | |
# # | |
# 1. Save this file in /usr/bin as incomming_webhook_slack # | |
# 2. Make it executable: # | |
# chmod +x /usr/bin/incomming_webhook_slack # | |
# 3. Put this line at the end of file of your_svn_repo/hooks/post-commit: # | |
# incomming_webhook_slack $REPOS $REV svn_path # | |
# 4. Edit this file, config all variable to point to your webhook # | |
# # | |
# Refs: # | |
# https://gist.github.com/amree/8a12037a731bc4893d76 # | |
# # | |
# Special thanks to AnDQT@VNG # | |
# # | |
# Don't hesitate to tell me if you have any problem ! # | |
# # | |
######################################################################################### | |
export LANG="en_US.UTF-8" | |
export LC_ALL="en_US.UTF-8" | |
REPOS="$1" | |
REV="$2" | |
PATH="$3" | |
#export https_proxy=http://your-proxy-if-necessary:port | |
# Your chanel to post message | |
channel="#svn" | |
# Choose username to show | |
username="AutoLogger" | |
# Avatar | |
iconurl=":ghost:" | |
# Your webhook url when you add Incomming Webhook Integration | |
webhook_url="https://hooks.slack.com/services/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B" | |
# SVN Info | |
author=$(/usr/bin/svnlook author -r $REV $REPOS) | |
commit_msg=$(/usr/bin/svnlook log -r $REV $REPOS) | |
JSON_TOPIC_RAW=${commit_msg// | |
/\\\n} # \n (newline) | |
# Build payload to send to slack (use Incomming WebHook Api) | |
payload="{\"text\": \"Revision:${REV}\nAuthor:${author}\nMessage: ${JSON_TOPIC_RAW}\nPath: <${PATH}|click here> for detail\"}" | |
# | |
ret=`/usr/bin/curl | |
-H "Content-Type: application/json" \ | |
-d $"${payload}" \ | |
$webhook_url` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment