Mantis Logo
Mantis Manual
Manual
Installation

Requirements
Backups
Upgrading
CVS Integration
Uninstall


Partner Links


CVS Integration
Last Modified: August 12, 2005 08:08AM
(Introduced in 0.19.0)
Description

CVS integration allows Mantis to register commits to the CVS source control system into corresponding bug notes in the issue tracker.

The setup requires that the mantis installation be accessible on the computer running the CVS server. A copy of the Mantis config_inc.php file must be present.

Note that the mysql database also needs to be accessible from the cvs machine. That is, "localhost" for $g_hostname won't work unless CVS and Mantis are hosted on the same machine.

To activate the integration, the following line to the cvs "commitinfo" file. (Instructions to edit this file are in any number of CVS primers).

ALL /usr/bin/php /path_to_mantis/core/checkin.php

This will pass the commit message to checkin.php for all commits. If the string
issue #nnnn is found in the commit message, the Mantis corresponding to "nnnn" will have the CVS commit message added as a bug note to the issue. Multiple issues can be listed.

This feature is configured through config_inc.php and through custom functions.



See also: Source Control Integration for configuration, and Custom Functions

User Contributed Notes
CVS Integration
Add Notes About Notes
dmitrys no spam at earthlink d o t net
03-Feb-2005 19:32
#343
that's "note" not "mote". Just wanted to be the first to point this out :)
oleg_skr at hotmail dot com
09-Mar-2005 22:33
#372
I've had a lot of troubles with "CVS Integration".

First of all, I would like to say, that to activate the integration, you have to put the line to the cvs "verifymsg" file, and not "commitinfo".

While "commitinfo" knows only the files, that have been changed, the paths to them, and not the CVS-Annotation.

The line must look like that:
#-------Mantis_integration--------#
DEFAULT /usr/bin/php /path_to_mantis/core/checkin.php
#---------------------------------#

And you have also to change file checkin.php, while the message is not in STDIN transfered, but in first parameter.

You have to change checkin.php thus:

#-------cut----------#

# Detect references to issues + concat all lines to have the comment log.
$t_commit_regexp = config_get( 'source_control_regexp' );
$t_comment = '';
$t_issues = array();
#while ( ( $t_line = fgets( STDIN, 1024 ) ) ) {
$t_line=$argv[1]; # line added
$t_comment .= $t_line;
if ( preg_match_all( $t_commit_regexp, $t_line, $t_matches ) ) {
for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
$t_issues[] = $t_matches[1][$i];
}
}
#}

#-------cut----------#

I've not tested it jet, will do this tomorrow, but it must work.

Have fun!
Oleg.
shawncollins at NOSPAMcableone d0t net
11-Mar-2005 14:09
#374
I made the CVS integration work by taking the instructions from Oleg and making one adjustment to the checkin.php file.

change the line (from Oleg's post):

$t_line=$argv[1]; # line added

to:

$t_line = exec( "cat $argv[1]\n" ); # line added + modified

CVS stashes the comments in a temp file whose location is specified in $argv[1].

A more complete frag is:

#-------cut----------#

# Detect references to issues + concat all lines to have the comment log.
$t_commit_regexp = config_get( 'source_control_regexp' );
$t_comment = '';
$t_issues = array();
#while ( ( $t_line = fgets( STDIN, 1024 ) ) ) {
$t_line=exec( "cat $argv[1]\n" ); # line added + modified
$t_comment .= $t_line;
if ( preg_match_all( $t_commit_regexp, $t_line, $t_matches ) ) {
for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
$t_issues[] = $t_matches[1][$i];
}
}
#}

#-------cut----------#


Oleg -- nice catch on the "verifymsg" issue!
thierry.vermeersch@nl.abb.com
15-Mar-2005 5:34
#381
What should this parameter do?

# --- CVS linking ---------------
# insert the URL to your CVSweb or ViewCVS
# eg: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/mantisbt/mantisbt/
$g_cvs_web = '';

