vmware-marketplacemantis

Integrate Subversion with Mantis

Follow these steps:

  • Install Subversion using the system packages:

          $ sudo apt-get update && sudo apt-get install -y subversion
    
  • Create a repository using the following commands:

      $ sudo mkdir /opt/bitnami/repositories
      $ sudo svnadmin create /opt/bitnami/repositories/myapp
      $ sudo chown -R bitnami:daemon /opt/bitnami/repositories
      $ sudo chmod -R 775 /opt/bitnami/repositories
    
  • Create a new Mantis user, which will be the user that the script will run as. Edit the /opt/bitnami/mantis/config/config_inc.php file and add the following lines:

      /* Subversion Connection*/
    
      $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';
    
  • Create the post-commit script, which will call Mantis after every commit, at /opt/bitnami/repositories/mantis/hooks/post-commit. Fill it with this content:

      #!/bin/bash
    
      REPOS="$1"
      REV="$2"
      SVNLOOK="svnlook"
    
      auth=$($SVNLOOK author -r $REV $REPOS)
      dt=$($SVNLOOK date -r $REV $REPOS)
      changed=$($SVNLOOK changed -r $REV $REPOS)
      log=$($SVNLOOK log -r $REV $REPOS)
      n=$'\n'
      /opt/bitnami/php/bin/php -q */opt/bitnami/mantis/scripts/checkin.php <<< "Changeset [${REV}] by $auth, $dt$n$log$n$changed"
    
  • Change script permissions so that it can be executed by the daemon user:

      $ sudo chown bitnami:daemon /opt/bitnami/repositories/mantis/hooks/post-commit
      $ sudo chmod 775 /opt/bitnami/repositories/mantis/hooks/post-commit
    

This script will add a line to the corresponding Mantis issue number when a commit message references that issue number, such as:

$ svn commit -m "whatever issue #number whatever"

It will also close the Mantis issue with status “resolved” when a commit message includes the word “fixed” and the issue number, like this:

$ svn commit -m "whatever fixed issue #number whatever"
Last modification February 9, 2023