]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1283649 - When an attachment is a github pull request link, the pull request...
authorDavid Lawrence <dkl@mozilla.com>
Tue, 12 Jul 2016 14:44:03 +0000 (14:44 +0000)
committerDavid Lawrence <dkl@mozilla.com>
Tue, 12 Jul 2016 14:44:03 +0000 (14:44 +0000)
extensions/BMO/Extension.pm
extensions/BMO/template/en/default/hook/attachment/edit-view.html.tmpl [new file with mode: 0644]
extensions/BMO/template/en/default/hook/attachment/list-action.html.tmpl
extensions/Splinter/Extension.pm
extensions/Splinter/lib/Util.pm
extensions/Splinter/template/en/default/hook/attachment/edit-action.html.tmpl
extensions/Splinter/template/en/default/hook/attachment/list-action.html.tmpl
extensions/Splinter/template/en/default/pages/splinter.html.tmpl
skins/standard/attachment.css

index 8bf430529fa488e0f7feaea5d58193576f8aff28..02989d75616e21dfd7e9527cdbf3e2e028920f93 100644 (file)
@@ -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 (file)
index 0000000..60159fc
--- /dev/null
@@ -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>
index 6982b33388c224d968e582b3be2522a72fe211bf..494ab59efb074c835917b178e004abad74d1abb6 100644 (file)
@@ -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 %]
index a3d9fe181a435f15d1ac34c622c1b796bd9d40ca..42a18d91271ecec16a79f9cfe1eefa9a59d8971f 100644 (file)
@@ -1,3 +1,10 @@
+# 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::Splinter;
 
 use strict;
@@ -75,8 +82,13 @@ sub page_before_template {
             }
 
             $vars->{'attach_id'} = $attachment->id;
-            $vars->{'attach_data'} = $attachment->data;
-            $vars->{'attach_is_crlf'} = $attachment->{data} =~ /\012\015/ ? 1 : 0;
+            if ($user->id && $attachment->contenttype eq "text/x-github-pull-request" && $attachment->can_review) {
+                $vars->{'attach_data'} = $attachment->fetch_github_pr_diff;
+            }
+            else {
+                $vars->{'attach_data'} = $attachment->data;
+            }
+            $vars->{'attach_is_crlf'} = $vars->{'attach_data'} =~ /\012\015/ ? 1 : 0;
         }
 
         my $field_object = new Bugzilla::Field({ name => 'attachments.status' });