I don't know what to expect. I've set the link, but I cannot see any difference....

Thierry
oleg_skr at hotmail dot com
19-Mar-2005 11:00
#385
The final version of my "checkin.php" file is:

#------------begin-------------------

#!/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.3 2005/03/19 14:02:00 Oleg Skrypnyuk 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(0);
}

$cvs_commit = fopen('PATH_TO_MANTIS/core/verifymsg_cvs.log', 'a+');

$cvs_user = exec("whoami" );

if($cvs_user == "skrypnyo" )
$mantis_user = "Oscar";
else
$mantis_user = $cvs_user;

# Check that the username exists
if (user_get_id_by_name($mantis_user) === false) {
fwrite($cvs_commit, "$mantis_user does not exists\n" );
fclose($cvs_commit);
exit(0);
} else {
# Login as current user
if (!auth_attempt_script_login($mantis_user)) {
fwrite($cvs_commit, "Unable to login $mantis_user\n" );
fclose($cvs_commit);
exit(0);
}
}

# Detect references to issues + concat all lines to have the comment log.
$bug_regexp = "/\bBug {0,1}(\d+)\:/i";
$bug_resolved_regexp = "/\bBug {0,1}(\d+) resolved\:/i";

$bugs_note = array();
$bugs_resolved = array();

$cvs_note_file = fopen($argv[1], "r" );
$cvs_annotation = "";
while (!feof($cvs_note_file)) {
$t_line = fgets($cvs_note_file, 4096);

if ( preg_match_all( $bug_regexp, $t_line, $t_matches ) ) {
for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
$bugs_note[0][] = $t_matches[1][$i]; #issue_id
$bugs_note[1][] = str_replace($t_matches[0][$i], "", $t_line); #issue_note
}
}

if ( preg_match_all( $bug_resolved_regexp, $t_line, $t_matches ) ) {
for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
$bugs_resolved[0][] = $t_matches[1][$i]; #issue_resolved_id
$bugs_resolved[1][] = str_replace($t_matches[0][$i], "", $t_line); #issue_resolved_note
}
}
$cvs_annotation .= $t_line;
}

fclose($cvs_note_file);


# If no issues found, then no work to do.
if ((count($bugs_note) == 0)&&(count($bugs_resolved) == 0)) {
fwrite($cvs_commit, "Comment:\n---\n$cvs_annotation---\n does not reference any issues.\n\n" );
fclose($cvs_commit);
exit(0);
}


# Attempt to find the location of the core files.
$t_core_path = dirname(__FILE__).DIRECTORY_SEPARATOR.'core'.DIRECTORY_SEPARATOR;
if (isset($GLOBALS['g_core_path']) && !isset( $HTTP_GET_VARS['g_core_path'] ) && !isset( $HTTP_POST_VARS['g_core_path'] ) && !isset( $HTTP_COOKIE_VARS['g_core_path'] ) ) {
$t_core_path = $g_core_path;
}

# Load rest of core in seperate directory.
require_once($t_core_path.'bug_api.php');
require_once($t_core_path.'bugnote_api.php');
require_once($t_core_path.'user_api.php');


for ($i=0; $i<count($bugs_note[0]); $i++) {
fwrite($cvs_commit, "$mantis_user, issue ".$bugs_note[0][$i]." note added:".$bugs_note[1][$i]);
if (bug_exists($bugs_note[0][$i])) {
bugnote_add($bugs_note[0][$i], $bugs_note[1][$i], VS_PRIVATE == config_get('source_control_notes_view_status'));
}
}

