转自http://www.ichiayi.com/wikipage/tech/svnmantis
当 Mantis 有张贴一个新的 Issue 时, 与这个 Issue 相关的 Subversion 更动纪录可以自动回写至 Mantis 这个 Issue 内的 Bug 笔记内.
vi /var/www/html/mantis/config_inc.php
:
:
#Source Control
$g_source_control_account = 'svnbot';
$g_source_control_regexp = '//b(?:bug|issue|mantis)/s*[#]{0,1}(/d+)/b/i';
$g_source_control_set_status_to = RESOLVED;
$g_source_control_set_resolution_to = FIXED;
$g_source_control_fixed_regexp = '//bfix(?:ed|es)/s+(?:bug|issue|mantis)?/s*[#]{0,1}(/d+)/b/i';
:
直接执行以下的命令, 可以在 mantis 内的 Issue#2 新增 Bug 笔记
php /var/www/html/mantis/core/checkin.php <<< "Test issue #2 by svnbot."
直接执行以下的命令, 可以在 mantis 内的 Issue#2 新增 Bug 笔记以及将问题状态更改为以解决
php /var/www/html/mantis/core/checkin.php <<< "Test fixed issue #2 by svnbot."
vi /var/www/svn2mantis.pl
#!/usr/bin/perl
#
# 上午 11:15 2007 年6 月22 日
# Jonathan Tsai
# Ver 1.10
#
# 自动将 svn 讯息写入 mantis 纪录内
#
# 参考 http://www.ichiayi.com/trywiki/tech/svnmantis 的说明方式
# 本 script 需配合:
# 1. /var/www/svn/xxxrepos/hooks/post-commit 一起使用
# 2.apache user 可使用 ssh 免密码登入 Mantis 主机 <- SVN 主机与 Mantis 主机不同时需要
#
# 1.00 ( 2007/3/26 ) 第一版启用
# 1.01 ( 2007/3/26 ) 增加 commit 后自动整合的说明
# 1.10 ( 2007/6/22 ) 增加 远程登入 Mantis 主机功能设定
#
$prgname = substr($0, rindex($0,"/")+1);
$ver = "1.10 ( 2007/6/22 )";
# $sshcmd 设为空字符串表示 SVN 与 Mantis 安装在相同主机
$sshcmd = "";
# 否则应该输入由 svn 主机免密码登入 Mantis 主机的命令列
#$sshcmd = "/usr/bin/ssh jonathan@ 10.10.10 .96";
# 读取参数数据
$REPOS=$ARGV[0];
$REV=$ARGV[1];
# 定义外部指令
$svnlook = "export LANG=zh_TW.UTF-8;/usr/bin/svnlook";
$phpcmd = "/usr/bin/php";
$checkincmd = "/var/www/html/mantis/core/checkin.php";
# 取得 svn 相关信息
$auth=`$svnlook author -r $REV $REPOS`;
$dt=`$svnlook date -r $REV $REPOS`;
$changed=`$svnlook changed -r $REV $REPOS`;
$log=`$svnlook log -r $REV $REPOS`;
$msg="Changeset [".$REV."] by $auth/n$dt/n$log/n$changed";
# 传送至 mantis
if (length($sshcmd)>0) {
`$sshcmd $phpcmd -q $checkincmd <<< "$msg"`;
}
else {
`$phpcmd -q $checkincmd <<< "$msg"`;
}
chmod a+x /var/www/svn2mantis.pl
/var/www/svn2mantis.pl /var/www/svn/servercfg 644
Changeset [644] by jonathan
2007-03-26 11:29:55 +0800 (一, 26 3月 2007)
将 svnlook 命令前加入 LANG=zh_TW.UTF-8 来测试整合 mantis 中文讯息问题.
mantis#2
U PD-920/var/www/svn2mantis.pl
如果有多个 svn repos 就在每个 repos 内依照这步骤一一执行, 以下还是以 servercfg 的 svn repos 为例
cd /var/www/svn/servercfg
cd hooks
vi post-commit
#!/bin/sh
REPOS="$1"
REV="$2"
/var/www/svn2mantis.pl "$REPOS" "$REV"
chown apache:apache post-commit
chmod a+x post-commit
这样一但 commit 后, 会马上执行这个 post-commit 的 shell script, 来执行 svn2mantis.pl 将 SVN 内的纪录内容整合到 Mantis 的 Issue Bug 笔记内.
su - jonathan
ssh 10.10.10 .96 <- 输入密码确认可以登入
exit <- 回到 svn 主机
cd .ssh
ssh-keygen -d <- 产生 id_dsa.pub (询问时均 Enter 跳下不输入任何字符)
scp id_dsa.pub 10.10.10 .96:/home/jonathan/.ssh/10.10.10.91_authorized_keys2
su - jonathan
cd .ssh
cat 10.10.10 .91_authorized_keys2 >> authorized_keys2
chmod 600 authorized_keys2
[jonathan@eddev ~]$ ssh jonathan@ 10.10.10 .96
Last login: Fri Jun 22 10:14:40 2007 from 10.10.10 .91
[jonathan@tryboxap04 ~]$
su -
cd /var/www
cp -a ~jonathan/.ssh .
chown -R apache:apache .ssh
vi /var/www/svn2mantis.pl
#!/usr/bin/perl
#
# 上午 11:15 2007 年6 月22 日
# Jonathan Tsai
# Ver 1.10
#
# 自动将 svn 讯息写入 mantis 纪录内
#
# 参考 http://www.ichiayi.com/trywiki/tech/svnmantis 的说明方式
# 本 script 需配合:
# 1. /var/www/svn/xxxrepos/hooks/post-commit 一起使用
# 2.apache user 可使用 ssh 免密码登入 Mantis 主机 <- SVN 主机与 Mantis 主机不同时需要
#
# 1.00 ( 2007/3/26 ) 第一版启用
# 1.01 ( 2007/3/26 ) 增加 commit 后自动整合的说明
# 1.10 ( 2007/6/22 ) 增加 远程登入 Mantis 主机功能设定
#
$prgname = substr($0, rindex($0,"/")+1);
$ver = "1.10 ( 2007/6/22 )";
# $sshcmd 设为空字符串表示 SVN 与 Mantis 安装在相同主机
#$sshcmd = "";
# 否则应该输入由 svn 主机免密码登入 Mantis 主机的命令列
$sshcmd = "/usr/bin/ssh jonathan@ 10.10.10 .96";
# 读取参数数据
$REPOS=$ARGV[0];
$REV=$ARGV[1];
# 定义外部指令
$svnlook = "export LANG=zh_TW.UTF-8;/usr/bin/svnlook";
$phpcmd = "/usr/bin/php";
$checkincmd = "/var/www/html/mantis/core/checkin.php";
# 取得 svn 相关信息
$auth=`$svnlook author -r $REV $REPOS`;
$dt=`$svnlook date -r $REV $REPOS`;
$changed=`$svnlook changed -r $REV $REPOS`;
$log=`$svnlook log -r $REV $REPOS`;
$msg="Changeset [".$REV."] by $auth/n$dt/n$log/n$changed";
# 传送至 mantis
if (length($sshcmd)>0) {
`$sshcmd $phpcmd -q $checkincmd <<< "$msg"`;
}
else {
`$phpcmd -q $checkincmd <<< "$msg"`;
}
chmod a+x /var/www/svn2mantis.pl
/var/www/svn2mantis.pl /var/www/svn/moeaprj 1700
Changeset [1700] by chou
2007-06-20 12:09:04 +0800 (三, 20 6月 2007)
更改发文查询的本文含附件打印 mantis#516
U EDOC2/Source/docsrv_html/inc/templates/edrecvquery_2.inc.htm
如果有多个 svn repos 就在每个 repos 内依照这步骤一一执行, 以下还是以 moeaprj 的 svn repos 为例
cd /var/www/svn/moeaprj
cd hooks
vi post-commit
#!/bin/sh
REPOS="$1"
REV="$2"
/var/www/svn2mantis.pl "$REPOS" "$REV"
chown apache:apache post-commit
chmod a+x post-commit
这样一但 commit 后, 会马上执行这个 post-commit 的 shell script, 来执行 svn2mantis.pl 将 SVN 内的纪录内容整合到 Mantis 的 Issue Bug 笔记内.