1

我需要一些帮助来启动 bugzilla 扩展。

我想加入bug_format_comment(FWIW:更改一些在我提交给 SVN 时自动添加为注释的纯文本以链接到相应的 SCM 提交。)

现在,当我手动向错误添加评论时,似乎什么都没有发生。

除了将它放在 /extensions/my-ext-name/ 目录中之外,我还需要做些什么来使扩展运行?我如何测试扩展是否被调用?

我使用旧版本的 Bugzilla (3.2.x)。甚至支持那个钩子吗?(我在文档中找不到该信息)。

这是我的完整Extension.pm文件(我没有 Perl 经验。我从示例扩展中获取了钩子的示例并从那里运行)

package Bugzilla::Extension::Websvn-scmbug-autolink;
use strict;
use base qw(Bugzilla::Extension);
# This code for this is in ./extensions/Websvn-scmbug-autolink/lib/Util.pm
use Bugzilla::Extension::Websvn-scmbug-autolink::Util;
use URI::Escape;

our $VERSION = '0.01';

# See the documentation of Bugzilla::Hook ("perldoc Bugzilla::Hook" 
# in the bugzilla directory) for a list of all available hooks.
sub install_update_db {
    my ($self, $args) = @_;

}

sub bug_format_comment {
    my ($self, $args) = @_;


    my $regexes = $args->{'regexes'};
    # push(@$regexes, { match => qr/\bfoo\b/, replace => 'bar' });


# 6665 --> 6666
# CTUFramework:trunk/CTUCsharpRuntime/CtuFramework/text1-renamed.txt
    #my $bar_match = qr/\b(bar)\b/;
    my $bar_match = qr/(?:^|\r|\n)(\d+|NONE) (-->) (\d+|NONE)[ \r\n\t]+([^:]+):(.*?)[\r\n]/s; #/s - treat as single line
    push(@$regexes, { match => $bar_match, replace => \&_replace_bar });
    my $scm_match2 = qr/(?:^|\r|\n)(\d+|NONE) (-->) (\d+|NONE)[ \r\n\t]+([^:]+):(.*?)[\r\n]/s; #/s - treat as single line
    push(@$regexes, { match => $scm_match2, replace => \&_replace_bar });
}

# Used by bug_format_comment--see its code for an explanation.
sub _replace_bar {
    my $args = shift;

    my $scmFromVer = $args->{matches}->[0]; 
    my $scmToVer = $args->{matches}->[1];
    my $scmArrow = $args->{matches}->[2];
    my $scmProject = $args->{matches}->[3];
    my $scmFile = $args->{matches}->[4];
    # Remember, you have to HTML-escape any data that you are returning!
    my $websvnRoot = "http://devlinux/websvn";
    my $websvnRepo = uri_escape($scmProject); #maybe do a mapping
    my $websvnFilePath = uri_escape("/".$scmFile);

    my $fromRevUrl = sprintf("%s/revision.php?repname=%s&rev=%s", 
        $websvnRoot, $websvnRepo, $scmFromVer);
    my $toRevUrl =   sprintf("%s/revision.php?repname=%s&rev=%s", 
        $websvnRoot, $websvnRepo, $scmToVer);
    my $diffUrl =    sprintf("%s/diff.php?repname=%s&path=%s&rev=%s", 
        $websvnRoot, $websvnRepo, $websvnFilePath, $scmToVer);
    my $fileUrl =    sprintf("%s/filedetails.php?repname=%s&path=%s&rev=%s", 
        $websvnRoot, $websvnRepo, $websvnFilePath, $scmToVer);

    # TODO no link for 'NONE'
    my $fromRevLink = sprintf(qq{<a href="%s">%s</a>}, $fromRevUrl, $scmFromVer);
    my $toRevLink =   sprintf(qq{<a href="%s">%s</a>}, $toRevUrl, $scmToVer);
    my $diffLink =    sprintf(qq{<a href="%s">%s</a>}, $diffUrl, $scmArrow);
    my $fileLink =    sprintf(qq{<a href="%s">%s</a>}, $fileUrl, $scmFilePath);
    # $match = html_quote($match);
    return "$fromRevLink $diffLink $toRevLink:$fileLink";
};
__PACKAGE__->NAME;
4

2 回答 2

2

如所写,您的扩展甚至不会加载:破折号在 Perl 包名称中无效。

将名称从 更改Websvn-scmbug-autolinkWebsvn_scmbug_autolink

于 2013-03-09T18:23:51.540 回答
0

我搜索了 Bugzilla 源代码,发现 3.2.x 版本根本不支持该钩子。该钩子是在 Bugzilla 3.6 中引入的:http: //bzr.mozilla.org/bugzilla/3.6/revision/6762

PS。我在模板脚本中破解了正则表达式替换以获取评论。哈克,但它的工作原理。

于 2013-03-11T10:53:09.387 回答