Skip to content

Instantly share code, notes, and snippets.

@rkJun
Last active October 30, 2023 18:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rkJun/f524b393a123af67b203 to your computer and use it in GitHub Desktop.
Save rkJun/f524b393a123af67b203 to your computer and use it in GitHub Desktop.
Subversion integration with Slack
#!/bin/bash
#
# Bash script for Subversion integration with Slack
#
# 1. Save this file in /usr/bin as slack-svn
# 2. Make it executable:
# chmod +x /usr/bin/slack-svn
# 3. Put this line at the end of file of your_svn_repo/hooks/post-commit:
# slack-svn $REPOS $REV full_path_to_svn_directory
# 4. Edit this file, especially from line 16-20 and 27 (example given is for Redmine)
#
# Refs:
# - https://github.com/chriseldredge/git-slack-hook/blob/master/git-slack-hook
# - http://svnbook.red-bean.com
# - https://api.slack.com/docs/attachments
REPOS="$1"
REV="$2"
PATH="$3"
# Change these lines as needed
channel="#yourchannel"
username="svn"
iconurl="http://i.imgur.com/2RqyaIS.png"
org_name="yourslackorgname"
token="yourtoken"
# SVN Info
author=$(/usr/bin/svnlook author -r $REV $PATH)
commit_msg=$(/usr/bin/svnlook log -r $REV $PATH)
header="New commit:"
value="<http://redmine.org/projects/projectname/repository/revisions/$REV|$REV> $commit_msg"
attachments="[{ \"fallback\" : \"${header}\", \"color\" : \"good\", \"fields\" : [ {\"title\" : \"${author}\", \"value\" : \"${value}\"} ] }]"
#msg=$(echo -e "\"text\":\"${header}\", \"attachments\" : $attachments")
#payload="{${msg}, \"channel\": \"$channel\""
#payload="$payload, \"username\": \"$username\""
#payload="$payload, \"icon_url\": \"$iconurl\""
#payload="$payload}"
payload="{\"channel\": \"$channel\" , \"text\": \"New commit: $value - $author\" }"
/usr/bin/curl \
--data-urlencode "payload=$payload" \
"https://${org_name}.slack.com/services/hooks/incoming-webhook?token=$token"
@rboman
Copy link

rboman commented Mar 18, 2019

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment