summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Walsh <davidwalsh83@gmail.com>2017-06-16 21:52:00 +0200
committerDavid Lawrence <dkl@mozilla.com>2017-06-20 05:51:49 +0200
commita2032ba71b965ec350157aa91697b0c3a26efeb3 (patch)
treeb4e0cb554c40ec4be3785ff2a1fdc64bf5643643
parente198cf96051c7732a9da98fc938f201a3e1dd31e (diff)
downloadbugzilla-a2032ba71b965ec350157aa91697b0c3a26efeb3.tar.gz
bugzilla-a2032ba71b965ec350157aa91697b0c3a26efeb3.tar.xz
Bug 1374396 - Add initial push connector for Phabricator r=dkl
-rw-r--r--Bugzilla/Bug.pm6
-rw-r--r--extensions/Push/lib/Connector/Phabricator.pm83
2 files changed, 89 insertions, 0 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index 25c8c1f6d..eb228d27c 100644
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -4811,4 +4811,10 @@ sub _multi_select_accessor {
return $accessor;
}
+
+sub has_attachment_with_mimetype {
+ my ($self, $type) = @_;
+ return any { $_->contenttype eq $type } @{ $self->attachments };
+}
+
1;
diff --git a/extensions/Push/lib/Connector/Phabricator.pm b/extensions/Push/lib/Connector/Phabricator.pm
new file mode 100644
index 000000000..89ca41a2d
--- /dev/null
+++ b/extensions/Push/lib/Connector/Phabricator.pm
@@ -0,0 +1,83 @@
+# 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::Push::Connector::Phabricator;
+
+use 5.10.1;
+use strict;
+use warnings;
+
+use base 'Bugzilla::Extension::Push::Connector::Base';
+
+use Bugzilla::Bug;
+use Bugzilla::Constants;
+use Bugzilla::Extension::Push::Constants;
+use Bugzilla::Extension::Push::Util;
+use Bugzilla::User;
+
+use constant PHAB_CONTENT_TYPE => 'text/x-phabricator-request';
+
+sub options {
+ return (
+ { name => 'phabricator_url',
+ label => 'Phabricator URL',
+ type => 'string',
+ default => '',
+ required => 1,
+ }
+ );
+}
+
+sub should_send {
+ my ( $self, $message ) = @_;
+
+ return 0 unless Bugzilla->params->{phabricator_enabled};
+
+ if (!( $message->routing_key
+ =~ /^(?:attachment|bug)\.modify:.*\bbug_group\b/
+ )
+ )
+ {
+ return 0;
+ }
+
+ 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 } );
+ my $has_phab_stub_attachment
+ = $bug->has_attachment_with_mimetype(PHAB_CONTENT_TYPE);
+
+ if ($has_phab_stub_attachment) {
+ return 1;
+ }
+
+ return 0;
+}
+
+sub send {
+ my $logger = Bugzilla->push_ext->logger;
+
+ $logger->info('AUDIT');
+
+ return PUSH_RESULT_OK;
+}
+
+sub _get_bug_data {
+ my ( $self, $data ) = @_;
+ my $target = $data->{event}->{target};
+ if ( $target eq 'bug' ) {
+ return $data->{bug};
+ }
+ elsif ( exists $data->{$target}->{bug} ) {
+ return $data->{$target}->{bug};
+ }
+ else {
+ return;
+ }
+}
+
+1;