对于Bugfree和SVN整合,我搞了一周终于搞好了,勉强可以使用,并且整合成功。唯一Bug,就是文件信息比较多是在Bugfree中不信息显示不是很好。如附件图片
1、环境的搭架,具体搭建,请见bugfree官方网站的Bugfree和Svn整合
我用的环境是,Bugfree2.0.3 SVN1.4.6 php5
2、代码修复说明
post-commit.bat代码
@echo off
setlocal enabledelayedexpansion /*可使用延迟变量,我是网上找的具体我也不是非常明白*/
set REPOS=%1
set REV=%2
set PHP_EXE=C:\"Program Files"\PHP\php.exe
/* 注意:这里如果你的路径名中有空格一定用双引号引起,不然会找不到对应路径*/
set CHECK_IN_PHP=C:\svn_ci.php
set SVN_LOOK_EXE=C:\"Program Files"\Subversion\bin\svnlook.exe
for /f "delims=" %%a in ('%SVN_LOOK_EXE% author -r %REV% %REPOS%') do set AUTHOR=%%a
for /f "delims=" %%a in ('%SVN_LOOK_EXE% date -r %REV% %REPOS%') do set DATE=%%a
for /f "delims=" %%a in ('%SVN_LOOK_EXE% changed -r %REV% %REPOS%') do (
set CHANGED=!CHANGED! %%a /* 将所有的文件更新数据连接*/
echo changed = !CHANGED!
)
/* */
for /f "delims=" %%a in ('%SVN_LOOK_EXE% log -r %REV% %REPOS%') do set LOG=%%a
for /f "delims=" %%a in ('%PHP_EXE% -r "echo chr(0x04);"') do set N=%%a
echo repos = %REPOS%
echo rev = %REV%
echo changed = %CHANGED%
echo LOG = %LOG%
%PHP_EXE% %CHECK_IN_PHP% "Changeset [%REV%] by %AUTHOR%, %DATE%%N%%LOG%%N%%REV%%N%%CHANGED%"
endlocal
这个文件跟Bugfree官方网上的基本上一样,只有部分进行修改,修改地方我都进行了说明。
3、SVN_ci.php文件,代码说明,这个文件中的内容我主是通过Bugfree中api-example.php文件来修改的。我发现官网的下载文件内容基本一样。大家直接用官网上文件进行修改也是一样的。
注意:1、可以先通过PHP.exe来调试成功svn_ci.php (如PHP.exe c:\svn_ci.php "123123123 fix bug #3")
2、最好是Class.http.php和svn_ci.php放在同一个目录下。
SVN_ci.php代码:
<?php
/**
* BugFree api 使用样例文件
*/
@header("Content-Type: text/html; charset=gbk");
error_reporting(E_ALL^E_NOTICE);
// 类文件可以从此链接获得:http://www.phpfour.com/blog/downloads/http-class
include('class.http.php');
define('API_NEWLINE', chr(0x03)); // 定义值参考Include/Api.inc.php
define('API_DEVIDER', chr(0x04)); // 定义值参考Include/Api.inc.php
define('API_KEY', 'YOUR_KEY'); // 定义值参考Include/Api.inc.php
define('USER_NAME', 'admin'); // 用户名
define('USER_PASSWORD', 'e10adc3949ba59abbe56e057f20f883e'); // 数据库中存储的密码,一般为md5(原始密码)
define('API', "http://192.168.23.97:8989/bugfree/api.php"); // api地址
print_r($argv);
// 解析api产生的结果
function parse($result)
{
$apiInfo = array();
$message = explode(API_NEWLINE, $result);
if(count($message) == 1) return $message;
$keyArray = explode(API_DEVIDER, $message[1]);
$valueArray = explode(API_DEVIDER, $message[2]);
foreach($keyArray as $key => $keyName)
{
$apiInfo[$keyName] = $valueArray[$key];
}
return $apiInfo;
}
// 加密函数
function encrypt($UserName, $UserPassword, $ApiKey, $Rand)
{
return md5(md5($UserName . $UserPassword) . $ApiKey . $Rand);
}
$fixMessageList = explode(API_DEVIDER, $argv[1]);
print_r($fixMessageList);
// get bug IDs
$fixRegx = '/\s*fix\s*bug\s+(#(\d+)( |,)*)+/i';
preg_match_all($fixRegx, $fixMessageList[1], $regs);
$fixRegx = '/#(\d+)+/i';
preg_match_all($fixRegx, $regs[0][0], $regs);
$BugIdList = array();
if(is_array($regs[1]))
{
$BugIdList = $regs[1];
}
$BugIdList = array_unique($BugIdList);
if(count($BugIdList) <= 0) exit;
// create replynote
$note = '';
$note = $fixMessageList[0] . "\n\n";
$fileList = explode("\n", $fixMessageList[3]);
$rev = $fixMessageList[2];
$pre = $rev - 1;
foreach($fileList as $file)
{
preg_match_all('/(\w)(\s+)(.*)/', $file, $regs);
$action = trim($regs[1][0]);
$fileName = trim($regs[3][0]);
if($fileName == '') continue;
$note .= $file;
// u can change this url's link
$note .= ' [url=' . VIEWVC . $fileName . '?r1='. $pre . '&sortdir=down&r2=' . $rev . '&sortby=log][diff][/url]';
$note .= "\n";
}
// 获得会话
$http = new Http();
$http->addParam('mode' , 'getsid');
//$http->addParam('charset' , 'GBK');
$http->execute(API);
$apiInfo = parse($http->result);
$apiInfo = parse($http->result);
print_r($apiInfo);
// 获得sessionname和sessionid,用于保持后面的对话
$sessionname = $apiInfo['sessionname'];
$sessionid = $apiInfo['sessionid'];
// 使用刚刚获得的会话id进行登录
$http = new Http();
$http->addParam('mode' , 'login');
$http->addParam('charset' , 'GBK');
$http->addParam('username' , USER_NAME);
$http->addParam('auth' , encrypt(USER_NAME, USER_PASSWORD, API_KEY, $apiInfo['rand']));
$http->addParam($sessionname , $sessionid);
$http->execute(API);
$apiInfo = parse($http->result);
print_r($apiInfo);
// 编辑Bug
//$BugID = 2;
foreach($BugIdList as $BugID)//遍历所有BugID
{
$http = new Http();
//$http->addParam('charset' , 'GBK');
$http->addParam('mode' , 'updatebug');
//$http->addParam('BugID' , 3);
$http->addParam('BugID' , $BugID);
$http->addParam('ReplyNote' , $note);
//$http->addParam('ReplyNote' , $note);
$http->addParam($sessionname , $sessionid);
$http->execute(API);
$apiInfo = parse($http->result);
print_r($apiInfo);
}
/*
$http = new Http();
$http->addParam('charset' , 'GBK');
$http->addParam('mode' , 'updatebug');
$http->addParam('BugID' , 3);
//$http->addParam('BugID' , $BugID);
$http->addParam('ReplyNote' , $argv[1]);
//$http->addParam('ReplyNote' , $note);
$http->addParam($sessionname , $sessionid);
$http->execute(API);
*/
?>
4、调试Bat文件,(可以将post-commit.bat复制到C盘下,将代码库中hooks目录下的,post-commit.bat修改如下:)
@echo off
setlocal
c:/post-commit.bat %1 %2 > c:/test.log /*执行C盘下的post-commit.bat,将输入结果存放在c:/test.log文件中*/
endlocal
5、手动运用 C:\Program Files\Subversion\bin\svnlook.exe 进行一些调试用。网上有更加详细说明。
附件中有修改后效果图和修改后文件