summaryrefslogtreecommitdiffstats
path: root/extensions/MozReview/Extension.pm
blob: 2287a2136535d04935ebde873eec70bfa86023b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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::MozReview;

use 5.10.1;
use strict;
use parent qw(Bugzilla::Extension);

use Bugzilla::Attachment;
use Bugzilla::Config::Common;

our $VERSION = '0.01';

sub template_before_process {
    my ($self, $args) = @_;
    my $file = $args->{'file'};
    my $vars = $args->{'vars'};

    return unless (($file eq 'bug/show-header.html.tmpl' ||
                    $file eq 'bug/edit.html.tmpl') &&
                   Bugzilla->params->{mozreview_base_url});

    my $bug = exists $vars->{'bugs'} ? $vars->{'bugs'}[0] : $vars->{'bug'};

    if ($bug) {
        my @rrids;
        my $attachments = Bugzilla::Attachment->get_attachments_by_bug($bug);

        foreach my $attachment (@$attachments) {
            if ($attachment->contenttype eq 'text/x-review-board-request' &&
                !$attachment->isobsolete) {
                push @rrids, ($attachment->data =~ m#/r/(\d+)/?$#);
            }
        }

        if (scalar @rrids) {
            $vars->{'mozreview'} = 1;
            $vars->{'review_request_ids'} = \@rrids;
        }
    }
}

sub config_modify_panels {
    my ($self, $args) = @_;
    push @{ $args->{panels}->{advanced}->{params} }, {
        name    => 'mozreview_base_url',
        type    => 't',
        default => '',
        checker => \&check_urlbase
    };
}

__PACKAGE__->NAME;