]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 355847: Make the WebService able to add a comment to a bug
authormkanat%bugzilla.org <>
Sun, 6 Jan 2008 08:52:17 +0000 (08:52 +0000)
committermkanat%bugzilla.org <>
Sun, 6 Jan 2008 08:52:17 +0000 (08:52 +0000)
Patch By Tsahi Asher <tsahi_75@yahoo.com> r=mkanat, a=mkanat

Bugzilla/WebService/Bug.pm
Bugzilla/WebService/Constants.pm
contrib/bz_webservice_demo.pl

index 8dacfe9565e6ecbd1ec9186f80126ad2696f9804..7148b78cb528b3b102ce74ccd2302dd30ddbb3cb 100755 (executable)
@@ -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
index 2dfb0b112b7e42593d07ff823daf89772c577e27..a1ecb53ed7b3c4213aa4f1a428064e9d78df421a 100755 (executable)
@@ -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,
index 72dd78a19dab149407b23f0cb92b8a59b842f44f..72c8fdaa93e9a4868e419ba252eecaeea27531c8 100755 (executable)
@@ -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