]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1380727 - Update BMO Push Connector to Make Revisions Public when Bug Made Public
authorDavid Walsh <davidwalsh83@gmail.com>
Wed, 19 Jul 2017 20:03:44 +0000 (15:03 -0500)
committerdklawren <dklawren@users.noreply.github.com>
Wed, 19 Jul 2017 20:03:44 +0000 (16:03 -0400)
extensions/PhabBugz/lib/Util.pm
extensions/PhabBugz/lib/WebService.pm
extensions/Push/lib/Connector/Phabricator.pm

index cc26f4d891158a7a4a54c0c3a70e35f10b5cabb8..cbbca7eab3adf5ed7e081f763f4e0231f6945dc1 100644 (file)
@@ -27,20 +27,20 @@ our @EXPORT = qw(
     get_bug_role_phids
     get_members_by_bmo_id
     get_project_phid
-    get_revision_by_id
+    get_revisions_by_ids
     intersect
     make_revision_public
     request
     set_project_members
 );
 
-sub get_revision_by_id {
-    my $id = shift;
+sub get_revisions_by_ids {
+    my ($ids) = @_;
 
     my $data = {
         queryKey => 'all',
         constraints => {
-            ids => [ int($id) ]
+            ids => $ids
         }
     };
 
@@ -49,7 +49,7 @@ sub get_revision_by_id {
     ThrowUserError('invalid_phabricator_revision_id')
         unless (exists $result->{result}{data} && @{ $result->{result}{data} });
 
-    return $result->{result}{data}[0];
+    return @{$result->{result}{data}};
 }
 
 sub create_revision_attachment {
index 0e2574582cbecfd66a070cf4b13198d8ac5fed91..a8312dc8e7505ed09e697b134777fb286ee5074c 100644 (file)
@@ -27,7 +27,7 @@ use Bugzilla::Extension::PhabBugz::Util qw(
     edit_revision_policy
     get_bug_role_phids
     get_project_phid
-    get_revision_by_id
+    get_revisions_by_ids
     intersect
     make_revision_public
     request
@@ -50,7 +50,8 @@ sub revision {
 
     # Obtain more information about the revision from Phabricator
     my $revision_id = $params->{revision};
-    my $revision = get_revision_by_id($revision_id);
+    my $revisions = get_revisions_by_ids([$revision_id]);
+    my $revision = $revisions->[0];
 
     my $revision_phid  = $revision->{phid};
     my $revision_title = $revision->{fields}{title} || 'Unknown Description';
index 5c9cabe8b54139ab0546dcd41e754950c04808b5..be0ea9b58cf62e2c4f1dc3144466e6d2a1f6de34 100644 (file)
@@ -1,9 +1,9 @@
 # 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.
+# 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::Push::Connector::Phabricator;
 
@@ -15,11 +15,14 @@ use base 'Bugzilla::Extension::Push::Connector::Base';
 
 use Bugzilla::Bug;
 use Bugzilla::Constants;
+use Bugzilla::Extension::PhabBugz::Util qw(intersect make_revision_public get_revisions_by_ids);
 use Bugzilla::Extension::Push::Constants;
 use Bugzilla::Extension::Push::Util;
 use Bugzilla::User;
+use List::Util qw(any);
 
 use constant PHAB_CONTENT_TYPE => 'text/x-phabricator-request';
+use constant PHAB_ATTACHMENT_PATTERN => qr/^phabricator-D(\d+)/;
 
 sub options {
     return (
@@ -47,9 +50,46 @@ sub should_send {
 }
 
 sub send {
+    my ( $self, $message ) = @_;
+
     my $logger = Bugzilla->push_ext->logger;
 
-    $logger->info('AUDIT');
+    my $data = $message->payload_decoded;
+    my $bug_data = $self->_get_bug_data($data) || return 0;
+    my $bug = Bugzilla::Bug->new( { id => $bug_data->{id}, cache => 1 } );
+
+    if(!is_public($bug)) {
+        $logger->info('Bailing on send because the bug is not public');
+        return PUSH_RESULT_OK;
+    }
+
+    my @attachments = grep {
+        $_->isobsolete == 0 &&
+        $_->contenttype eq PHAB_CONTENT_TYPE &&
+        $_->attacher->login eq 'phab-bot@bmo.tld'
+    } @{ $bug->attachments() };
+
+    if(@attachments){
+        my @rev_ids;
+        foreach my $attachment (@attachments) {
+            my ($rev_id) = ($attachment->filename =~ PHAB_ATTACHMENT_PATTERN);
+            next if !$rev_id;
+            push(@rev_ids, int($rev_id));
+        }
+
+        if(@rev_ids) {
+            $logger->info('Getting info for revisions: ');
+            $logger->info(@rev_ids);
+
+            my @rev_details = get_revisions_by_ids(\@rev_ids);
+            foreach my $rev_detail (@rev_details) {
+                my $rev_phid = $rev_detail->{phid};
+                $logger->info('Making revision $rev_phid public:');
+                $logger->info($rev_phid);
+                make_revision_public($rev_phid);
+            }
+        }
+    }
 
     return PUSH_RESULT_OK;
 }