for ($i=0; $i<count($bugs_resolved[0]); $i++) {
fwrite($cvs_commit, "$mantis_user, issue ".$bugs_resolved[0][$i]." resolved, note added:".$bugs_resolved[1][$i]);
if (bug_exists($bugs_resolved[0][$i])) {
bugnote_add($bugs_resolved[0][$i], $bugs_resolved[1][$i], VS_PRIVATE == config_get('source_control_notes_view_status'));

if (!bug_is_user_handler($bugs_resolved[0][$i], user_get_id_by_name($mantis_user))){
bug_assign($bugs_resolved[0][$i], user_get_id_by_name($mantis_user));
}

bug_set_field($bugs_resolved[0][$i], 'status', RESOLVED);
}
}

fwrite($cvs_commit, "\n" );

fclose($cvs_commit);

exit(0);
?>
#-----------end--------------------

First of all, when I've tried to use "cat $argv[1]", I've got only the last line of CVS-comment back. That's why I use php-way to read the file instead.

Than, I've added a log-file, to monitor the troubles by integration.

Next, I've made it, that notes in mantis will be added not from standard CVS-user, but from that user, that CVS-update does.
Relations between CVS-users and Mantis-users can be made like:

#----cut----
if($cvs_user == "skrypnyo" )
$mantis_user = "Oscar";
else
$mantis_user = $cvs_user;
#----cut----

And the last one, I've added new regexp, to set the status of issue to "resolved", and appropriate to it adjusted the file.


I understand, that my version does not suit the global mantis structure, but I personally have no need to make it uniform.

I hope this post will help somebody.
Oleg.
cp@sandon.it
22-Apr-2005 11:48
#417
Actually one can use the loginfo file (not commitinfo) where the log message is sent via STDIN. The advantage of verifymsg is that a script can abort the commit returning a value different than 0. If the checkin script checks if the issue numbers exist, it could abort the operation if they are not correct. Be aware that the actual implementation of checkin.php will return 1 if its account is not valid or is not able to login thus stopping any attempt to commit in such a situation, but does not check AFAIK the existence of issues.
gepy77@hotmail.com
08-Jun-2005 1:36
#459
I used Wincvs and Mantis.

I tried cvs integration.

but fgets( STDIN , 1024) isn't reutrn any value.

and value of argv[1] is /home/cvs/poject_name.(it's directory name)

plz help for this.

thanks.
mkgnu@gmx.net
27-Jun-2005 13:52
#490
Why aren't you just using

http://freshmeat.net/projects/scmbug ?

Why are we back to square one all of the sudden ?
iva@konin.lm.pl
07-Jul-2005 3:37
#503
Is there a way I could connect Mantis running on Linux and CVSNT server running on Windows?
lem.tomas@gmail.com
27-Jul-2005 9:23
#541
is there plans on integrating with Subversion
victor @ Mantis
27-Jul-2005 9:56
#542
lem.tomas, checkout "Scmbug: Integrates Mantis with several Source Control tools like CVS, Subversion, and Arch."

http://freshmeat.net/projects/scmbug/

-vboctor
ribeiradascabras-spam@yahoo.com
04-Aug-2005 11:54
#554
I started using SCMBUG with Subversion. It works well but the functionality is somewhat limited. It seems we can only add notes to bugs through svn commit messages. I would like also to resolve/fix bugs using the same process but that does not seem to be possible. Is this correct or am I missing something?

Luis

P.S. the email is not optional after all in this submission tool...
krishanr@damcogroup.com
05-Oct-2005 9:43
#633
I have added the line DEFAULT /usr/bin/php -v #-f /usr/local/apache2/htdocs/mantis/core/checkin.php
in the loginfo file. But when i tried to commit through a remote machine on which wincvs was installed on windows plateform to a remote unix machine on which cvs repository and mantis were installed.
i am getting the following error PHP Warning: Unknown(): Unable to load dynamic library '/usr/lib/php4/mysql.so' - /usr/lib/php4/mysql.so: undefined symbol: Perl_Iperl_destruct_level_ptr in Unknown on line 0
PHP Warning: Unknown(): Unable to load dynamic library '/usr/lib/php4/mysql.so' - /usr/lib/php4/mysql.so: undefined symbol: Perl_Iperl_destruct_level_ptr in Unknown on line 0
<br />
<b>Fatal error</b>: Call to undefined function: mysql_connect() in <b>/usr/local/apache2/htdocs/mantis/core/adodb/drivers/adodb-mysql.inc.php</b> on line <b>339</b><br />

can any body help me.
thanks
cp@sandon.it
16-Dec-2005 8:47
#774
I found out that CVSNT implements loginfo in two ways: it is possibile to select via format strings on the script line what data to pass, and stdin will contain anyway the "old" CVS data.
Therefore parameters passed to the script may vary.
mantis@erkens.info
20-Dec-2005 7:30
#776
In #541 lem.tomas asks if subversion support will be added.
I have just done this my self by making a simpel "hook" script called "post-commit" in the repository hooks directory using the svnlook tool.
I don't use CVS, so I don't know how it's done there, but this works for me.


#!/bin/bash
REPOS=$1
REV=$2
/usr/bin/svnlook log $REPOS -r $REV | /usr/bin/php -q /path/to/mantis/core/checkin.php
mantis@erkens.info
20-Dec-2005 7:35
#778
I'm sorry about the double post, but the submit script here is broken, I got an error about mail problems and I thougt that it was because of the .info in my address.
xeber@webalianza.com
29-Dec-2005 7:53
#791
I can not insert the commit comment as issue note.

This is the comment:
 issue #2
...........
........
....

This is the error:
Comment does not reference any issues.

Can someone help me?
cp@sandon.it
04-Feb-2006 11:40
#865
With CVSNT 2.5.0.2 I did:

1) In loginfo I added this line
ALL C:/PHP/PHP.EXE "D:/webroot/mantis/core/checkin.php" %m %s

