summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordklawren <dklawren@users.noreply.github.com>2018-04-12 19:21:21 +0200
committerDylan William Hardison <dylan@hardison.net>2018-04-12 19:21:21 +0200
commit5a966f5a68136e17f7ab86d3be1cdf3ba5eacb9c (patch)
treebcb37be2ab22deaebef3184e53db5a8235a5ce7c
parent3be12a6b2c8163e5a9df14db20a2594a7f53f8f3 (diff)
downloadbugzilla-5a966f5a68136e17f7ab86d3be1cdf3ba5eacb9c.tar.gz
bugzilla-5a966f5a68136e17f7ab86d3be1cdf3ba5eacb9c.tar.xz
Bug 1453681 - Phabricator project.search when searching for a specific project name can return more than one match
-rw-r--r--extensions/PhabBugz/lib/Project.pm13
-rw-r--r--extensions/PhabBugz/lib/Util.pm9
2 files changed, 20 insertions, 2 deletions
diff --git a/extensions/PhabBugz/lib/Project.pm b/extensions/PhabBugz/lib/Project.pm
index b0babc58b..0fb9ecaa5 100644
--- a/extensions/PhabBugz/lib/Project.pm
+++ b/extensions/PhabBugz/lib/Project.pm
@@ -47,7 +47,18 @@ sub new_from_query {
my $result = request( 'project.search', $data );
if ( exists $result->{result}{data} && @{ $result->{result}{data} } ) {
- return $class->new( $result->{result}{data}[0] );
+ # If name is used as a query param, we need to loop through and look
+ # for exact match as Conduit will tokenize the name instead of doing
+ # exact string match :( If name is not used, then return first one.
+ if ( exists $params->{name} ) {
+ foreach my $item ( @{ $result->{result}{data} } ) {
+ next if $item->{fields}{name} ne $params->{name};
+ return $class->new($item);
+ }
+ }
+ else {
+ return $class->new( $result->{result}{data}[0] );
+ }
}
}
diff --git a/extensions/PhabBugz/lib/Util.pm b/extensions/PhabBugz/lib/Util.pm
index 52ea9c0d5..cd396602e 100644
--- a/extensions/PhabBugz/lib/Util.pm
+++ b/extensions/PhabBugz/lib/Util.pm
@@ -297,7 +297,14 @@ sub get_project_phid {
return undef
unless (exists $result->{result}{data} && @{ $result->{result}{data} });
- $project_phid = $result->{result}{data}[0]{phid};
+ # If name is used as a query param, we need to loop through and look
+ # for exact match as Conduit will tokenize the name instead of doing
+ # exact string match :(
+ foreach my $item ( @{ $result->{result}{data} } ) {
+ next if $item->{fields}{name} ne $project;
+ $project_phid = $item->{phid};
+ }
+
$memcache->set_config({ key => "phab_project_phid_" . $project, data => $project_phid });
}
return $project_phid;