Working with Mantis and SVN

[del.icio.us] [Slashdot] [Digg] [Reddit] [Facebook] [Technorati] [Google] [StumbleUpon]

For developing software we use Mantis and Subversion (SVN), and as a client we are using SVN for Dreamweaver. We are not the only ones, it is simple, it is the perfect combination for developing and both products are Open Source too. The problem we are facing is that we are working twice at each task. This means loosing time, and time is money.

What is in fact the process in which runs a bug/new feature?

There are several steps that a bug goes through, but most of its time stays in resolving/commenting. The first step is adding it to the system, the so called "Report issue". After adding it to the system, this has to be allocated to a developer, this way is starting the development/programming process. In many cases a bug/new feature is not resolved at first try, this needs to be developed, tested, modified and finally resolved/closed. Until now, this seems to be a quite difficult and time consuming task. After the programmer had applied the source changes on SVN and left a comment on the “commit” notes field, he should have entered through Mantis interface and add a comment there too, and add working time. After the problem had been solved and the bug had been “fixed”, it was checked and marked as "closed".

I’ve read more articles on the internet, but the one that had put us on "the right track" was "Integrating Mantis and Subversion". The thing interests us is that when a programmer comments in SVN the file he had been working on, it goes to Mantis too, at "issue number #XX", to the task he had been working on. Following the steps from the article, I’ve taken the post-commit part. Run after the transaction is committed, and a new revision is created. Often used to send notification emails or trigger repository backups. Errors from this hook are ignored Subversion comes with some scripts for common actions.

I’ve created a new user in Mantis, I’ve named it svn. I’ve than added it to our projects and given it all the permissions needed to comment and fix a task. After this, I’ve added a few lines in config_inc.php, as read on Mantis forum.

# Account to be used by the source control script.  The account must be enabled
# and must have the appropriate access level to add notes to all issues even
# private ones (DEVELOPER access recommended).
$g_source_control_account = 'svn';


# For open source projects it is expected that the notes be public VS_PUBLIC, however,
# for non-open source it will probably be VS_PRIVATE.
$g_source_control_notes_view_status = VS_PRIVATE;


# Regular expression used to detect issue ids within checkin comments.
# see preg_match_all() documentation at (detect bug or issue in comment)
$g_source_control_regexp = '/b(?:bug|issue)s*[#]{0,1}(d+)b/i';


# If set to a status, then after a checkin with a log message that matches the regular expression in
# $g_source_control_fixed_regexp, the issue status is set to the specified status.  If set to OFF, the
# issue status is not changed. Use CLOSED if you prefer.
$g_source_control_set_status_to = RESOLVED;


# Whenever an issue status is set to $g_source_control_set_status_to, the issue resolution is set to
# the value specified for this configuration.
$g_source_control_set_resolution_to = FIXED;


# Regular expression used to detect the fact that an issue is fixed and extracts
# its issue id.  If there is a match to this regular expression, then the issue
# will be marked as resolved and the resolution will be set to fixed.

$g_source_control_fixed_regexp = '/bfix(?:ed|es)s+(?:bug|issue)?s*[#]{0,1}(d+)b/i';

The next step is checking whether everything is OK. After executing these commands, the results should be a #526 comment at the bug.

php /path/to/mantis/core/checkin.php <<< "We have fixed issue #526 solved some things etc...."

Following the steps mentioned in the article, I’ve also modified the /path/to/svn/hooks/post-commit file and I’ve changed it in executable (chmod 770 post-commit). This is how our post-commit file looks like...

#!/bin/bash

REPOS="$1"
REV="$2"

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'

cd "/path/to/mantis/"
echo -n "Changeset [$] by $auth, $dt$n$log$n$changed" | /usr/bin/php -q "./core/checkin.php" > /dev/null


#echo "Changeset [$] by $auth, $dt$n$log$n$changed" >> /tmp/svnlog.nop.log
exit 0

This is what others did too, I haven’t said anything new until now, but we had to redo the steps to see what the problems are. Even if the major problem was solved, it still wasn’t enough, the programmers needed to tell us for every task (issue) even the time they have spent on them. Some projects are paid by the hour. So the solution was only resolved partially. We needed to be able to send the time to Mantis.

So just a little research…. In the ./core/checkin.php file was the solution. I’ve added the time part, in order to be sent as an issue, and the time t=hh:mm

# Call the custom function to register the checkin on each issue.

$timestra = array();
if (preg_match('/t=(d+):(d+)/',$t_comment,$timestra)){
$h=$timestra[1];
$m=$timestra[2];
$minutes=$h*60+$m;
};
foreach ( $t_issues as $t_issue_id ) {
if ( !in_array( $t_issue_id, $t_fixed_issues ) ) {
helper_call_custom_function( 'checkin', array( $t_issue_id, $t_comment, $t_history_old_value, $t_history_new_value, false ,$minutes) );
}
}

foreach ( $t_fixed_issues as $t_issue_id ) {
helper_call_custom_function( 'checkin', array( $t_issue_id, $t_comment, $t_history_old_value, $t_history_new_value, true , $minutes) );
}

This, however, was not enough, I’ve written a modified function, ./custom_functions_inc.php

function custom_function_override_checkin( $p_issue_id, $p_comment, $p_file, $p_new_version, $p_fixed,$minutes ) {
if( bug_exists( $p_issue_id ) ) {
history_log_event_special( $p_issue_id, CHECKIN, $p_file, $p_new_version );
$t_private = false;
if( VS_PRIVATE == config_get( 'source_control_notes_view_status' ) ) {
$t_private = true;
}
$bugnote_id=bugnote_add( $p_issue_id, $p_comment, 0, $t_private );

$t_status = config_get( 'source_control_set_status_to' );
if(( OFF != $t_status ) && $p_fixed ) {
bug_set_field( $p_issue_id, 'status', $t_status );
bug_set_field( $p_issue_id, 'resolution', config_get( 'source_control_set_resolution_to' ) );
}
if (!empty($minutes)) bugnote_set_time_tracking($bugnote_id,db_minutes_to_hhmm($minutes));
}
}

Now the solution is resolved. The three images above, speak for themselves :-)

Source code and the DIFF file for checkin.php can be downloaded here. We used Mantis 1.2.0a3.







Print
Send link by e-mail