I was kinda bored yesterday. And was poking around the SVN hooks scripts. When i noticed the post-commit script i was using was written in Python. Nothing wrong with that. I just wondered how hard it would be to do the same in PHP. So i came up with a little test. Which at this moment lacks error checking and just looks plain ugly. But it does the job. and i only needed a working PHP CLI executable to make it work.
First we set the email address and the location of svnlook.
Use the argv array to get to the commandline parameters and build up a SVN statement to get some basic info.
Now let’s get the changes made in this revisions.
Once we have the diff contents we can loop through the lines and use some simple regex to highlight the changes. I’ve added a bit more code to add pre tags for a better visual effect.
Now we can build the body for the email that will be generated.
Add a MIME header so my mail client displays it properly. And send it of through the build in mail() function.