summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2008-01-06 09:52:17 +0100
committermkanat%bugzilla.org <>2008-01-06 09:52:17 +0100
commitc2ebd1bb43d06223d26426a233c00a6ca22f45d6 (patch)
treea387d87722d08e39a5241a4dcca6910ef95af7d2
parent91d9ad905e8e74a7284e3484ca995c97b1c146ce (diff)
downloadbugzilla-c2ebd1bb43d06223d26426a233c00a6ca22f45d6.tar.gz
bugzilla-c2ebd1bb43d06223d26426a233c00a6ca22f45d6.tar.xz
Bug 355847: Make the WebService able to add a comment to a bug
Patch By Tsahi Asher <tsahi_75@yahoo.com> r=mkanat, a=mkanat
-rwxr-xr-xBugzilla/WebService/Bug.pm81
-rwxr-xr-xBugzilla/WebService/Constants.pm2
-rwxr-xr-xcontrib/bz_webservice_demo.pl43
3 files changed, 123 insertions, 3 deletions
diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm
index 8dacfe956..7148b78cb 100755
--- a/Bugzilla/WebService/Bug.pm
+++ b/Bugzilla/WebService/Bug.pm
@@ -14,6 +14,8 @@
#
# Contributor(s): Marc Schumann <wurblzap@gmail.com>
# Max Kanat-Alexander <mkanat@bugzilla.org>
+# Mads Bondo Dydensborg <mbd@dbc.dk>
+# Tsahi Asher <tsahi_75@yahoo.com>
package Bugzilla::WebService::Bug;
@@ -25,7 +27,6 @@ use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Field;
use Bugzilla::WebService::Constants;
-use Bugzilla::Util qw(detaint_natural);
use Bugzilla::Bug;
use Bugzilla::BugMail;
use Bugzilla::Constants;
@@ -177,6 +178,36 @@ sub legal_values {
return { values => \@result };
}
+sub add_comment {
+ my ($self, $params) = @_;
+
+ #The user must login in order add a comment
+ Bugzilla->login(LOGIN_REQUIRED);
+
+ # Check parameters
+ defined $params->{id}
+ || ThrowCodeError('param_required', { param => 'id' });
+ ValidateBugID($params->{id});
+
+ my $comment = $params->{comment};
+ defined $comment
+ || ThrowCodeError('param_required', { param => 'comment' });
+
+ my $bug = new Bugzilla::Bug($params->{id});
+
+ Bugzilla->user->can_edit_product($bug->product_id)
+ || ThrowUserError("product_edit_denied", {product => $bug->product});
+
+ # Append comment
+ $bug->add_comment($comment, { isprivate => $params->{private},
+ work_time => $params->{work_time} });
+ $bug->update();
+
+ # Send mail.
+ Bugzilla::BugMail::Send($bug->bug_id, { changer => Bugzilla->user->login });
+ return undef;
+}
+
1;
__END__
@@ -467,5 +498,53 @@ in them. The error message will have more details.
=back
+=item C<add_comment> B<EXPERIMENTAL>
+
+=over
+
+=item B<Description>
+
+This allows you to add a comment to a bug in Bugzilla.
+
+=item B<Params>
+
+=over
+
+=item C<id> (int) B<Required> - The id or alias of the bug to append a
+comment to.
+
+=item C<comment> (string) B<Required> - The comment to append to the bug.
+
+=item C<private> (boolean) - If set to true, the comment is private, otherwise
+it is assumed to be public.
+
+=item C<work_time> (double) - Adds this many hours to the "Hours Worked"
+on the bug. If you are not in the time tracking group, this value will
+be ignored.
+
+
+=back
+
+=item B<Errors>
+
+=over
+
+=item 100 (Invalid Bug Alias)
+
+If you specified an alias and either: (a) the Bugzilla you're querying
+doesn't support aliases or (b) there is no bug with that alias.
+
+=item 101 (Invalid Bug ID)
+
+The id you specified doesn't exist in the database.
+
+=item 108 (Bug Edit Denied)
+
+You did not have the necessary rights to edit the bug.
+
+=back
+
+=back
+
=back
diff --git a/Bugzilla/WebService/Constants.pm b/Bugzilla/WebService/Constants.pm
index 2dfb0b112..a1ecb53ed 100755
--- a/Bugzilla/WebService/Constants.pm
+++ b/Bugzilla/WebService/Constants.pm
@@ -75,6 +75,8 @@ use constant WS_ERROR_CODE => {
product_disabled => 106,
# Invalid Summary
require_summary => 107,
+ # Not authorized to edit the bug
+ product_edit_denied => 108,
# Authentication errors are usually 300-400.
invalid_username_or_password => 300,
diff --git a/contrib/bz_webservice_demo.pl b/contrib/bz_webservice_demo.pl
index 72dd78a19..72c8fdaa9 100755
--- a/contrib/bz_webservice_demo.pl
+++ b/contrib/bz_webservice_demo.pl
@@ -51,6 +51,9 @@ my $bug_id;
my $product_name;
my $create_file_name;
my $legal_field_values;
+my $add_comment;
+my $private;
+my $work_time;
GetOptions('help|h|?' => \$help,
'uri=s' => \$Bugzilla_uri,
@@ -60,7 +63,10 @@ GetOptions('help|h|?' => \$help,
'bug_id:s' => \$bug_id,
'product_name:s' => \$product_name,
'create:s' => \$create_file_name,
- 'field:s' => \$legal_field_values
+ 'field:s' => \$legal_field_values,
+ 'comment:s' => \$add_comment,
+ 'private:i' => \$private,
+ 'worktime:f' => \$work_time
) or pod2usage({'-verbose' => 0, '-exitval' => 1});
=head1 OPTIONS
@@ -88,7 +94,7 @@ Bugzilla password. Specify this together with B<--login> in order to log in.
=item --rememberlogin
-Gives access to Bugzilla's “Bugzilla_remember” option.
+Gives access to Bugzilla's "Bugzilla_remember" option.
Specify this option while logging in to do the same thing as ticking the
C<Bugzilla_remember> box on Bugilla's log in form.
Don't specify this option to do the same thing as unchecking the box.
@@ -114,6 +120,20 @@ Pass a field name to get legal values for this field. It must be either a
global select field (such as bug_status, resolution, rep_platform, op_sys,
priority, bug_severity) or a custom select field.
+=item --comment
+
+A comment to add to a bug identified by B<--bug_id>. You must also pass a B<--login>
+and B<--password> to log in to Bugzilla.
+
+=item --private
+
+An optional non-zero value to specify B<--comment> as private.
+
+=item --worktime
+
+An optional double precision number specifying the work time for B<--comment>.
+
+
=back
=head1 DESCRIPTION
@@ -302,6 +322,25 @@ if ($legal_field_values) {
print join("\n", @{$result->{values}}) . "\n";
}
+=head2 Adding a comment to a bug
+
+Call C<Bug.add_comment> with the bug id, the comment text, and optionally the number
+of hours you worked on the bug, and a boolean indicating if the comment is private
+or not.
+
+=cut
+
+if ($add_comment) {
+ if ($bug_id) {
+ $soapresult = $proxy->call('Bug.add_comment', {id => $bug_id,
+ comment => $add_comment, private => $private, work_time => $work_time});
+ _die_on_fault($soapresult);
+ print "Comment added.\n";
+ }
+ else {
+ print "A --bug_id must be supplied to add a comment.";
+ }
+}
=head1 NOTES