Dependency Graph

Dependency Graph
related to related to child of child of duplicate of duplicate of

View Issue Details

IDProjectCategoryView StatusLast Update
0007330mantisbtotherpublic2010-09-19 03:11
Reporterjba-mono Assigned Todhx  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionwon't fix 
Product Version1.0.5 
Summary0007330: Make Source Control Regex's work better for comma separated issue messages
Description

Hi guys, I'm trying to integrate my mantis issue tracking system with subversion and it mostly works really well.

I'm having trouble matching commit logs that fix multiple (comma separated)

The best way to explain this is with an example. I want to match the following line in a commit message and have it update all issues:

Issues #410, 455, 0000430, 421

This should identify 410, 455, 430 and 421 and add a bugnote to all. I use this regex:
"/\bissues? #?(\d+)(,? ?#?(\d+))*/i"

The problem with this is that php method that processes the regex only process all matches in the first item array matches[1][0..n]. Using the above regex, only the first issue is placed in matches[1][0], subsequent matches are placed in the later arrays, matches[2][..].

The tortoise SVN fokes get around this by having two regexes, one to define the entire string, and one to define which portion of the string is the issue number. So you would have the following regexes:
a) "/\bissues? #?(\d+)(,? ?#?(\d+))*/i"
b) (\d+)

It then applies the first regex to find the entire string match. And then uses the second regex to extract the bug id's out of that match in a two step process.

TagsNo tags attached.
Attached Files
checking.php.patch (1,565 bytes)   
--- E:\mantis\mantis_current\core\checkin.php	Wed Aug 09 11:05:19 2006
+++ E:\mantis\mantis_1.0.5\core\checkin.php	Wed Aug 09 11:11:49 2006
@@ -35,33 +35,21 @@
 	# Detect references to issues + concat all lines to have the comment log.
 	$t_commit_regexp = config_get( 'source_control_regexp' );
 	$t_commit_fixed_regexp = config_get( 'source_control_fixed_regexp' );
-	$t_issue_number_regexp = config_get( 'source_countrol_issue_number_regexp' );
 
 	$t_comment = '';
 	$t_issues = array();
 	$t_fixed_issues = array();
 	while ( ( $t_line = fgets( STDIN, 1024 ) ) ) {
 		$t_comment .= $t_line;
-
-		# get the full text of the line with issues in it
 		if ( preg_match_all( $t_commit_regexp, $t_line, $t_matches ) ) {
-			$t_issue_full_text = $t_matches[0][0];
-			# now extract all the issue numbers
-			if ( preg_match_all( $t_issue_number_regexp, $t_issue_full_text, $t_matches ) ) {
 				for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
-					$t_issues[] = $t_matches[0][$i];
-				}
+				$t_issues[] = $t_matches[1][$i];
 			}
 		}
 		
-		# get the full text of the line with fixed issues in it
 		if ( preg_match_all(  $t_commit_fixed_regexp, $t_line, $t_matches ) ) {
-			$t_fixed_issue_full_text = $t_matches[0][0];
-			# now extract all the issue numbers
-			if ( preg_match_all( $t_issue_number_regexp, $t_fixed_issue_full_text, $t_matches ) ) {
 				for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
-					$t_fixed_issues[] = $t_matches[0][$i];
-				}
+				$t_fixed_issues[] = $t_matches[1][$i];
 			}
 		}
 	}