%m is the log message, %s module and files. Other variables can be used, see the documentation.

2) I modified checkin.php to not use data passed in STDIN, which is the "old" CVS way to pass data, some of them are not useful:

- Commented out code using STDIN
- Added the line to retrieve message and changed files

$t_comment = $_SERVER['argv'][1] . ' Module: ' . $_SERVER['argv'][2];

This line has to be customized if other CVSNT vars are used.

- Applied the regexpr to $t_comment

if ( preg_match_all( $t_commit_regexp, $t_comment, $t_matches ) ) {
  for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
    $t_issues[] = $t_matches[1][$i];
  }
}

if ( preg_match_all( $t_commit_fixed_regexp, $t_comment, $t_matches) ) {
  for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
    $t_fixed_issues[] = $t_matches[1][$i];
  }
}

BTW applying the regexpr on the read buffer ($t_line) is IMHO a bug, because if the string to match is split across two different reads it won't be matched.
CVSNT has now Bug IDs too (%b variable), this could allow for a tighter integration.
Don't know it this would work with CVS
mbond@astrum.com.au
28-May-2006 10:55
#1093
Ive got this working, however it seems to have killed my commit emails. this is the content of my loginfo file

ALL c:/PHP/php-cgi.exe "D:/mantis-1.0.3/core/checkin.php" %m %s
DEFAULT C:/Programs/CVSMailer/CVSMailer.exe -l$CVSPID "$USER" $CVSROOT %{sVv}

so the first line is for Mantis integration, and the second line is for CVSMailer. CVSMailer was working fine until I added Mantis, now Mantis is working and CVSMailer is not.

also - I get 9 notes added to the bug for a single checkin which is kind of strange... has anyone seen this?
cp@sandon.it
16-Oct-2006 8:51
#1273
Maybe the DEFAULT rule is not trigger because the ALL rule. CVS docs says DEFAULT should match even if ALL is used, but maybe your version doesn't. Try to change it to an ALL rule too.
Add Notes About Notes
Last updated: Sat, 17 May 2008 - 5:16:35

Mantis @ SourceForge