index 870e67be786fd8471c065ab1aae12f1685f1c0b0..6421d2f0b244174702107b180476e9f727ddf5d5 100644 (file)
@@ -78,8 +78,9 @@ sub attachment_is_visible {
 sub attachment_id_is_patch {
     my $attach_id = shift;
     my $attachment = attachment_id_is_valid($attach_id);
-
-    return ($attachment && $attachment->ispatch);
+    return ($attachment
+            && ($attachment->ispatch
+                || ($attachment->contenttype eq "text/x-github-pull-request" && $attachment->external_redirect)));
 }
 
 sub get_review_base {
@@ -103,7 +104,7 @@ sub get_review_link {
 
     my $attachment = attachment_id_is_valid($attach_id);
 
-    if ($attachment && $attachment->ispatch) {
+    if (attachment_id_is_patch($attach_id)) {
         return "<a href='" . html_quote(get_review_url($attachment->bug, $attach_id)) . 
                "'>$link_text</a>";
     }
index 7648e1d7629061c30281dfbc4d0fafed95071f1d..6100deeb7d442a3e504510c55fd489ac7acc6b26 100644 (file)
@@ -19,7 +19,8 @@
   #                 David Lawrence <dkl@mozilla.com>
   #%]
 
-[% IF attachment.ispatch %]
+[% IF attachment.ispatch
+   || (attachment.mimetype == "text/x-github-pull-request" && attachment.external_redirect) %]
   &#x0020; |
   <a href="[% Bugzilla.splinter_review_url(attachment.bug_id, attachment.id) FILTER none %]">Review</a>
 [% END %]
index ee793b1927b14f60284bfb4373d8189389b1b06c..e22151b508440f09c3cfbdceda856a633229c189 100644 (file)
@@ -19,7 +19,8 @@
   #                 David Lawrence <dkl@mozilla.com>
   #%]
 
-[% IF attachment.ispatch %]
+[% IF attachment.ispatch
+   || (attachment.mimetype == "text/x-github-pull-request" && attachment.can_review) %]
   &#x0020; |
-  <a href="[% Bugzilla.splinter_review_url(bugid, attachment.id) FILTER none %]">Review</a>
+  <a href="[% Bugzilla.splinter_review_url(bugid, attachment.id) FILTER none %]">Splinter Review</a>
 [% END %]
index 16d31275962613458810d34b1178fd7ef7cba7eb..9ecaded3f69b282bae6ca1c159fd7fba0e1b8f25 100644 (file)
@@ -34,7 +34,7 @@
                  "skins/custom/bug_groups.css" ]
   javascript_urls = [ "js/yui/element/element-min.js",
                       "js/yui/container/container-min.js",
-                      "js/yui/button/button-min.js", 
+                      "js/yui/button/button-min.js",
                       "js/yui/json/json-min.js",
                       "js/yui/datasource/datasource-min.js",
                       "js/yui/datatable/datatable-min.js",
     [% END %]
 
     [% FOREACH attachment = bug.attachments %]
-      [% NEXT IF attachment.isprivate && !user.is_insider && attachment.attacher.id != user.id %]        
-      [% NEXT IF !attachment.ispatch %]
+      [% NEXT IF attachment.isprivate && !user.is_insider && attachment.attacher.id != user.id %]
+      [% NEXT IF !attachment.ispatch && !(attachment.mimetype == "text/x-github-pull-request" && attachment.external_redirect) %]
       var attachid = parseInt('[% attachment.id FILTER js %]');
       var attachment = new Splinter.Bug.Attachment('', attachid);
-      [% IF attachment.id == attach_id && attachment.ispatch %]
+      [% IF attachment.id == attach_id %]
         [% flag_types = attachment.flag_types %]
         [% can_edit = attachment.validate_can_edit %]
         attachment.data = '[% attach_data FILTER js %]';
       attachment.date = Splinter.Bug.parseDate('[% attachment.attached FILTER time("%Y-%m-%d %T %z") FILTER js %]');
       attachment.whoName = Splinter.Utils.strip('[% attachment.attacher.name FILTER js %]');
       attachment.whoEmail = Splinter.Utils.strip('[% attachment.attacher.email FILTER js %]');
-      attachment.isPatch = [% attachment.ispatch ? 1 : 0 %];
+      attachment.isPatch = [% attachment.ispatch || (attachment.mimetype == "text/x-github-pull-request" && attachment.external_redirect) ? 1 : 0 %];
       attachment.isObsolete = [% attachment.isobsolete ? 1 : 0 %];
       attachment.isPrivate = [% attachment.isprivate ? 1 : 0 %];
       attachment.isCRLF = [% attach_is_crlf ? 1 : 0 %];
     <a id="allReviewsLink" href="[% Bugzilla.splinter_review_base FILTER none %]">
       [reviews]</a>
   [% END %]
-  <a id='helpLink' target='splinterHelp' 
+  <a id='helpLink' target='splinterHelp'
      href="[% urlbase FILTER none %]page.cgi?id=splinter/help.html">
     [help]</a>
 </div>
     <li>From the Overview page, you can add a more generic overview comment that will appear at the beginning of your review.</li>
     <li>To comment on a specific lines in the patch, first select the filename from the file navigation links.</li>
     <li>Then double click the line you want to review and a comment box will appear below the line.</li>
-    <li>When the review is complete and you publish it, the overview comment and all line specific comments with their context, 
+    <li>When the review is complete and you publish it, the overview comment and all line specific comments with their context,
         will be combined together into a single review comment on the [% terms.bug %] report.</li>
-    <li>For more detailed instructions, read the Splinter 
+    <li>For more detailed instructions, read the Splinter
         <a id='helpLink' target='splinterHelp' href="[% urlbase FILTER none %]page.cgi?id=splinter/help.html">help page</a>.
     </li>
   </ul>
 <div id="splinter-files" style="display: none;">
   <div id="file-collapse-all" style="display:none;">
     <a href="javascript:void(0);" onclick="Splinter.toggleCollapsed('', 'none')">Collapse All</a> |
-    <a href="javascript:void(0);" onclick="Splinter.toggleCollapsed('', 'block')">Expand All</a> 
+    <a href="javascript:void(0);" onclick="Splinter.toggleCollapsed('', 'block')">Expand All</a>
   </div>
 </div>
 
 <div id="credits">
-  Powered by <a href="http://fishsoup.net/software/splinter">Splinter</a> 
+  Powered by <a href="http://fishsoup.net/software/splinter">Splinter</a>
 </div>
 
 <div id="saveDraftNotice" style="display: none;"></div>
index 01c4311d4d778a47fce470886ccbb051f855ff87..ace4b67813c34fb176aab1cdc29817fffb64aa32 100644 (file)
@@ -221,6 +221,7 @@ div#update_container {
     height: 400px; 
     width: 95%;
     margin-left: 2%;
+    overflow: auto;
 }
 
 .viewall_frame {