| 1 | #!/bin/false | ||
| 2 | # PODNAME: BZ::Client::Bug::Comment | ||
| 3 | # ABSTRACT: Client side representation of an Comment on a Bug in Bugzilla | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings 'all'; | ||
| 7 | |||
| 8 | package BZ::Client::Bug::Comment; | ||
| 9 | $BZ::Client::Bug::Comment::VERSION = '4.4001'; | ||
| 10 | use parent qw( BZ::Client::API ); | ||
| 11 | |||
| 12 | # See https://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html | ||
| 13 | # These are in order as per the above | ||
| 14 | |||
| 15 | ## functions | ||
| 16 | |||
| 17 | sub get { | ||
| 18 | my($class, $client, $params) = @_; | ||
| 19 | unless (ref $params) { | ||
| 20 | $params = { id => $params }; | ||
| 21 | } | ||
| 22 | $client->log('debug', __PACKAGE__ . "::get: Asking for $params"); | ||
| 23 | my $result = $class->api_call($client, 'Bug.comments', $params); | ||
| 24 | |||
| 25 | if (my $comments = $result->{comments}) { | ||
| 26 | if (!$comments || 'HASH' ne ref($comments)) { | ||
| 27 | $class->error($client, | ||
| 28 | 'Invalid reply by server, expected hash of comments.'); | ||
| 29 | } | ||
| 30 | for my $id (keys %$comments) { | ||
| 31 | $comments->{$id} = __PACKAGE__->new( %{$comments->{$id}} ); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | if (my $bugs = $result->{bugs}) { | ||
| 36 | if (!$bugs || 'HASH' ne ref($bugs)) { | ||
| 37 | $class->error($client, | ||
| 38 | 'Invalid reply by server, expected array of bugs.'); | ||
| 39 | } | ||
| 40 | for my $id (keys %$bugs) { | ||
| 41 | $bugs->{$id} = [ | ||
| 42 | map { __PACKAGE__->new( %$_ ) } @{$bugs->{$id}->{comments}} ]; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | $client->log('debug', __PACKAGE__ . '::get: Got ' . %$result); | ||
| 47 | |||
| 48 | return wantarray ? %$result : $result | ||
| 49 | } | ||
| 50 | |||
| 51 | sub add { | ||
| 52 | my($class, $client, $params) = @_; | ||
| 53 | $client->log('debug', __PACKAGE__ . '::add: Adding'); | ||
| 54 | my $result = $class->api_call($client, 'Bug.add_comment', $params); | ||
| 55 | my $id = $result->{'id'}; | ||
| 56 | if (!$id) { | ||
| 57 | $class->error($client, 'Invalid reply by server, expected comment ID.'); | ||
| 58 | } | ||
| 59 | return $id | ||
| 60 | } | ||
| 61 | |||
| 62 | sub render { | ||
| 63 | my($class, $client, $params) = @_; | ||
| 64 | $client->log('debug', __PACKAGE__ . '::render: Rendering Comment'); | ||
| 65 | my $result = $class->api_call($client, 'Bug.render_comment', $params); | ||
| 66 | my $html = $result->{'html'}; | ||
| 67 | if (!$html) { | ||
| 68 | $class->error($client, 'Invalid reply by server, expected HTML.'); | ||
| 69 | } | ||
| 70 | return $html | ||
| 71 | } | ||
| 72 | |||
| 73 | ## rw methods | ||
| 74 | |||
| 75 | sub bug_id { | ||
| 76 | my $self = shift; | ||
| 77 | if (@_) { | ||
| 78 | $self->{'bug_id'} = shift; | ||
| 79 | } | ||
| 80 | else { | ||
| 81 | return $self->{'bug_id'} | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | sub comment { | ||
| 86 | my $self = shift; | ||
| 87 | if (@_) { | ||
| 88 | $self->{'text'} = shift; | ||
| 89 | delete $self->{'comment'}; | ||
| 90 | } | ||
| 91 | else { | ||
| 92 | return $self->{'text'} || $self->{'comment'} | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | sub text { goto &comment } | ||
| 97 | |||
| 98 | sub is_private { | ||
| 99 | my $self = shift; | ||
| 100 | if (@_) { | ||
| 101 | $self->{'is_private'} = shift; | ||
| 102 | } | ||
| 103 | else { | ||
| 104 | return $self->{'is_private'} | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | sub work_time { | ||
| 109 | my $self = shift; | ||
| 110 | if (@_) { | ||
| 111 | $self->{'work_time'} = shift; | ||
| 112 | } | ||
| 113 | else { | ||
| 114 | return $self->{'work_time'} | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | ## ro methods | ||
| 119 | |||
| 120 | sub id { my $self = shift; return $self->{'id'} } | ||
| 121 | |||
| 122 | sub attachment_id { my $self = shift; return $self->{'attachment_id'} } | ||
| 123 | |||
| 124 | sub count { my $self = shift; return $self->{'count'} } | ||
| 125 | |||
| 126 | sub creator { my $self = shift; return $self->{'creator'} || $self->{'author'} } | ||
| 127 | |||
| 128 | sub author { goto &creator } | ||
| 129 | |||
| 130 | sub creation_time { my $self = shift; return $self->{'creation_time'} } | ||
| 131 | |||
| 132 | sub time { goto &creation_time } | ||
| 133 | |||
| 134 | 1; | ||
| 135 | |||
| 136 | __END__ | ||
| 137 | |||
| 138 | =pod | ||
| 139 | |||
| 140 | =encoding UTF-8 | ||
| 141 | |||
| 142 | =head1 NAME | ||
| 143 | |||
| 144 | BZ::Client::Bug::Comment - Client side representation of an Comment on a Bug in Bugzilla | ||
| 145 | |||
| 146 | =head1 VERSION | ||
| 147 | |||
| 148 | version 4.4001 | ||
| 149 | |||
| 150 | =head1 SYNOPSIS | ||
| 151 | |||
| 152 | This class provides methods for accessing and managing comments in Bugzilla. Instances | ||
| 153 | of this class are returned by L<BZ::Client::Bug::Comment::get>. | ||
| 154 | |||
| 155 | my $client = BZ::Client->new( url => $url, | ||
| 156 | user => $user, | ||
| 157 | password => $password ); | ||
| 158 | |||
| 159 | my $comments = BZ::Client::Bug::Comment->get( $client, $ids ); | ||
| 160 | |||
| 161 | =head1 CLASS METHODS | ||
| 162 | |||
| 163 | This section lists the class methods, which are available in this module. | ||
| 164 | |||
| 165 | =head2 get | ||
| 166 | |||
| 167 | my $comments = BZ::Client::Bug::Comment->get( $client, 1234 ); | ||
| 168 | my $comments = BZ::Client::Bug::Comment->get( $client, { ids => \@list, commend_ids => \@list } ); | ||
| 169 | |||
| 170 | This allows you to get data about comments, given a list of bugs and/or comment ids. | ||
| 171 | |||
| 172 | Actual Bugzilla API method is "comments". | ||
| 173 | |||
| 174 | =head3 History | ||
| 175 | |||
| 176 | Added in Bugzilla 3.4 | ||
| 177 | |||
| 178 | =head3 Parameters | ||
| 179 | |||
| 180 | A single scalar is considered a search for L</ids>, otherwise a hash reference must be provided. | ||
| 181 | |||
| 182 | Note: At least one of L</ids> or L</comment_ids> is required. | ||
| 183 | |||
| 184 | In addition to the parameters below, this method also accepts the standard L<BZ::Client::Bug/include_fields> and L<BZ::Client::Bug/exclude_fields> arguments. | ||
| 185 | |||
| 186 | =over 4 | ||
| 187 | |||
| 188 | =item ids | ||
| 189 | |||
| 190 | I<ids> (array) - An array that can contain both bug ID's and bug aliases. All of the comments (that are visible to you) will be returned for the specified bugs. | ||
| 191 | |||
| 192 | =item comment_ids | ||
| 193 | |||
| 194 | I<comment_ids> (array) - An array of integer comment ID's. These comments will be returned individually, separate from any other comments in their respective bugs. | ||
| 195 | |||
| 196 | =item new_since | ||
| 197 | |||
| 198 | I<new_since> (L<DateTime>) - If specified, the method will only return comments newer than this time. This only affects comments returned from the L</ids> argument. You will always be returned all comments you request in the I<comment_ids> argument, even if they are older than this date. | ||
| 199 | |||
| 200 | =back | ||
| 201 | |||
| 202 | =head3 Returns | ||
| 203 | |||
| 204 | A hash reference containing two items is returned. e.g. | ||
| 205 | |||
| 206 | { | ||
| 207 | |||
| 208 | bugs => { | ||
| 209 | 123 => \@comments, | ||
| 210 | 456 => \@comments, | ||
| 211 | }, | ||
| 212 | |||
| 213 | comments => { | ||
| 214 | 789 => $comment, | ||
| 215 | }, | ||
| 216 | |||
| 217 | } | ||
| 218 | |||
| 219 | The Bugzilla WebService documentation doesnt state what order the comments will be in, however they seem to be returned [ oldest, newest ]. If this order is important to you, then you should sort them just to be sure. | ||
| 220 | |||
| 221 | More details on the above example: | ||
| 222 | |||
| 223 | =over 4 | ||
| 224 | |||
| 225 | =item bugs | ||
| 226 | |||
| 227 | This is used for bugs specified in L</ids> parameter. | ||
| 228 | |||
| 229 | This is a hash, wherein the keys are the numeric IDs of the bugs, and the corresponding value is an array ref of comment objects. | ||
| 230 | |||
| 231 | Note that any individual bug will only be returned once, so if you specify an ID multiple times in ID's, it will still only be returned once. | ||
| 232 | |||
| 233 | =item comments | ||
| 234 | |||
| 235 | Each individual comment requested in L</comment_ids> is returned here. | ||
| 236 | |||
| 237 | This is a hash wherein the keys are the numeric comment ID, and the corresponding value is the comment object. | ||
| 238 | |||
| 239 | =back | ||
| 240 | |||
| 241 | A "comment" as described above is an object instance of this package i.e. L<BZ::Client::Bug::Comment>. | ||
| 242 | |||
| 243 | =head3 Errors | ||
| 244 | |||
| 245 | =over 4 | ||
| 246 | |||
| 247 | =item 100 - Invalid Bug Alias | ||
| 248 | |||
| 249 | If you specified an alias and there is no bug with that alias. | ||
| 250 | |||
| 251 | =item 101 - Invalid Bug ID | ||
| 252 | |||
| 253 | The C<bug_id> you specified doesn't exist in the database. | ||
| 254 | |||
| 255 | =item 102 - Access Denied | ||
| 256 | |||
| 257 | You do not have access to the C<bug_id> you specified. | ||
| 258 | |||
| 259 | =item 110 - Comment Is Private | ||
| 260 | |||
| 261 | You specified the ID of a private comment in the I<comment_ids> argument, and you are not in the "insider group" that can see private comments. | ||
| 262 | |||
| 263 | =item 111 - Invalid Comment ID | ||
| 264 | |||
| 265 | You specified an ID in the L</comment_ids> argument that is invalid--either you specified something that wasn't a number, or there is no comment with that ID. | ||
| 266 | |||
| 267 | =back | ||
| 268 | |||
| 269 | =head2 add | ||
| 270 | |||
| 271 | This allows you to add a comment to a bug in Bugzilla. | ||
| 272 | |||
| 273 | Actual Bugzilla API method is "add_comment". | ||
| 274 | |||
| 275 | =head3 History | ||
| 276 | |||
| 277 | Added in Bugzilla 3.2. | ||
| 278 | |||
| 279 | Modified to return the new comment's ID in Bugzilla 3.4 | ||
| 280 | |||
| 281 | Modified to throw an error if you try to add a private comment but can't, in Bugzilla 3.4. | ||
| 282 | |||
| 283 | =head3 Parameters | ||
| 284 | |||
| 285 | An instance of this package or a hash containing: | ||
| 286 | |||
| 287 | =over 4 | ||
| 288 | |||
| 289 | =item id | ||
| 290 | |||
| 291 | I<id> (int or string) Required - The ID or alias of the bug to append a comment to. | ||
| 292 | |||
| 293 | =item comment | ||
| 294 | |||
| 295 | I<comment> (string) Required - The comment to append to the bug. If this is empty or all whitespace, an error will be thrown saying that you did not set the comment parameter. | ||
| 296 | |||
| 297 | =item is_private | ||
| 298 | |||
| 299 | I<is_private> (boolean) - If set to true, the comment is private, otherwise it is assumed to be public. | ||
| 300 | |||
| 301 | Before Bugzilla 3.6, the L</is_private argument> was called C<private>, and you can still call it C<private> for backwards-compatibility purposes if you wish. | ||
| 302 | |||
| 303 | =item work_time | ||
| 304 | |||
| 305 | I<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. | ||
| 306 | |||
| 307 | =back | ||
| 308 | |||
| 309 | =head3 Returns | ||
| 310 | |||
| 311 | The id of the newly-created comment. | ||
| 312 | |||
| 313 | =head3 Errors | ||
| 314 | |||
| 315 | =over | ||
| 316 | |||
| 317 | =item 54 - Hours Worked Too Large | ||
| 318 | |||
| 319 | You specified a L</work_time> larger than the maximum allowed value of C<99999.99>. | ||
| 320 | |||
| 321 | =item 100 - Invalid Bug Alias | ||
| 322 | |||
| 323 | If you specified an alias and there is no bug with that alias. | ||
| 324 | |||
| 325 | =item 101 - Invalid Bug ID | ||
| 326 | |||
| 327 | The ID you specified doesn't exist in the database. | ||
| 328 | |||
| 329 | =item 109 - Bug Edit Denied | ||
| 330 | |||
| 331 | You did not have the necessary rights to edit the bug. | ||
| 332 | |||
| 333 | =item 113 - Can't Make Private Comments | ||
| 334 | |||
| 335 | You tried to add a private comment, but don't have the necessary rights. | ||
| 336 | |||
| 337 | =item 114 - Comment Too Long | ||
| 338 | |||
| 339 | You tried to add a comment longer than the maximum allowed length (65,535 characters). | ||
| 340 | |||
| 341 | =back | ||
| 342 | |||
| 343 | Before Bugzilla 3.6, error 54 and error 114 had a generic error code of 32000. | ||
| 344 | |||
| 345 | =head2 render | ||
| 346 | |||
| 347 | Returns the HTML rendering of the provided comment text. | ||
| 348 | |||
| 349 | Actual Bugzilla API method is "render_comment". | ||
| 350 | |||
| 351 | Note: this all takes place on your Bugzilla server. | ||
| 352 | |||
| 353 | =head3 History | ||
| 354 | |||
| 355 | Added in Bugzilla 5.0. | ||
| 356 | |||
| 357 | =head3 Parameters | ||
| 358 | |||
| 359 | =over 4 | ||
| 360 | |||
| 361 | =item text | ||
| 362 | |||
| 363 | I<text> (string) Required - Text comment text to render | ||
| 364 | |||
| 365 | =item id | ||
| 366 | |||
| 367 | I<id> The ID of the bug to render the comment against. | ||
| 368 | |||
| 369 | =back | ||
| 370 | |||
| 371 | =head3 Returns | ||
| 372 | |||
| 373 | The HTML rendering | ||
| 374 | |||
| 375 | =head3 Errors | ||
| 376 | |||
| 377 | =over 4 | ||
| 378 | |||
| 379 | =item 100 - Invalid Bug Alias | ||
| 380 | |||
| 381 | If you specified an alias and there is no bug with that alias. | ||
| 382 | |||
| 383 | =item 101 - Invalid Bug ID | ||
| 384 | |||
| 385 | The C<bug_id> you specified doesn't exist in the database. | ||
| 386 | |||
| 387 | =item 102 - Access Denied | ||
| 388 | |||
| 389 | You do not have access to the C<bug_id> you specified. | ||
| 390 | |||
| 391 | =back | ||
| 392 | |||
| 393 | =head2 new | ||
| 394 | |||
| 395 | my $comment = BZ::Client::Bug::Comment->new( | ||
| 396 | id => $bug_id, | ||
| 397 | comment => $comment, | ||
| 398 | is_private => 1 || 0, | ||
| 399 | work_time => 3.5 | ||
| 400 | ); | ||
| 401 | |||
| 402 | Creates a new instance with the given details. Doesn't actually touch your Bugzilla Server - see L</add> for that. | ||
| 403 | |||
| 404 | =head1 INSTANCE METHODS | ||
| 405 | |||
| 406 | This section lists the modules instance methods. | ||
| 407 | |||
| 408 | =head2 bug_id | ||
| 409 | |||
| 410 | I<bug_id> (int) - The ID of the bug that this comment is on when reading | ||
| 411 | |||
| 412 | I<bug_id> (int or string) - The ID or alias of the bug to append a comment to when writing | ||
| 413 | |||
| 414 | =head2 comment | ||
| 415 | |||
| 416 | I<comment> (string) The actual text of the comment when reading | ||
| 417 | |||
| 418 | When writing, the comment to append to the bug. If this is empty or all whitespace, an error will be thrown saying that you did not set the L</comment> parameter. | ||
| 419 | |||
| 420 | Max length is 65,535 characters. | ||
| 421 | |||
| 422 | =head2 text | ||
| 423 | |||
| 424 | Synonym for L</comment> | ||
| 425 | |||
| 426 | =head2 is_private | ||
| 427 | |||
| 428 | I<is_private> (boolean) - If set to true, the comment is private, otherwise it is assumed to be public. | ||
| 429 | |||
| 430 | Read and Write. | ||
| 431 | |||
| 432 | =head2 work_time | ||
| 433 | |||
| 434 | I<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. | ||
| 435 | |||
| 436 | Max value is 99999.99 | ||
| 437 | |||
| 438 | =head2 id | ||
| 439 | |||
| 440 | I<id> (int) The globally unique ID for the comment. | ||
| 441 | |||
| 442 | Read only. | ||
| 443 | |||
| 444 | =head2 attachment_id | ||
| 445 | |||
| 446 | I<attachment_id> (int) If the comment was made on an attachment, this will be the ID of that attachment. Otherwise it will be null. | ||
| 447 | |||
| 448 | Read only. | ||
| 449 | |||
| 450 | Added to the return value in Bugzilla 3.6 | ||
| 451 | |||
| 452 | =head2 count | ||
| 453 | |||
| 454 | I<count> (int) - The number of the comment local to the bug. The Description is 0, comments start with 1. | ||
| 455 | |||
| 456 | Read only. | ||
| 457 | |||
| 458 | Added to the return value in Bugzilla 4.4. | ||
| 459 | |||
| 460 | =head2 creator | ||
| 461 | |||
| 462 | I<creator> (string) - The login name of the comment's author. | ||
| 463 | |||
| 464 | Also returned as L</author>, for backwards-compatibility with older Bugzillas. (However, this backwards-compatibility will go away in Bugzilla 5.0) | ||
| 465 | |||
| 466 | In bugzilla 4.0, the L</author> return value was renamed to L</creator>. | ||
| 467 | |||
| 468 | =head2 author | ||
| 469 | |||
| 470 | See creator | ||
| 471 | |||
| 472 | =head2 time | ||
| 473 | |||
| 474 | I<time> (L<DateTime>) - The time (in Bugzilla's timezone) that the comment was added. | ||
| 475 | |||
| 476 | Read only. | ||
| 477 | |||
| 478 | =head2 creation_time | ||
| 479 | |||
| 480 | I<creation_time> (L<DateTime>) - This is exactly same as the L</time> key. Use this field instead of L</time> for consistency with other methods including L</get> and "attachments". For compatibility, I</time> is still usable. However, please note that I</time> may be deprecated and removed in a future release of Bugzilla. | ||
| 481 | |||
| 482 | Read only. | ||
| 483 | |||
| 484 | Added in Bugzilla 4.4. | ||
| 485 | |||
| 486 | =head1 SEE ALSO | ||
| 487 | |||
| 488 | L<BZ::Client>, L<BZ::Client::API>, L<Bugzilla API|https://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html> | ||
| 489 | |||
| 490 | =head1 AUTHORS | ||
| 491 | |||
| 492 | =over 4 | ||
| 493 | |||
| 494 | =item * | ||
| 495 | |||
| 496 | Dean Hamstead <dean@bytefoundry.com.au> | ||
| 497 | |||
| 498 | =item * | ||
| 499 | |||
| 500 | Jochen Wiedmann <jochen.wiedmann@gmail.com> | ||
| 501 | |||
| 502 | =back | ||
| 503 | |||
| 504 | =head1 COPYRIGHT AND LICENSE | ||
| 505 | |||
| 506 | This software is copyright (c) 2017 by Dean Hamstad. | ||
| 507 | |||
| 508 | This is free software; you can redistribute it and/or modify it under | ||
| 509 | the same terms as the Perl 5 programming language system itself. | ||
| 510 | |||
| 511 | =cut |