]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1490687 - Stop setting r+s on Phabricator attachments
authordklawren <dklawren@users.noreply.github.com>
Wed, 12 Sep 2018 23:56:20 +0000 (19:56 -0400)
committerGitHub <noreply@github.com>
Wed, 12 Sep 2018 23:56:20 +0000 (19:56 -0400)
extensions/PhabBugz/lib/Feed.pm

index f2a440bb12b4ed7b3e212f2a0347aa49c4ad9e9b..2dbeef6a711731643486523583433af5efa3a599 100644 (file)
@@ -14,7 +14,6 @@ use IO::Async::Loop;
 use List::Util qw(first);
 use List::MoreUtils qw(any uniq);
 use Moo;
-use Scalar::Util qw(blessed);
 use Try::Tiny;
 use Type::Params qw( compile );
 use Type::Utils;
@@ -501,105 +500,6 @@ sub process_revision_change {
         $attachment->update($timestamp);
     }
 
-    # REVIEWER STATUSES
-
-    my (@accepted, @denied);
-    foreach my $review (@{ $revision->reviews }) {
-        push @accepted, $review->{user} if $review->{status} eq 'accepted';
-        push @denied,   $review->{user} if $review->{status} eq 'rejected';
-    }
-
-    my @accepted_user_ids = map { $_->bugzilla_user->id } grep { defined $_->bugzilla_user } @accepted;
-    my @denied_user_ids   = map { $_->bugzilla_user->id } grep { defined $_->bugzilla_user } @denied;
-    my %reviewers_hash    = map { $_->{user}->name => 1 } @{ $revision->reviews };
-
-    foreach my $attachment (@attachments) {
-        my ($attach_revision_id) = ($attachment->filename =~ PHAB_ATTACHMENT_PATTERN);
-        next if $revision->id != $attach_revision_id;
-
-        # Clear old accepted review flags if no longer accepted
-        my (@denied_flags, @new_flags, @removed_flags, %accepted_done, $flag_type);
-        foreach my $flag (@{ $attachment->flags }) {
-            next if $flag->type->name ne 'review';
-            $flag_type = $flag->type if $flag->type->is_active;
-            next if $flag->status ne '+';
-            if (any { $flag->setter->id == $_ } @denied_user_ids) {
-                INFO('Denying review flag set by ' . $flag->setter->name);
-                push(@denied_flags, { id => $flag->id, setter => $flag->setter, status => 'X' });
-            }
-            if (any { $flag->setter->id == $_ } @accepted_user_ids) {
-                INFO('Skipping as review+ already set by ' . $flag->setter->name);
-                $accepted_done{$flag->setter->id}++;
-            }
-            if (!any { $flag->setter->id == $_ } (@accepted_user_ids, @denied_user_ids)) {
-                INFO('Clearing review+ flag set by ' . $flag->setter->name);
-                push(@removed_flags, { id => $flag->id, setter => $flag->setter, status => 'X' });
-            }
-        }
-
-        $flag_type ||= first { $_->name eq 'review' && $_->is_active } @{ $attachment->flag_types };
-
-        die "Unable to find review flag!" unless $flag_type;
-
-        # Create new flags
-        foreach my $user_id (@accepted_user_ids) {
-            next if $accepted_done{$user_id};
-            my $user = Bugzilla::User->check({ id => $user_id, cache => 1 });
-            INFO('Setting new review+ flag for ' . $user->name);
-            push(@new_flags, { type_id => $flag_type->id, setter => $user, status => '+' });
-        }
-
-        # Process each flag change by updating the flag and adding a comment
-        foreach my $flag_data (@new_flags) {
-            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) {
-            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) {
-            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
-                }
-            );
-        }
-    }
-
     # FINISH UP
 
     $bug->update($timestamp);
@@ -839,38 +739,4 @@ sub get_group_members {
     );
 }
 
-sub add_flag_comment {
-    state $check = compile(
-        $Invocant,
-        Dict [
-            bug        => Bug,
-            attachment => Attachment,
-            comment    => Str,
-            user       => User,
-            old_flags  => ArrayRef,
-            new_flags  => ArrayRef,
-            timestamp  => Str,
-        ],
-    );
-    my ( $self, $params ) = $check->(@_);
-    my ( $bug, $attachment, $comment, $user, $old_flags, $new_flags, $timestamp )
-        = @$params{qw(bug attachment comment user old_flags new_flags timestamp)};
-
-    # when this function returns, Bugzilla->user will return to its previous value.
-    my $restore_prev_user = Bugzilla->set_user($user, scope_guard => 1);
-
-    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);
-}
-
 1;