summaryrefslogtreecommitdiffstats
path: root/Bugzilla/WebService
diff options
context:
space:
mode:
authorIsrael Madueme <purelogiq@gmail.com>2018-04-10 23:45:59 +0200
committerDylan William Hardison <dylan@hardison.net>2018-04-10 23:45:59 +0200
commit71ef35b5330d80e8f5d4bdc99f62aea3fadb22c5 (patch)
treee6ff8ab492fbe02077fc6111ab0150c66a171ba6 /Bugzilla/WebService
parent8ba7aa6be8fb5689634c453fd505822d02f586a6 (diff)
downloadbugzilla-71ef35b5330d80e8f5d4bdc99f62aea3fadb22c5.tar.gz
bugzilla-71ef35b5330d80e8f5d4bdc99f62aea3fadb22c5.tar.xz
Bug 1421110 - Add REST API endpoint for /bug/possible_duplicates
Diffstat (limited to 'Bugzilla/WebService')
-rw-r--r--Bugzilla/WebService/Bug.pm43
-rw-r--r--Bugzilla/WebService/Server/REST/Resources/Bug.pm5
2 files changed, 43 insertions, 5 deletions
diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm
index c07454d7d..feb541c2e 100644
--- a/Bugzilla/WebService/Bug.pm
+++ b/Bugzilla/WebService/Bug.pm
@@ -35,6 +35,8 @@ use Bugzilla::Search::Quicksearch;
use List::Util qw(max);
use List::MoreUtils qw(uniq);
use Storable qw(dclone);
+use Types::Standard -all;
+use Type::Utils;
#############
# Constants #
@@ -656,9 +658,30 @@ sub possible_duplicates {
Bugzilla->switch_to_shadow_db();
- # Undo the array-ification that validate() does, for "summary".
- $params->{summary} || ThrowCodeError('param_required',
- { function => 'Bug.possible_duplicates', param => 'summary' });
+ state $params_type = Dict [
+ id => Optional [Int],
+ product => Optional [ ArrayRef [Str] ],
+ limit => Optional [Int],
+ summary => Optional [Str],
+ include_fields => Optional [ ArrayRef [Str] ],
+ Bugzilla_api_token => Optional [Str]
+ ];
+
+ ThrowCodeError( 'param_invalid', { function => 'Bug.possible_duplicates', param => 'A param' } )
+ if !$params_type->check($params);
+
+ my $summary;
+ if ($params->{id}) {
+ my $bug = Bugzilla::Bug->check({ id => $params->{id}, cache => 1 });
+ $summary = $bug->short_desc;
+ }
+ elsif ($params->{summary}) {
+ $summary = $params->{summary};
+ }
+ else {
+ ThrowCodeError('param_required',
+ { function => 'Bug.possible_duplicates', param => 'id or summary' });
+ }
my @products;
foreach my $name (@{ $params->{'product'} || [] }) {
@@ -667,8 +690,18 @@ sub possible_duplicates {
}
my $possible_dupes = Bugzilla::Bug->possible_duplicates(
- { summary => $params->{summary}, products => \@products,
- limit => $params->{limit} });
+ {
+ summary => $summary,
+ products => \@products,
+ limit => $params->{limit}
+ }
+ );
+
+ # If a bug id was used, remove the bug with the same id from the list.
+ if ($params->{id}) {
+ @$possible_dupes = grep { $_->id != $params->{id} } @$possible_dupes;
+ }
+
my @hashes = map { $self->_bug_to_hash($_, $params) } @$possible_dupes;
$self->_add_update_tokens($params, $possible_dupes, \@hashes);
return { bugs => \@hashes };
diff --git a/Bugzilla/WebService/Server/REST/Resources/Bug.pm b/Bugzilla/WebService/Server/REST/Resources/Bug.pm
index 33cf43321..26aec011c 100644
--- a/Bugzilla/WebService/Server/REST/Resources/Bug.pm
+++ b/Bugzilla/WebService/Server/REST/Resources/Bug.pm
@@ -34,6 +34,11 @@ sub _rest_resources {
method => 'get'
}
},
+ qr{^/bug/possible_duplicates$}, {
+ GET => {
+ method => 'possible_duplicates'
+ }
+ },
qr{^/bug/([^/]+)$}, {
GET => {
method => 'get',