checking.php.patch (1,565 bytes)   
checkin.php.txt (3,692 bytes)   
#!/usr/local/bin/php -q
<?php
	# Mantis - a php based bugtracking system
	# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
	# Copyright (C) 2002 - 2004  Mantis Team   - mantisbt-dev@lists.sourceforge.net
	# This program is distributed under the terms and conditions of the GPL
	# See the README and LICENSE files for details

	# --------------------------------------------------------
	# $Id: checkin.php,v 1.4.12.1 2006/05/28 14:27:15 vboctor Exp $
	# --------------------------------------------------------

	global $g_bypass_headers;
	$g_bypass_headers = 1;
	require_once( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' );

	# Make sure this script doesn't run via the webserver
	# @@@ This is a hack to detect php-cgi, there must be a better way.
	if ( isset( $_SERVER['SERVER_PORT'] ) ) {
		echo "checkin.php is not allowed to run through the webserver.\n";
		exit( 1 );
	}

	# Check that the username is set and exists
	$t_username = config_get( 'source_control_account' );
	if ( is_blank( $t_username ) || ( user_get_id_by_name( $t_username ) === false ) ) {
		echo "Invalid source control account ('$t_username').\n";
		exit( 1 );
	}

	if ( !defined( "STDIN" ) ) {
		define("STDIN", fopen('php://stdin','r'));
	}

	# Detect references to issues + concat all lines to have the comment log.
	$t_commit_regexp = config_get( 'source_control_regexp' );
	$t_commit_fixed_regexp = config_get( 'source_control_fixed_regexp' );
	$t_issue_number_regexp = config_get( 'source_countrol_issue_number_regexp' );

	$t_comment = '';
	$t_issues = array();
	$t_fixed_issues = array();
	while ( ( $t_line = fgets( STDIN, 1024 ) ) ) {
		$t_comment .= $t_line;		
		# get the full text of the line with issues in it		
		if ( preg_match_all( $t_commit_regexp, $t_line, $t_matches ) ) {		
			# now extract all the issue numbers
			$t_issue_full_text = $t_matches[0][0];
			if ( preg_match_all( $t_issue_number_regexp, $t_issue_full_text, $t_matches ) ) {				
				for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
					$t_issues[] = $t_matches[0][$i];
					echo $t_matches[0][$i];
				}
			}
		}
		
		# get the full text of the line with fixed issues in it
		if ( preg_match_all(  $t_commit_fixed_regexp, $t_line, $t_matches ) ) {
			$t_fixed_issue_full_text = $t_matches[0][0];
			# now extract all the issue numbers
			if ( preg_match_all( $t_issue_number_regexp, $t_fixed_issue_full_text, $t_matches ) ) {
				for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
					$t_fixed_issues[] = $t_matches[0][$i];
				}
			}
		}
	}
	
	# If no issues found, then no work to do.
	if ( ( count( $t_issues ) == 0 ) && ( count( $t_fixed_issues ) == 0 ) ) {
		echo "Comment does not reference any issues.\n";
		exit(0);
	}

	# Login as source control user
	if ( !auth_attempt_script_login( $t_username ) ) {
		echo "Unable to login\n";
		exit( 1 );
	}

	# history parameters are reserved for future use.
	$t_history_old_value = '';
	$t_history_new_value = '';

	# add note to each bug only once
	$t_issues = array_unique( $t_issues );
	$t_fixed_issues = array_unique( $t_fixed_issues );

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

	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 ) );
		}
	}

	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 ) );
	}

	exit( 0 );
?>
checkin.php.txt (3,692 bytes)   

Relationships

related to 0011732 closeddhx Remove built-in source code integration support 
related to 0007331 closeddhx Make Source Control Regex's work better with $g_bug_link_tag 

Activities

jba-mono

jba-mono

2006-08-03 23:02

reporter   ~0013187

Last edited: 2006-08-09 20:35

Damn, the string I'm entering is being processed by mantis bug tag matching.

The string I want to match is the following, where i have replaced the hash (pound?) symbol with the dollar sign '$' to get around mantis' auto formatting of issue numbers:

Issues $410, 455, $430, 421

jba-mono

jba-mono

2006-08-08 21:14

reporter   ~0013231

Just going to upload a patch to checking.php to work the way I suggested.

My configuration variables are as such:


$g_source_control_regexp = "/^issues? #?(\d+)(?:,? ?#?(\d+))\b/i";
$g_source_control_fixed_regexp = "/^fixed issues? #?(\d+)(?:,? ?#?(\d+))
\b/i";
$g_source_countrol_issue_number_regexp = "(\d+)";

vboctor

vboctor

2006-09-20 00:06

manager   ~0013415

Can you please upload your modified version of the checkin script. The attachments were lost when the website was migrated.

jba-mono

jba-mono

2006-10-17 02:49

reporter   ~0013621

Uploaded full checkin.php (instead of patch as done previously) as requested by vboctor. Sorry for the delay in getting to this, you almost got lost in my spam folder.

dhx

dhx

2010-03-31 04:18

reporter   ~0024955

Won't fix as this old source code integration support is being dropped in favour of using a more modern plugin approach with the SourceIntegration plugin.

Refer to 0011732 for more details and feedback.