From 43d5609877e8690fe5bba5243d4642014fb2ba06 Mon Sep 17 00:00:00 2001 From: dklawren Date: Mon, 11 Sep 2017 17:14:28 -0400 Subject: Bug 1397927 - Add comment to bug when a revision is accepted/denied with the users real names (#233) Bug 1397927 - Add comment to bug when a revision is accepted/denied with the users real names * - Bug fixes * Wording changes. --- extensions/PhabBugz/lib/WebService.pm | 38 ++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'extensions/PhabBugz/lib') diff --git a/extensions/PhabBugz/lib/WebService.pm b/extensions/PhabBugz/lib/WebService.pm index e09a72036..6ef5a8b5c 100644 --- a/extensions/PhabBugz/lib/WebService.pm +++ b/extensions/PhabBugz/lib/WebService.pm @@ -164,6 +164,11 @@ sub update_reviewer_statuses { || ThrowCodeError('param_required', { param => 'accepted_users' }); $accepted_user_ids = [ split(':', $accepted_user_ids) ]; + my $denied_user_ids = $params->{denied_users}; + defined $denied_user_ids + || ThrowCodeError('param_required', { param => 'denied_users' }); + $denied_user_ids = [ split(':', $denied_user_ids) ]; + my $bug = Bugzilla::Bug->check($bug_id); my @attachments = @@ -179,17 +184,16 @@ sub update_reviewer_statuses { my ($curr_revision_id) = ($attachment->filename =~ PHAB_ATTACHMENT_PATTERN); next if $revision_id != $curr_revision_id; - # Clear old flags if no longer accepted or a previous - # acceptor is not in the new list. - my (@old_flags, @new_flags, %accepted_done, $flag_type); + # Clear old flags if no longer accepted + my (@old_flags, @new_flags, %accepted_done, %denied_done, $flag_type); foreach my $flag (@{ $attachment->flags }) { next if $flag->type->name ne 'review'; $flag_type = $flag->type; - unless (any { $flag->setter->id == $_ } @$accepted_user_ids) { - push(@old_flags, { id => $flag->id, status => 'X' }); + if (any { $flag->setter->id == $_ } @$denied_user_ids) { + push(@old_flags, { id => $flag->id, setter => $flag->setter, status => 'X' }); } - else { - $accepted_done{$flag->setter->id}++; # so we do not set it again as new + if (any { $flag->setter->id == $_ } @$accepted_user_ids) { + $accepted_done{$flag->setter->id}++; } } @@ -202,8 +206,28 @@ sub update_reviewer_statuses { push(@new_flags, { type_id => $flag_type->id, setter => $user, status => '+' }); } + # Also add comment to for attachment update showing the user's name + # that changed the revision. + my $comment; + foreach my $flag_data (@new_flags) { + $comment .= $flag_data->{setter}->name . " has approved the revision.\n"; + } + foreach my $flag_data (@old_flags) { + $comment .= $flag_data->{setter}->name . " has requested changes to the revision.\n"; + } + + if ($comment) { + $comment .= "\n" . Bugzilla->params->{phabricator_base_uri} . "D" . $revision_id; + $bug->add_comment($comment, { + isprivate => $attachment->isprivate, + type => CMT_ATTACHMENT_UPDATED, + extra_data => $attachment->id + }); + } + $attachment->set_flags(\@old_flags, \@new_flags); $attachment->update($timestamp); + $bug->update($timestamp) if $comment; push(@updated_attach_ids, $attachment->id); } -- cgit v1.2.3-24-g4f1b