Last active
November 23, 2016 07:33
-
-
Save hjsix2/e64e85172893317875d871b828021cf1 to your computer and use it in GitHub Desktop.
Subversion integration with Slack
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 | |
# | |
# 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 | |
export LANG=ko_KR.UTF-8 | |
REPOS="$1" | |
REV="$2" | |
PATH="$3" | |
# Redmine WS Key | |
redmineKey = "TFlAcQ4JojHya7OxDNIJ" | |
# 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}" | |
# Redmine 자동 갱신요청. | |
/usr/bin/curl "http://bd.prototype.co.kr/redmine/sys/fetch_changesets?id=sto&key=$redmineKey" | |
/usr/bin/curl \ | |
--data-urlencode "payload=$payload" \ | |
"https://${org_name}.slack.com/services/hooks/subversion?token=$token" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment