May 14, 2008 @ 7:55 am
tags: , ,

Quick and dirty: SVN is version control software. Mantis is a web-based bug tracking in PHP you can install on your server. And Beanstalk is hosted a SVN service, because I screw up my own repositories all the time.

The cool part is that you can hook scripts into SVN for just about anything with the right knowledge. The bad part is that, with hosted SVN, you generally don't have the ability to set up those hooks. Here is how I got around that little caveat.


It is simple really: rename the svn program to svn_old and replace it with a script that calls svn and your mantis script. Sure, that's a little extreme, but I've been typing svn too long to stop now, certainly during a big project crunch. For the timid, you can call the script whatever you want and forego renaming svn.

You will need to modify your Mantis' config_inc.php a bit. I found these lines of code from this guy who last year helped us all integrate a local mantis to a local svn repository. Add the following lines:

$g_source_control_account = 'svn';
$g_source_control_regexp = '/\b(?:bug|issue)\s*[#]{0,1}(\d+)\b/i';
$g_source_control_set_status_to = RESOLVED;
$g_source_control_set_resolution_to = FIXED;
$g_source_control_fixed_regexp = '/\bfix(?:ed|es)\s+(?:bug|issue)?\s*[#]{0,1}(\d+)\b/i';

Now for the actual script:

#!/usr/bin/php -q
<?php
// path variables
$path_svn = '/usr/bin/svn_old';
// or just svn if you didn't rename
$path_mantis = '/usr/bin/php -q /path/to/mantis/core/checkin.php';
// take off the $argv[0]
$argv = array_slice($argv, 1);
// parse incoming variables to find message
$use_next_variable = false;
foreach ($argv as $id => $arg) {
  if ($use_next_variable) {
    $argv[$id] = '\". $argv[$id]. '\";
    break;
  }
  if ($arg == '-m') {
    $use_next_variable = true;
  }
}
// build commands
$command_svn = $path_svn. ' '. implode($argv, ' ');
$command_mantis = $path_mantis . ' <<< '. $argv[$id];
// do svn
system($command_svn);
// no reason to get mantis' hopes up if !$use_next_variable
if ($use_next_variable) {
  // do mantis
  system($command_mantis);
}

I couldn't find a working PHP colorizer plugin for Wordpress that worked how I wanted it to, so no color syntax for you. If you renamed svn and named your new script that, you will have the enjoyable feature of having to change absolutely nothing about your svn routine.

I'm out.

1 Comment »

  1. not php colorizer, php code higlighter.
    i suggest Geshi. Geshi can highlight many file formats.
    I think You can integrate it with Wordpress or search for geshi plugin if someone does it.

    Comment by turker — August 17, 2008 @ 5:33 am

RSS feed for comments on this post. TrackBack URI

Leave a comment