Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Bugzilla/BugUrl.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use base qw(Bugzilla::Object);
use Bugzilla::Util;
use Bugzilla::Error;
use Bugzilla::Constants;
use Bugzilla::Hook;
use Module::Runtime qw(require_module);

use URI::QueryParam;
Expand Down Expand Up @@ -131,8 +132,12 @@ sub should_handle {
sub class_for {
my ($class, $value) = @_;

my @sub_classes = $class->SUB_CLASSES;
Bugzilla::Hook::process('bug_url_sub_classes',
{sub_classes => \@sub_classes});

my $uri = URI->new($value);
foreach my $subclass ($class->SUB_CLASSES) {
foreach my $subclass (@sub_classes) {
require_module($subclass);
return wantarray ? ($subclass, $uri) : $subclass
if $subclass->should_handle($uri);
Expand Down
15 changes: 15 additions & 0 deletions Bugzilla/Hook.pm
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,21 @@ The hash of changed fields. C<< $changes->{field} = [old, new] >>

=back

=head2 bug_url_sub_classes

Allows you to add more L<Bugzilla::BugUrl> sub-classes.

See the C<MoreBugUrl> extension to see how things work.

Params:

=over

=item C<sub_classes> - An arrayref of strings which represent L<Bugzilla::BugUrl>
sub-classes.

=back

=head2 buglist_columns

This happens in L<Bugzilla::Search/COLUMNS>, which determines legal bug
Expand Down
20 changes: 20 additions & 0 deletions extensions/MoreBugUrl/Config.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Extension::MoreBugUrl;

use 5.10.1;
use strict;
use warnings;

use constant NAME => 'MoreBugUrl';

use constant REQUIRED_MODULES => [];

use constant OPTIONAL_MODULES => [];

__PACKAGE__->NAME;
50 changes: 50 additions & 0 deletions extensions/MoreBugUrl/Extension.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Extension::MoreBugUrl;

use 5.10.1;
use strict;
use warnings;

use base qw(Bugzilla::Extension);

use constant MORE_SUB_CLASSES => qw(
Bugzilla::Extension::MoreBugUrl::BitBucket
Bugzilla::Extension::MoreBugUrl::ReviewBoard
Bugzilla::Extension::MoreBugUrl::RT
Bugzilla::Extension::MoreBugUrl::PHP
Bugzilla::Extension::MoreBugUrl::Redmine
Bugzilla::Extension::MoreBugUrl::Savane
Bugzilla::Extension::MoreBugUrl::WineHQForums
);

# We need to update the bug_see_also table because ReviewBoard was
# originally under Bugzilla/BugUrl/.
sub install_update_db {
my $dbh = Bugzilla->dbh;

my $should_rename = $dbh->selectrow_array(q{SELECT 1 FROM bug_see_also
WHERE class = 'Bugzilla::BugUrl::ReviewBoard'}
);

if ($should_rename) {
my $sth = $dbh->prepare(
'UPDATE bug_see_also SET class = ?
WHERE class = ?'
);
$sth->execute('Bugzilla::Extension::MoreBugUrl::ReviewBoard',
'Bugzilla::BugUrl::ReviewBoard');
}
}

sub bug_url_sub_classes {
my ($self, $args) = @_;
push @{$args->{sub_classes}}, MORE_SUB_CLASSES;
}

__PACKAGE__->NAME;
40 changes: 40 additions & 0 deletions extensions/MoreBugUrl/lib/BitBucket.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Extension::MoreBugUrl::BitBucket;

use 5.10.1;
use strict;
use warnings;

use base qw(Bugzilla::BugUrl);

###############################
#### Methods ####
###############################

sub should_handle {
my ($class, $uri) = @_;

# BitBucket issues have the form of
# bitbucket.org/user/project/issue/1234
return (lc($uri->authority) eq "bitbucket.org"
&& $uri->path =~ m|[^/]+/[^/]+/issue/\d+|i) ? 1 : 0;
}

sub _check_value {
my $class = shift;

my $uri = $class->SUPER::_check_value(@_);

my ($path) = $uri->path =~ m|([^/]+/[^/]+/issue/\d+)|i;
$uri = new URI("https://bitbucket.org/$path");

return $uri;
}

1;
44 changes: 44 additions & 0 deletions extensions/MoreBugUrl/lib/PHP.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Extension::MoreBugUrl::PHP;

use 5.10.1;
use strict;
use warnings;

use base qw(Bugzilla::BugUrl);

###############################
#### Methods ####
###############################

sub should_handle {
my ($class, $uri) = @_;

# PHP Bug URLs have only one form:
# https://bugs.php.net/bug.php?id=1234
return (lc($uri->authority) eq 'bugs.php.net'
and $uri->path =~ m|/bug\.php$|
and $uri->query_param('id') =~ /^\d+$/) ? 1 : 0;
}

sub _check_value {
my $class = shift;

my $uri = $class->SUPER::_check_value(@_);

# PHP Bug URLs redirect to HTTPS, so just use the HTTPS scheme.
$uri->scheme('https');

# And remove any # part if there is one.
$uri->fragment(undef);

return $uri;
}

1;
42 changes: 42 additions & 0 deletions extensions/MoreBugUrl/lib/RT.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Extension::MoreBugUrl::RT;

use 5.10.1;
use strict;
use warnings;

use base qw(Bugzilla::BugUrl);

###############################
#### Methods ####
###############################

sub should_handle {
my ($class, $uri) = @_;

# RT URLs can look like various things:
# http://example.com/rt/Ticket/Display.html?id=1234
# https://example.com/Public/Bug/Display.html?id=1234
return ($uri->path =~ m|/Display\.html$| and $uri->query_param('id') =~ /^\d+$/)
? 1
: 0;
}

sub _check_value {
my $class = shift;

my $uri = $class->SUPER::_check_value(@_);

# And remove any # part if there is one.
$uri->fragment(undef);

return $uri;
}

1;
42 changes: 42 additions & 0 deletions extensions/MoreBugUrl/lib/Redmine.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Extension::MoreBugUrl::Redmine;

use 5.10.1;
use strict;
use warnings;

use base qw(Bugzilla::BugUrl);

###############################
#### Methods ####
###############################

sub should_handle {
my ($class, $uri) = @_;
return ($uri->path =~ m|/issues/\d+$|) ? 1 : 0;
}

sub _check_value {
my $class = shift;

my $uri = $class->SUPER::_check_value(@_);

# Redmine URLs have only one form:
# http://demo.redmine.com/issues/111

# Make sure there are no query parameters.
$uri->query(undef);

# And remove any # part if there is one.
$uri->fragment(undef);

return $uri;
}

1;
47 changes: 47 additions & 0 deletions extensions/MoreBugUrl/lib/ReviewBoard.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Extension::MoreBugUrl::ReviewBoard;

use 5.10.1;
use strict;
use warnings;

use base qw(Bugzilla::BugUrl);

###############################
#### Methods ####
###############################

sub should_handle {
my ($class, $uri) = @_;
return ($uri->path =~ m|/r/\d+/?$|) ? 1 : 0;
}

sub _check_value {
my $class = shift;

my $uri = $class->SUPER::_check_value(@_);

# Review Board URLs have only one form (the trailing slash is optional):
# http://reviews.reviewboard.org/r/111/

# Make sure there are no query parameters.
$uri->query(undef);

# And remove any # part if there is one.
$uri->fragment(undef);

# make sure the trailing slash is present
if ($uri->path !~ m|/$|) {
$uri->path($uri->path . '/');
}

return $uri;
}

1;
40 changes: 40 additions & 0 deletions extensions/MoreBugUrl/lib/Savane.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Extension::MoreBugUrl::Savane;

use 5.10.1;
use strict;
use warnings;

use base qw(Bugzilla::BugUrl);

###############################
#### Methods ####
###############################

sub should_handle {
my ($class, $uri) = @_;
return ($uri->as_string =~ m|/bugs/(index\.php)?\?\d+$|) ? 1 : 0;
}

sub _check_value {
my $class = shift;

my $uri = $class->SUPER::_check_value(@_);

# Savane URLs have only two forms:
# http://gna.org/bugs/index.php?12345
# http://gna.org/bugs/?12345

# And remove any # part if there is one.
$uri->fragment(undef);

return $uri;
}

1;
Loading
Loading