bchmantis

Integrate Subversion with Mantis

Follow these steps:

  • [Configure Subversion access over HTTP](/bch/apps/subversion/get-started/configure-use-svn-repository/.

  • Create a repository using the following commands:

      $ sudo mkdir /opt/bitnami/repositories
      $ sudo svnadmin create /opt/bitnami/repositories/myapp
      $ sudo chown -R daemon:bitnami /opt/bitnami/repositories
    
  • Create a new Mantis user, which will be the user that the script will run as. Edit the /opt/bitnami/apps/mantis/htdocs/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="/opt/bitnami/subversion/bin/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/apps/mantis/htdocs/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 daemon:bitnami /opt/bitnami/repositories/mantis/hooks/post-commit
      $ sudo chmod u+x /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 April 8, 2020