Pregunta

I need some help getting a bugzilla extension off the ground.

I want to hook into bug_format_comment (FWIW: to change some plain text automatically added as a comment when I commit to SVN to links to the respective SCM commit.)

Right now, nothing seems to happen when I manually add a comment to a bug.

Is there anything special I need to do to make the extension run, besides putting it in the /extensions/my-ext-name/ dir ? How can I test if the extension is called at all?

I use an old version of Bugzilla (3.2.x). Is that hook even supported? (I can't find that info in the documentation).

Here's my complete Extension.pm file (I have no experience in Perl. I took the example of the hook from the example extension and ran from there)

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;
¿Fue útil?

Solución 2

I searched the Bugzilla sources, and found that the hook is simply not supported in version 3.2.x. The hook was introduced in Bugzilla 3.6: http://bzr.mozilla.org/bugzilla/3.6/revision/6762

PS. I hacked the regex replaces right in the template script for comments. Hacky, but it works.

Otros consejos

As written, your extension won't even load: dashes are not valid in Perl package names.

Change the name from Websvn-scmbug-autolink to Websvn_scmbug_autolink.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top