generalmantis

Integrate Subversion with Mantis

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

Follow these steps:

  • Install Subversion using the system packages:

    • Debian:

        $ sudo apt-get update && sudo apt-get install -y subversion
      
    • CentOS:

        $ sudo yum install subversion
      

Approach A: Bitnami installations using system packages

  • 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"

Approach B: Self-contained Bitnami installations

  • 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/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="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 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 June 16, 2021