Yesterday (and the day before, and the day before that) I spent some time try to get my Subversion install to send a message to Twitter when I commit some code. Yes, I know it's a fairly pointless feature, but it started off as a bit of fun, which really I should have cut and run after the first hour of non-progress. But I'm a stubborn kinda guy, so I ploughed on, and eventually got it to work. Here's (some) of the story.
If you want to know how I got it to work, skip straight to step 4.
Step 1 - There Must be a Twitter Plugin...
I'd just done exactly the same thing with my Jenkins server, and that seriously took all of 10 minutes. I browsed the plugin repositroy, found one that tweets after a Jenkins build, I installed it, configured the necessary OAuth stuff, and I'm off. Job done.
So I approached Subversion (naively) in the same way - there must be a plugin, right? I can't be the only person who's thought of this?
Wait! Subversion doesn't do plugins, does it? Damn. Okay, a little googling later, and up comes TwitVN, which looks promising - let's start following the instructions.
Step 2 - Install Python
First off, I head across to http://www.python.org/ to download an up-to-date copy of Python. I install the thing (c:\python27? That install location doesn't sit too well with me!), open up a command prompt, and test it out. I can run the exe no problem, Ctrl+Z followed by Enter to exit (huh!?), and I'm back at a command prompt.
I now need "easy_install" apparently, this comes easily enough from http://pypi.python.org/pypi/setuptools, again this works okay, so far so good! I pull down the tools that TwitVN needs (simplejson and Tweepy), and I'm now ready to test TwitVN.
Step 3 - Waste a Few Hours with Python SVN Addons
To test TwitVN, I discover I need to replace my post-commit.py file with a post-commit.bat file, since Windows SVN doesn't have the ability to run these python scripts apparently. So I create a post-commit batch file with the following command:
And then I execute said batch file. Damn, the first thing I get is an error about a missing module "svn.repos". Okay, there's just another "egg" I need to install with that easy_install tool, right? Nope. Well then there's going to be a website with all the stuff where I can run some simple process to do the install, and there's gotta be a ton of people messing around with Python and Subversion on Windows anyhow? Again nope (in this case nope twice).
There are some promising results showing up in Google, but it turns out that since Subversion is currently migrating to the Apache guys, there're broken links all over the place. Not only that, there seem to be multiple libraries available - there's something called PySvn, which seems like my best bet, but that doesn't seem to match the libraries that my TwitVn script uses, so that's a no go. Most of the hours wasted on this little project went into searching (in vain) for the right Python module.
Step 4 - Uninstall Python, and Install A Subversion Server with Python Integrated
At this point, a different plan of attack. Rather than trying to put all these bits together myself, I had a vague recollection that there was a distribution of Subversion that already had Python integrated, and if so it MUST have the svn.* modules preloaded? Let's investigate...
I end up doing the following:
- Uninstall existing non-Collabnet Subversion installation
- Install Collabnet's Subversion Edge, which has integrated Python (for some reason this took me an hour for an 80 meg file)
- Check that you now have the following two files present:
- First hack - at this point I had to do a registry hack to get the next tool to install correctly:
- Open regedit
- Navigate to "HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.5\InstallPath"
- There should be a (Default) entry under this key, if there are quotation marks around the path name for this value, you'll need to remove them.
- Follow the TwitVn instrctions at http://code.google.com/p/twitvn/wiki/TwitVNOAuthSetup:
- Install the "easy_install" tool from http://pypi.python.org/pypi/setuptools. When installing this tool, check the two folder locations it gives you are valid.
- Open a command prompt, navigate to C:\csvn\Python25\Scripts
- Type in "easy_install simplejson" to install Simplejson
- Type in "easy_install tweepy" to install Tweepy
- Navigate to the "hooks" folder in your Subversion repository folderAdd a "post-commit.bat" file with the following lines:
- set PYTHONPATH=C:\csvn\lib\svn-python
- c:\csvn\python25\python.exe D:\path\to\svn\repository\hooks\TwitVN\twitvn.py -f "%1" -r "%2"
- Complete the OAuth config as per the TwitVn instructions.
- Test your batch file by opening a command prompt in this location, and entering "post-commit d:\path\to\svn\repository 1"
- Second hack - at this point I got a pop-up window saying "libapr-1.dll was not found":
- Copy all of the DLLs from "c:\csvn\bin" to "c:\windows\system32"
- Test your script again, at this point I now got an error about using the "len" function on the author field. This is because none of my subversion commits have an author.
- To fix this, consider adding the following to your just before the line that generates the error:
- if not author: author = "Anon"
- One more test, and lo and behold, it works!
Granted, this isn't the most productive use of my time I can recall, but it's been an adventure at least!