当前位置: 首页 > 工具软件 > CodeStriker > 使用案例 >

svn-bugzilla-codestriker安装与配置

佘俊茂
2023-12-01

安装环境

cm@cm:~$ cat /etc/issue

Ubuntu 15.10 \n \l

本机地址:192.168.1.140
svn dir: /home/svn/codes
svnroot:  svn://192.168.1.140/codes  

bugzilla版本:    4.4.12

codestriker版本: 1.9.10

SVN安装配置

安装subversion,创建myrepo代码库:

apt-get install subversion

mkdir -p /home/svn/codes
chmod -R 777 /home/svn/codes
svnadmin create /home/svn/codes/myrepo

编辑svnserve.conf配置文件,关闭匿名访问;打开密码验证和权限控制:

/home/svn/codes/conf/svnserve.conf
anon-access = none
password-db = passwd
authz-db = authz

编辑passwd文件,添加用户user1,密码123456(svn用户的用户名需和之后注册bugzilla的邮箱用户名相同,bugzilla会使用此用户名匹配邮件地址):

/home/svn/codes/conf/passwd

[users]
user1 = 123456

编辑authz文件,设置user1对svn库myrepo具有读写权限,其它用户无任何权限:

/home/svn/codes/conf/authz
 
[/myrepo]
user1 = rw
* =

Bugzilla安装配置

安装bugzilla依赖包:

apt-get install mysql-client
apt-get install mysql-server
apt-get install libgd-dev
apt-get install apache2

创建mysql用户,用户名bugs,密码123456。创建bugzilla所使用数据库bugs:

mysql> CREATE USER 'bugs'@'localhost' IDENTIFIED BY '123456';
mysql> GRANT ALL ON *.* TO 'bugs'@localhost;
mysql> flush privileges;
mysql> CREATE DATABASE bugs

解压bugzilla到目录/var/www/html,配置apache2,添加bugzilla访问url:

cd /etc/apache2/mods-enabled/
ln -s ../mods-available/expires.load expires.load
ln -s ../mods-available/headers.load headers.load
ln -s ../mods-available/perl.load perl.load
ln -s ../mods-available/cgi.load cgi.load


vi /etc/apache2/apache2.conf

<Directory "/var/www/html/bugzilla/">
        AddHandler cgi-script .cgi 
        Options +Indexes +ExecCGI +FollowSymLinks
        DirectoryIndex index.cgi
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

/etc/init.d/apache2 restart

编辑bugzilla的配置文件localconfig,添加之前创建的数据库参数:

/var/www/html/bugzilla/localconfig

$db_driver = 'mysql';
$db_host = 'localhost';
$db_name = 'bugs';
$db_user = 'bugs';
$db_pass = '123456';

运行bugzilla安装程序/var/www/html/bugzilla/checksetup.pl 按照提示创建bugzilla管理账号。打开浏览器,访问bugzilla主页, http://192.168.1.140/bugzilla,进入Administer -> parameters配置邮件系统:

mail_delivery_method: SMTP
mailfrom:      xxxxxxxxx@qq.com
smtpserver:    smtp.exmail.qq.com:465  //QQ邮箱端口号为465
smtp_username: xxxxxxxxx@qq.com
smtp_password: ******
smtp_ssl:      on

Codestriker安装配置

安装依赖包:

perl -MCPAN -e 'install "Template"'

创建mysql数据库codestrikerdb,创建用户codestriker,密码cspasswd:

mysql -u root -p
          
CREATE DATABASE codestrikerdb CHARACTER SET utf8;

GRANT SELECT,INSERT,UPDATE,DELETE,INDEX,ALTER,CREATE,DROP,REFERENCES
 ON codestrikerdb.* TO codestriker@localhost IDENTIFIED BY 'cspasswd';

FLUSH PRIVILEGES;

QUIT

解压codestriker到目录/var/www/html,执行安装脚本bin/install.pl,编辑配置文件codestriker.conf:

$dbuser = 'codestriker';
$dbpasswd = 'cspasswd';

$daemon_email_address = 'xxxxxxxxx@qq.com';
$mailhost = 'smtp.exmail.qq.com';
$mailuser = 'xxxxxxxxx@qq.com';
$mailpasswd = '******

@valid_repositories =
    (
     'svn://192.168.1.140/codes',
	);
	
$repository_name_map =
{
    '/home/svn/codes/myrepo/trunk' => 'myrepo',
};

$bug_db = 'bugzilla';
$bug_db_host = 'localhost';
$bug_db_name = 'bugs';
$bug_db_password = '123456';
$bug_db_dbname = 'bugs';
$bug_db_user_id = '2';

$bugtracker = 'http://192.168.1.140/bugzilla/show_bug.cgi?id=';

修改bin/subversion-post-commit.pl文件:

my $CODESTRIKER_URL = 'http://192.168.1.140/codestriker/codestriker.pl';
my $CODESTRIKER_PROJECT = 'myrepo';
my $CODESTRIKER_REPOSITORY = 'svn://192.168.1.140/codes/myrepo/trunk';
my $CODESTRIKER_REVIEWERS = 'manager@qq.com';
my $email_domain = 'qq.com';

没有找到在哪里配置codestriker所使用邮箱服务器的端口号,手动修改为qq邮箱的SMTP服务端口465:

vi codestriker/lib/Codestriker.pm
sub send_email {
    my ($type, %args) = @_;

#    my $smtp = Net::SMTP->new($Codestriker::mailhost);
    my $smtp = Net::SMTP->new($Codestriker::mailhost, PeerPort => 465);   //465为qq邮箱的SMTP端口号。

修改apache2配置文件,添加codestriker的url:

vi /etc/apache2/apache2.conf

ScriptAlias /codestriker/  /var/www/html/codestriker/cgi-bin/
Alias /codestrikerhtml/  /var/www/html/codestriker/html/

<Directory "/var/www/html/codestriker/cgi-bin/">
   AllowOverride None
   Options ExecCGI
   Order allow,deny
   Allow from all
   SetHandler cgi-script
</Directory>

重启apache2:

/etc/init.d/apache2 restart

http://192.168.1.140/codestriker/codestriker.pl

三者关联

通过svn的hook进行关联,/home/svn/codes/hooks,首先编辑目录下pre-commit文件,判断svn commit时comment内容是否有bug id,无bug号不允许提交。例如:svn commit program.c -m "bug 3":

#!/bin/bash

REPOS=$1
TXN=$2

SVNLOOK=/usr/bin/svnlook

BUGKEY="bug"
COMMENT=`$SVNLOOK log -t "$TXN" "$REPOS"`

BUGID=${COMMENT#*$BUGKEY}

BID=`echo $BUGID | awk -F"[^0-9]" '{print $1}'`
if [ "$BID" != "" ]
then
    echo "ok"
else
    echo "no bug id found"
    exit 1
fi

exit 0

其次,编辑post-commit文件,调用codestriker接口:

#!/bin/sh

REPOS="$1"
TXN="$2"

SVNLOOK=/usr/bin/svnlook

/var/www/html/codestriker/bin/subversion-post-commit.pl $REPOS $TXN

exit 0

subversion-post-commit.pl实现新建codestricker的topic,添加bugzilla的comment并发送提交通知邮件功能。


 类似资料: