Integration of subversion and mantis

Source: Internet
Author: User
Tags bug tracking system

Http://kheresy.wordpress.com/2007/02/06/subversion-%E5%92%8C-mantis-%E7%9A%84%E6%95%B4%E5%90%88/

 

    • Subversion:Http://subversion.tigris.org/
    • Mantis:Http://www.mantisbt.org/

First, subversion (SVN) is a version control system that can be used to manage program versions. Mantis is a bug tracking system, it is used for tracking and managing program bugs. To integrate version control and problem tracking, We can automatically integrate the related information into the bug tracking system when updating the program.

To integrate the two, we need to understand that subversion has a function called "hooks. Through this function, you can write some scripts or even programs on your own, so that the subversion can automatically perform the specified action when the event is triggered. There are nine types of events:

    • Pre-commit: the row is committed before commit.
    • Pre-lock: the row is aborted before the future determination.
    • Pre-revprop-change: the cursor is added, modified, or deleted before it is deleted.
    • Pre-Unlock
    • Post-commit: The committed row after commit
    • Post-Lock
    • Post-revprop-change
    • Post-Unlock

According to Yu, you can take the exam:[SVN] How to Use hook scripts.

Heresy allows the script to upload rows during post-commit. The reason for doing so is mainly because in subversion, the information (Response case, solution, etc.) obtained at the time of commit seems to have to be completed after the commit, through the svnlook command.

First, let's explain that heresy's environment is on Linux, so the subsequent statements are based on Linux. The main changes are divided into two parts:

    1. Post-commit
    2. Mantis checkin. php Modification

Post-commit

Please refer to post-commit's zookeeper first ~ The method is to create a response line named "post-commit" under the svnroot/hooks/object, SVN will automatically commit the case after the commit.

