summaryrefslogtreecommitdiffstats
path: root/extensions/BMO
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/BMO')
-rw-r--r--extensions/BMO/Extension.pm22
-rw-r--r--extensions/BMO/template/en/default/hook/attachment/edit-view.html.tmpl51
-rw-r--r--extensions/BMO/template/en/default/hook/attachment/list-action.html.tmpl2
3 files changed, 74 insertions, 1 deletions
diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm
index 8bf430529..02989d756 100644
--- a/extensions/BMO/Extension.pm
+++ b/extensions/BMO/Extension.pm
@@ -80,6 +80,7 @@ BEGIN {
*Bugzilla::Attachment::bounty_details = \&_attachment_bounty_details;
*Bugzilla::Attachment::external_redirect = \&_attachment_external_redirect;
*Bugzilla::Attachment::can_review = \&_attachment_can_review;
+ *Bugzilla::Attachment::fetch_github_pr_diff = \&_attachment_fetch_github_pr_diff;
}
sub template_before_process {
@@ -1106,6 +1107,27 @@ sub _attachment_can_review {
return $external->{can_review};
}
+sub _attachment_fetch_github_pr_diff {
+ my ($self) = @_;
+
+ # must be our supported content-type
+ return undef unless
+ any { $self->contenttype eq $autodetect_attach_urls{$_}->{content_type} }
+ keys %autodetect_attach_urls;
+
+ # must still be a valid url
+ return undef unless _detect_attached_url($self->data);
+
+ my $ua = LWP::UserAgent->new( timeout => 10 );
+ if (Bugzilla->params->{proxy_url}) {
+ $ua->proxy('https', Bugzilla->params->{proxy_url});
+ }
+
+ my $response = $ua->get($self->data . ".diff");
+ return "Error retrieving Github pull request diff" if $response->is_error;
+ return $response->content;
+}
+
# redirect automatically to github urls
sub attachment_view {
my ($self, $args) = @_;
diff --git a/extensions/BMO/template/en/default/hook/attachment/edit-view.html.tmpl b/extensions/BMO/template/en/default/hook/attachment/edit-view.html.tmpl
new file mode 100644
index 000000000..60159fcb2
--- /dev/null
+++ b/extensions/BMO/template/en/default/hook/attachment/edit-view.html.tmpl
@@ -0,0 +1,51 @@
+[%# 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.
+ #%]
+
+[%
+ RETURN UNLESS attachment.mimetype == "text/x-github-pull-request" && attachment.can_review;
+ custom_attachment_viewer = 1;
+%]
+
+[% IF NOT user.id %]
+ <div>
+ <b>Display of Github pull requests only available to logged in users.</b>
+ </div>
+ [% RETURN %]
+[% END %]
+
+[% attachment_data = attachment.fetch_github_pr_diff %]
+
+<div>
+ [% INCLUDE global/textarea.html.tmpl
+ id = 'editFrame'
+ name = 'comment'
+ classes = 'bz_default_hidden'
+ minrows = 10
+ cols = 80
+ wrap = 'soft'
+ disabled = 'disabled'
+ defaultcontent = attachment_data.replace('(.*\n|.+)', '>$1');
+ %]
+ <pre id="viewFrame">
+ [% attachment_data FILTER html %]
+ </pre>
+ [% IF user.id %]
+ <script type="text/javascript">
+ <!--
+ var patchviewerinstalled = 0;
+ document.write('<button type="button" id="editButton" onclick="editAsComment(patchviewerinstalled);">Edit Attachment As Comment<\/button>');
+ document.write('<button type="button" id="undoEditButton" onclick="undoEditAsComment(patchviewerinstalled);" class="bz_default_hidden">Undo Edit As Comment<\/button>');
+ document.write('<button type="button" id="redoEditButton" onclick="redoEditAsComment(patchviewerinstalled);" class="bz_default_hidden">Redo Edit As Comment<\/button>');
+ var editFrame = document.getElementById('editFrame');
+ if (editFrame) {
+ editFrame.disabled = false;
+ }
+ //-->
+ </script>
+ [% END %]
+<div>
diff --git a/extensions/BMO/template/en/default/hook/attachment/list-action.html.tmpl b/extensions/BMO/template/en/default/hook/attachment/list-action.html.tmpl
index 6982b3338..494ab59ef 100644
--- a/extensions/BMO/template/en/default/hook/attachment/list-action.html.tmpl
+++ b/extensions/BMO/template/en/default/hook/attachment/list-action.html.tmpl
@@ -12,5 +12,5 @@
[% IF !attachment.ispatch && attachment.can_review %]
&#x0020; |
- <a href="attachment.cgi?id=[% attachment.id FILTER none %]">Review</a>
+ <a href="attachment.cgi?id=[% attachment.id FILTER none %]">Ext Review</a>
[% END %]