summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordklawren <dklawren@users.noreply.github.com>2018-08-06 18:15:49 +0200
committerDylan William Hardison <dylan@hardison.net>2018-08-06 18:15:49 +0200
commit97b81755333e915201360521416f831484b3b8fb (patch)
tree06de164aa3d60f5fa4032eb593e2c8600a4d8d41
parent7f09ef208e09c85ed7087ab32e89da29bde837db (diff)
downloadbugzilla-97b81755333e915201360521416f831484b3b8fb.tar.gz
bugzilla-97b81755333e915201360521416f831484b3b8fb.tar.xz
Bug 1480169 - Consider reducing the verbosity of phabricator 'Revision Approved' bugzilla comments
-rw-r--r--extensions/PhabBugz/lib/Feed.pm93
1 files changed, 69 insertions, 24 deletions
diff --git a/extensions/PhabBugz/lib/Feed.pm b/extensions/PhabBugz/lib/Feed.pm
index 7d6b4e0ed..69ce2227d 100644
--- a/extensions/PhabBugz/lib/Feed.pm
+++ b/extensions/PhabBugz/lib/Feed.pm
@@ -542,37 +542,55 @@ sub process_revision_change {
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;
+ # Process each flag change by updating the flag and adding a comment
foreach my $flag_data (@new_flags) {
- $comment .= $flag_data->{setter}->name . " has approved the revision.\n";
+ my $comment = $flag_data->{setter}->name . " has approved the revision.";
+ $self->add_flag_comment(
+ {
+ bug => $bug,
+ attachment => $attachment,
+ comment => $comment,
+ user => $flag_data->{setter},
+ old_flags => [],
+ new_flags => [$flag_data],
+ timestamp => $timestamp
+ }
+ );
}
foreach my $flag_data (@denied_flags) {
- $comment .= $flag_data->{setter}->name . " has requested changes to the revision.\n";
+ my $comment = $flag_data->{setter}->name . " has requested changes to the revision.\n";
+ $self->add_flag_comment(
+ {
+ bug => $bug,
+ attachment => $attachment,
+ comment => $comment,
+ user => $flag_data->{setter},
+ old_flags => [$flag_data],
+ new_flags => [],
+ timestamp => $timestamp
+ }
+ );
}
foreach my $flag_data (@removed_flags) {
- if ( exists $reviewers_hash{$flag_data->{setter}->name} ) {
- $comment .= "Flag set by " . $flag_data->{setter}->name . " is no longer active.\n";
- } else {
- $comment .= $flag_data->{setter}->name . " has been removed from the revision.\n";
+ my $comment;
+ if ( exists $reviewers_hash{ $flag_data->{setter}->name } ) {
+ $comment = "Flag set by " . $flag_data->{setter}->name . " is no longer active.\n";
}
+ else {
+ $comment = $flag_data->{setter}->name . " has been removed from the revision.\n";
+ }
+ $self->add_flag_comment(
+ {
+ bug => $bug,
+ attachment => $attachment,
+ comment => $comment,
+ user => $flag_data->{setter},
+ old_flags => [$flag_data],
+ new_flags => [],
+ timestamp => $timestamp
+ }
+ );
}
-
- if ($comment) {
- $comment .= "\n" . Bugzilla->params->{phabricator_base_uri} . "D" . $revision->id;
- INFO("Flag comment: $comment");
- # Add transaction_id as anchor if one present
- # $comment .= "#" . $params->{transaction_id} if $params->{transaction_id};
- $bug->add_comment($comment, {
- isprivate => $attachment->isprivate,
- type => CMT_ATTACHMENT_UPDATED,
- extra_data => $attachment->id
- });
- }
-
- $attachment->set_flags([ @denied_flags, @removed_flags ], \@new_flags);
- $attachment->update($timestamp);
}
# FINISH UP
@@ -817,4 +835,31 @@ sub get_group_members {
);
}
+sub add_flag_comment {
+ my ( $self, $params ) = @_;
+ my ( $bug, $attachment, $comment, $user, $old_flags, $new_flags, $timestamp )
+ = @$params{qw(bug attachment comment user old_flags new_flags timestamp)};
+
+ my $old_user;
+ if ($user) {
+ $old_user = Bugzilla->user;
+ Bugzilla->set_user($user);
+ }
+
+ INFO("Flag comment: $comment");
+ $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);
+
+ Bugzilla->set_user($old_user) if $old_user;
+}
+
1;