1. About
2. Software
3. Dependencies
4. Hook Scripts
4.1. Post-commit
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.
requests
library :pip install requests
subprocess
library :pip install subprocess
sys
library : (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.
Normal-length commit message and changelist:
Long commit message, normal-length changelist:
Normal-length commit message, long changelist:
- 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.
-
Change
pythonw_file_path
to point to the location ofpythonw.exe
in your Python installation directory. -
Download scr/post-commit.py, then change
hook_script_file_path
to point to the file path to which you downloadedpost-commit.py
. -
Change
reponame
to 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_url
to 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.
-
Open
post-commit.py
in a text editor. -
Change the value of
reporootdir
to 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.
EXAMPLE: reporootdir = "Y:\\Repositories\\"
- Change the value of
svnlook
to point to the location ofsvnlook.exe
, which can be found in VisualSVN's installation directory.
EXAMPLE: svnlook = "C:\\Program Files\\VisualSVN Server\\bin\\svnlook.exe"
- Optionally, change the value of
botavatarurl
to the URL of your own custom image to use for the avatar of the bot that'll post the commit message.
EXAMPLE: 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!