From 5a966f5a68136e17f7ab86d3be1cdf3ba5eacb9c Mon Sep 17 00:00:00 2001 From: dklawren Date: Thu, 12 Apr 2018 13:21:21 -0400 Subject: [PATCH] Bug 1453681 - Phabricator project.search when searching for a specific project name can return more than one match --- extensions/PhabBugz/lib/Project.pm | 13 ++++++++++++- extensions/PhabBugz/lib/Util.pm | 9 ++++++++- 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; -- 2.47.3