summaryrefslogtreecommitdiffstats
path: root/extensions/PhabBugz/lib/Feed.pm
diff options
context:
space:
mode:
authordklawren <dklawren@users.noreply.github.com>2018-07-13 07:05:33 +0200
committerGitHub <noreply@github.com>2018-07-13 07:05:33 +0200
commit163b1cab7daaa9843dffefaab090ed5f60961f72 (patch)
tree9ba7f6b94680d1d45f719da54a7b40be981967cf /extensions/PhabBugz/lib/Feed.pm
parente86fa4e731fb879bd8bd9c3afa3eca30730b9b13 (diff)
downloadbugzilla-163b1cab7daaa9843dffefaab090ed5f60961f72.tar.gz
bugzilla-163b1cab7daaa9843dffefaab090ed5f60961f72.tar.xz
Bug 1473798 - Add and remove members of a phabricator project instead of setting exact list
Diffstat (limited to 'extensions/PhabBugz/lib/Feed.pm')
-rw-r--r--extensions/PhabBugz/lib/Feed.pm19
1 files changed, 14 insertions, 5 deletions
diff --git a/extensions/PhabBugz/lib/Feed.pm b/extensions/PhabBugz/lib/Feed.pm
index c46d36c13..1f9824ed9 100644
--- a/extensions/PhabBugz/lib/Feed.pm
+++ b/extensions/PhabBugz/lib/Feed.pm
@@ -12,7 +12,7 @@ use 5.10.1;
use IO::Async::Timer::Periodic;
use IO::Async::Loop;
use List::Util qw(first);
-use List::MoreUtils qw(any);
+use List::MoreUtils qw(any uniq);
use Moo;
use Scalar::Util qw(blessed);
use Try::Tiny;
@@ -323,10 +323,19 @@ sub group_query {
# Make sure phab-bot also a member of the new project group so that it can
# make policy changes to the private revisions
INFO("Setting project members for " . $project->name);
- my $set_members = $self->get_group_members( $group );
- push @$set_members, $phab_user unless grep $_->phid eq $phab_user->phid, @$set_members;
- $project->set_members( $set_members );
- $project->update();
+ my $set_members = $self->get_group_members( $group );
+ my @set_member_phids = uniq map { $_->phid } (@$set_members, $phab_user);
+ my @current_member_phids = uniq map { $_->phid } @{ $project->members };
+ my ($added, $removed) = diff_arrays(\@set_member_phids, \@current_member_phids);
+
+ INFO('Adding members: ' . join( ',', @$added ));
+ $project->add_member( $_ ) foreach @$added;
+ INFO('Removing members: ' . join( ',', @$removed ));
+ $project->remove_member( $_ ) foreach @$removed;
+
+ my $result = $project->update();
+ local Bugzilla::Logging->fields->{api_result} = $result;
+ INFO("Project " . $project->name . " updated");
}
}