summaryrefslogtreecommitdiffstats
path: root/extensions/Push/lib
diff options
context:
space:
mode:
authorDavid Walsh <davidwalsh83@gmail.com>2017-07-19 22:03:44 +0200
committerdklawren <dklawren@users.noreply.github.com>2017-07-19 22:03:44 +0200
commitd88236d240358a239d3020066cb2a5806fb27e0e (patch)
treeb8424083885704028fbe056f98c423635898adf2 /extensions/Push/lib
parentbd5ae5e8e17f448e77766bbb1fdd09ba5e9230ec (diff)
downloadbugzilla-d88236d240358a239d3020066cb2a5806fb27e0e.tar.gz
bugzilla-d88236d240358a239d3020066cb2a5806fb27e0e.tar.xz
Bug 1380727 - Update BMO Push Connector to Make Revisions Public when Bug Made Public
Diffstat (limited to 'extensions/Push/lib')
-rw-r--r--extensions/Push/lib/Connector/Phabricator.pm52
1 files changed, 46 insertions, 6 deletions
diff --git a/extensions/Push/lib/Connector/Phabricator.pm b/extensions/Push/lib/Connector/Phabricator.pm
index 5c9cabe8b..be0ea9b58 100644
--- a/extensions/Push/lib/Connector/Phabricator.pm
+++ b/extensions/Push/lib/Connector/Phabricator.pm
@@ -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;
}