Subscribe to the RSS feed by copy/paste the link below
RSS

Mantis GIT Integration

Posted by Admin on 13. August, 2018
MyBlog ยป

I'd read many web tutorials about integrating MantisBT SVN with and I  wanted to do the same for GIT. My git server and MantisBT server are  the same machine which greatly simplified the process.


First edit config_inc.php in the mantis directory to include the following lines.


# Git integration<br />
$g_source_control_account = 'git';<br />
$g_source_control_regexp = '/\b(?:bug|issue|Bug|Issue)\s*[#]{0,1}(\d+)\b/i';<br />
$g_source_control_set_status_to&nbsp;&nbsp;&nbsp;&nbsp; = RESOLVED;<br />
$g_source_control_set_resolution_to = FIXED;<br />
$g_source_control_fixed_regexp&nbsp; = '/\bFix(?:ed|es)\s+(?:bug|issue)?\s*[#]{0,1}(\d+)\b/i';<br />
$g_source_control_notes_view_status = VS_PUBLIC;<br />

 


<p>Now create a post-receive hook in your bare repo containing the following.</p>

#!/bin/bash
# Push to the repository and build the html asciidocs.

while read oldrev newrev ref; do # Loop through branches
  #echo  -e "$oldrev $newrev $ref"
  revs=$(git rev-list $oldrev..$newrev --reverse)
  for rev in $revs; do # Loop through commits
    echo $rev
    if
    then
      echo "This is a bug branch";
      branch=$(basename $ref)
      msg="Branch $branch - $(git log  $rev^..$rev --name-only)"
      /usr/bin/php -q /home/mikee/progs/mantisbt/scripts/checkin.php <<< "$msg"
      echo -e $msg
    else
      echo "This is not a bug branch";
      branch=$(basename $ref)
      msg="Branch $branch - $(git log $rev^..$rev  --name-only)"
      /usr/bin/php -q /home/mikee/progs/mantisbt/scripts/checkin.php <<< "$msg"
      echo -e $msg
    fi
  done
done

There are two loops here. This script gets input as space delimited lines (oldrev newrev ref) for each BRANCH contained in the push, so that's the first loop. The second loop is to get each COMMIT (for each branch) in the push, the second loop. Without the two loops you will just process that last commit of the first branch of the data pushed. Add this to your git templates.

Your can omit the echo lines, these are for debugging.

Now when you are fixing a Mantis bug report, checkout a branch with the name Bug#nn. Work on the bug, checkin the bug then push to the repo. The post-receive hook will pass the string to MantisBT and this will become a comment on the bug. This can be modified to close the bug automatically if desired by adding the lines:


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

 

to config_inc.php then add the codewords "Fixed bug #nn" or  "Fixes bug #nn"; to the start of the commit message.


Because checkin.php only accepts local input , if MantisBT is on a different machine you will need to write a web interface file (web-checkin.php perhaps) and send the commit message to it using curl, or some other means.&nbsp; The git hook can be written using Python instead of bash which may make this process easier.&nbsp; I&nbsp;may do this and post the php script here later.


To follow up on this I'm looking into synronising the GitHub issues with my MantisBT bugtracker using Python. I'll do another blog post whem I'm done. Or fail to.


UPDATE
This is borken on mantis 2.3 as scripts/checkin.php is missing and core/custom_function_api.php is missing custom_function_default_checkin function.
From an old version of mantis I copied over checkin.php and edited custom_function_api.php by adding back in the missing function. It now works again.
The newer mantis' have a plugin for source control integration but it doesn't fit my use-case so is no use to me at all.

UPDATE 2
In  custom_function_api.php the keyword CHECKIN is no longer valid and will throw an error, Change it to BUGNOTE_ADDED and all will be well again.

Last changed: 13. August, 2018 at 17:49

Back to Overview



Comments

No comment found

Add Comment