Table Of Contents
This repository contains Subversion (VisualSVN) hook scripts that post messages to Discord.
NOTE: The CMD hook scripts that call the Python scripts are only valid when used with a Windows installation of VisualSVN. However, it should not be difficult to set it up with a non-Windows installation.
- VisualSVN : https://www.visualsvn.com/
- Discord : https://discordapp.com/
- Python 3.6 : https://www.python.org/downloads/
You'll need to have the following Python libraries installed in order to use these hook scripts. They can be installed with the
pip install <libraryname> command-line command.
pip install requests
pip install subprocess
syslibrary : (included in Python)
After a commit is made to the specified repository, this hook script posts a message to Discord server channel, which is specified through a webhook. The message contains the name of the repository, the revision number, the name of the user who committed, the commit message, and the changelist. The hook script will automagically truncate commit messages longer than 200 characters and changelists longer than 1700 characters in order to abide by Discord's maximum character limit of 2000.
Below are a few examples of what the message looks like in multiple scenarios.
- In VisualSVN, open your repository's Properties page.
- Navigate to the Hooks tab and double-click the "Post-commit hook" property.
- Copy the contents of scr/post-commit.cmd and paste them into the hook dialog's text box.
pythonw_file_pathto point to the location of
pythonw.exein your Python installation directory.
Download scr/post-commit.py, then change
hook_script_file_pathto point to the file path to which you downloaded
reponameto the name of the repository as set in VisualSVN.
In your Discord server, create a webhook in the channel in which the commit messages should be posted, copy the URL, then change
discord_webhook_urlto that URL.
NOTE: The Python hook script will override any username and avatar you specify in the Discord webhook dialog. With that said, the script can easily be changed if you don't want it to do this.
Click OK to accept the changes in the hook dialog, then click Apply and OK to accept the changes in the Properties dialog.
post-commit.pyin a text editor.
Change the value of
reporootdirto point to the root directory in which your Subversion repositories are stored. Don't forget to use double-backslashes in the file path! Also, make sure there's a (double-)backslash at the end of the file path so the repository's full file path can be assembled correctly.
reporootdir = "Y:\\Repositories\\"
- Change the value of
svnlookto point to the location of
svnlook.exe, which can be found in VisualSVN's installation directory.
svnlook = "C:\\Program Files\\VisualSVN Server\\bin\\svnlook.exe"
- Optionally, change the value of
botavatarurlto the URL of your own custom image to use for the avatar of the bot that'll post the commit message.
botavatarurl = "https://i.imgur.com/Pi5ICIR.jpg"
- Finally, save and close the file and try out the hook with a test commit to the repository for which you configured it!