summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordklawren <dklawren@users.noreply.github.com>2018-07-24 18:39:02 +0200
committerGitHub <noreply@github.com>2018-07-24 18:39:02 +0200
commit7ded28be567fd52b2ab752c30203e59f307ebdcd (patch)
tree15822d31450c63414ae6acbe2460315af8394606
parent345e686485e484e087ea58c988e4831209c39554 (diff)
downloadbugzilla-7ded28be567fd52b2ab752c30203e59f307ebdcd.tar.gz
bugzilla-7ded28be567fd52b2ab752c30203e59f307ebdcd.tar.xz
Bug 1477894 - get_attachment_revisions() should be returning an empty list, instead of a list of [0]
-rw-r--r--extensions/PhabBugz/lib/Revision.pm2
-rw-r--r--extensions/PhabBugz/lib/Util.pm3
-rw-r--r--t/phabbugz.t56
3 files changed, 55 insertions, 6 deletions
diff --git a/extensions/PhabBugz/lib/Revision.pm b/extensions/PhabBugz/lib/Revision.pm
index 900454220..4e82fa500 100644
--- a/extensions/PhabBugz/lib/Revision.pm
+++ b/extensions/PhabBugz/lib/Revision.pm
@@ -93,6 +93,8 @@ sub new_from_query {
: "";
return $class->new($result);
}
+
+ return undef;
}
sub BUILDARGS {
diff --git a/extensions/PhabBugz/lib/Util.pm b/extensions/PhabBugz/lib/Util.pm
index 214bc3fb7..99668289a 100644
--- a/extensions/PhabBugz/lib/Util.pm
+++ b/extensions/PhabBugz/lib/Util.pm
@@ -146,9 +146,10 @@ sub get_attachment_revisions {
my @revisions;
foreach my $revision_id (@revision_ids) {
- push @revisions, Bugzilla::Extension::PhabBugz::Revision->new_from_query({
+ my $revision = Bugzilla::Extension::PhabBugz::Revision->new_from_query({
ids => [ $revision_id ]
});
+ push @revisions, $revision if $revision;
}
return \@revisions;
diff --git a/t/phabbugz.t b/t/phabbugz.t
index 610089851..ba2f35e1d 100644
--- a/t/phabbugz.t
+++ b/t/phabbugz.t
@@ -62,7 +62,8 @@ local Bugzilla->params->{phabricator_base_uri} = 'http://fake.fabricator.tld';
my $Bugzilla = mock 'Bugzilla' => (
override => [
- 'dbh' => sub { mock() },
+ 'dbh' => sub { mock() },
+ 'user' => sub { Bugzilla::User->new({ name => 'phab-bot@bmo.tld' }) },
],
);
@@ -168,9 +169,53 @@ do {
'post' => sub {
my ($self, $url, $params) = @_;
if ($url =~ /differential\.revision\.search/) {
- my $data = decode_json($params->{params});
- my $content = '{"error_info":null,"error_code":null,"result":{"cursor":{"after":null,"order":null,"limit":100,"before":null},"query":{"queryKey":"all"},"maps":{},"data":[]}}';
- return mock { is_error => 0, content => $content};
+ my $content = <<JSON;
+{
+ "error_info": null,
+ "error_code": null,
+ "result": {
+ "data": [
+ {
+ "id": 9999,
+ "type": "DREV",
+ "phid": "PHID-DREV-uozm3ggfp7e7uoqegmc3",
+ "fields": {
+ "title": "Added .arcconfig",
+ "summary": "Added .arcconfig",
+ "authorPHID": "PHID-USER-4wigy3sh5fc5t74vapwm",
+ "dateCreated": 1507666113,
+ "dateModified": 1508514027,
+ "policy": {
+ "view": "public",
+ "edit": "admin"
+ },
+ "bugzilla.bug-id": "23",
+ "status": {
+ "value": "needs-review",
+ "name": "Needs Review",
+ "closed": false,
+ "color.ansi": "magenta"
+ }
+ },
+ "attachments": {
+ "reviewers": {
+ "reviewers": []
+ },
+ "subscribers": {
+ "subscriberPHIDs": [],
+ "subscriberCount": 0,
+ "viewerIsSubscribed": true
+ },
+ "projects": {
+ "projectPHIDs": []
+ }
+ }
+ }
+ ]
+ }
+}
+JSON
+ return mock { is_error => 0, content => $content };
}
else {
return mock { is_error => 1, message => "bad request" };
@@ -183,13 +228,14 @@ do {
attachments => [
mock {
contenttype => 'text/x-phabricator-request',
- filename => 'phabricator-D9999',
+ filename => 'phabricator-D9999-url.txt',
},
]
};
my $revisions = get_attachment_revisions($bug);
is(ref($revisions), 'ARRAY', 'it is an array ref');
isa_ok($revisions->[0], 'Bugzilla::Extension::PhabBugz::Revision');
+ is($revisions->[0]->bug_id, 23, 'Bugzila ID is 23');
ok( try { $revisions->[0]->update }, 'update revision');
};