From 50be238662cdeb47f0b74c060c4c336822844bdb Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Mon, 23 Jun 2008 06:23:53 +0000 Subject: Bug 424079: Ability to get history of bug activity in the WebService Patch By Noura Elhawary r=mkanat, a=mkanat --- Bugzilla/WebService/Bug.pm | 147 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) (limited to 'Bugzilla') diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index 44180cc14..9463bce73 100755 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -16,6 +16,7 @@ # Max Kanat-Alexander # Mads Bondo Dydensborg # Tsahi Asher +# Noura Elhawary package Bugzilla::WebService::Bug; @@ -111,6 +112,65 @@ sub get { return { bugs => \@return }; } +# this is a function that gets bug activity for list of bug ids +# it can be called as the following: +# $call = $rpc->call( 'Bug.get_history', { ids => [1,2] }); +sub get_history { + my ($self, $params) = @_; + + my $ids = $params->{ids}; + defined $ids || ThrowCodeError('param_required', { param => 'ids' }); + + my @return; + foreach my $bug_id (@$ids) { + my %item; + ValidateBugID($bug_id); + + my ($activity) = Bugzilla::Bug::GetBugActivity($bug_id); + $item{$bug_id} = []; + + foreach my $changeset (@$activity) { + my %bug_history; + $bug_history{when} = type('dateTime')->value( + $self->datetime_format($changeset->{when})); + $bug_history{who} = type('string')->value($changeset->{who}); + $bug_history{changes} = []; + foreach my $change (@{ $changeset->{changes} }) { + my $attach_id = delete $change->{attachid}; + if ($attach_id) { + $change->{attachment_id} = type('int')->value($attach_id); + } + $change->{removed} = type('string')->value($change->{removed}); + $change->{added} = type('string')->value($change->{added}); + $change->{field_name} = type('string')->value( + delete $change->{fieldname}); + # This is going to go away in the future from GetBugActivity + # so we shouldn't put it in the API. + delete $change->{field}; + push (@{$bug_history{changes}}, $change); + } + + push (@{$item{$bug_id}}, \%bug_history); + } + + # alias is returned in case users passes a mixture of ids and aliases + # then they get to know which bug activity relates to which value + # they passed + my $bug = new Bugzilla::Bug($bug_id); + if (Bugzilla->params->{'usebugaliases'}) { + $item{alias} = type('string')->value($bug->alias); + } + else { + # For API reasons, we always want the value to appear, we just + # don't want it to have a value if aliases are turned off. + $item{alias} = undef; + } + + push(@return, \%item); + } + + return { bugs => \@return }; +} sub create { my ($self, $params) = @_; @@ -367,7 +427,94 @@ You do not have access to the bug_id you specified. =back +=item C B + +=over + +=item B + +Gets the history of changes for particular bugs in the database. + +=item B + +=over + +=item C + +An array of numbers and strings. +If an element in the array is entirely numeric, it represents a bug_id +from the Bugzilla database to fetch. If it contains any non-numeric +characters, it is considered to be a bug alias instead, and the data bug +with that alias will be loaded. + +Note that it's possible for aliases to be disabled in Bugzilla, in which +case you will be told that you have specified an invalid bug_id if you +try to specify an alias. (It will be error 100.) + +=back + +=item B + +A hash containing a single element, C. This is a hash of hashes. +Each hash has the numeric bug id as a key, and contains the following +items: + +=over + +=item alias + +C The alias of this bug. If there is no alias or aliases are +disabled in this Bugzilla, this will be undef. + +=over + +=item when + +C The date the bug activity/change happened. + +=item who + +C The login name of the user who performed the bug change. + +=item changes + +C An array of hashes which contain all the changes that happened +to the bug at this time (as specified by C). Each hash contains +the following items: + +=over + +=item field_name + +C The name of the bug field that has changed. + +=item removed + +C The previous value of the bug field which has been deleted +by the change. + +=item added + +C The new value of the bug field which has been added by the change. + +=item attachment_id + +C The id of the attachment that was changed. This only appears if +the change was to an attachment, otherwise C will not be +present in this hash. + +=back + +=back + +=back + +=item B + +The same as L. + +=back =item C B -- cgit v1.2.3-24-g4f1b