While SVN will give this program two metric data, the first ($1Is repository. It should be the location of SVN ~ Second ($2) Is revision, that is, version. The svnlook program can obtain most of the data through these two records. The content of the Post-commit case in which heresy uploads is as follows:

 
#! /Bin/shphp =/usr/bin/phpscriptf = /... /svn2mantis. phpmantis = /... /mantisbt/CORE/checkin_svn.php $ PHP $ scriptf $1 $2 | $ PHP $ mantis

The second row to the fourth row is the path of the specific case.

    • $ PHP changes indicate the location of the PHP login row.
    • $ Scriptf is a PHP script of heresy's external website. It mainly aims to sort out the information obtained by svnlook. At the same time, the Chinese characters returned by svnlook are returned in the form of tokens. Therefore, you must handle them first before sending them to Mantis.
    • $ Mantis is the interface provided by Mantis. The signature name should be called checkin. php. However, heresy has never been able to understand how to use the dynamic data. Therefore, heresy modified the original version based on the original version. However, the content of this case is further mentioned in the second part.

In fact, there is only one row left on the rows.$ PHP $ scriptf $1 $2 | $ PHP $ mantisNow ~ In practice, the rows are written first.PHP svn2mantis. phpRepository RevisionAnd then output the result to stdout, pipe$ PHP $ mantis, That isPHP checkin_svn.phpIt is his stdin.

Therefore, the more important part should be the content of svn2mantis. php, and something else! Here is his content:

<? $ Repos = $ argv [1]; $ REV = $ argv [2]; $ rs = shell_exec ("svnlook Info-r $ rev $ repos "); $ PAT = explode ("N", $ RS, 4); $ author = $ Pat [0]; $ comment = $ Pat [3]; if ($ RSA = explode ("? \ ", $ Comment) {$ comment =" "; foreach ($ RSA as $ Val) {If (ereg (" (^ [0-9] {3 }) (. *) ", $ Val, $ p) $ comment. = CHR ($ P [1]). $ P [2]; else $ comment. = $ Val ;}$ Ra = shell_exec ("svnlook changed-r $ rev $ repos"); echo "$ authorn $ commentn --- n <B> modified files: </B> N $ Ra "?>

This program requires two records: repository and revision.$ Rs = shell_exec ("svnlook Info-r $ rev $ repos ");Start; PHP will continueSvnlook Info-r $ rev $ ReposTo obtain the information in the svn record. The format is roughly as follows:

 
Author2007-02-05 09:14:58 + 0800 (Mon, 05 Feb 2007) 85 Issue #1? 228? 184? 173? 230? 150? 135? 231? 154? 132? 230? 184? 172? 232? 169? 166

The first line is the modifier, the second line is the time, and the third line is the data word heresy, is the partial solution of the commit statement at the time of commit. Some modifications have been made to checkin_svn.php. Therefore, the first line must be changed by name, zookeeper must be the same as mantis ). However, the date of the second row and the unknown digit of the third row do not need to be added to mantis's bug memory in practice. Therefore, heresy decided to drop them. That is, through$ PAT = explode ("N", $ RS, 4 );This command splits the $ Rs root operator into four parts. In this way, the first part is the modifier worker ($ Author = $ Pat [0];), The second part is the time, the third part is the unknown bit, and the fourth part is the solution ($ Comment = $ Pat [3];).

However, you can see some 「? /### "In the form of information, in fact, these are the results of the text written by SVN into the UTF-8 word inventory; if you want to write into mantis, you also need to re-organize it to display it. Heresy's practice here is root cause 「?」 To cut the string ($ RSA = explode ("? \ ", $ Comment)); Then, check in sequence whether the beginning of each string is three numbers.CHR ()If this function is not used, it will be replaced directly. In this way, you can refer these words back to the Chinese text ~

And coming$ Ra = shell_exec ("svnlook changed-r $ rev $ repos ");In this case, call svnlook again to obtain more dynamic case information and attach it to Mantis. That is, the final output format:"$ Authorn $ commentn-n <B> modified files: </B> N $ Ra". In the above example, the final result is:

 
Authorissue #1 Chinese Character --- <B> modified files: </B> U A. cpp

The reason for his echo is that mantis's checkin. php is used to retrieve the information from stdin ~ Therefore, this program only needs to send all the information to mantis out of stdout with Echo.

 

 

Checkin_svn.php

As mentioned above, heresy cannot determine the number of checkin. php instances from Mantis. Therefore, it is decided to change checkin. php to checkin_svn.php. The main modification is the method of getting zookeeper.

First of all, the methods for obtaining and verifying the signature in checkin. php are as follows:

# 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) = $ echo "Invalid Source Control Account ('$ t_username '). N "; exit (1 );}

However, due to heresy's acquisition method, You have to mark this part (Add "#" to the Front ). The modified method is the same as the escape method, which is obtained by stdin. Heresy's approach is to take stdin into the first line as the initial line, that is, in the originalWhile ($ t_line = fgets (stdin, 1024 )))Add the following program:

 
# Check that the username is set and exists $ t_username = trim (fgets (stdin, 1024); If (is_blank ($ t_username) | (user_get_id_by_name ($ t_username) ==$ echo "Invalid Source Control Account ('$ t_username '). N "; exit (1 );}

In fact$ T_username = config_get ('source _ control_account ');Change$ T_username = trim (fgets (stdin, 1024 ));However, the original program location may not define stdin, so heresy pulled it only when it was enabled.While ($ t_line = fgets (stdin, 1024 ))).

 

After the above three cases have been modified and modified, as long as they are placed in the correct position, they should be able to operate normally ~ Post-commit must be placed under svnroot/hooks/, but svn2mantis. php is not limited, but it may be easier to put together. Checkin_svn.php should be placed in mantisbt's core category, which is in the same position as the original checkin. php (you can also directly modify checkin. php ).

In practice, when using a commit program, you must manually initiate an issue authentication response to Mantis (in the form of "Issue #1 」); in this way, the program will automatically append this resolution to the bug reporter in mantis issue #1 ~

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.