summaryrefslogtreecommitdiffstats
path: root/extensions/PhabBugz
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
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')
-rw-r--r--extensions/PhabBugz/lib/Feed.pm19
-rw-r--r--extensions/PhabBugz/lib/Project.pm6
2 files changed, 16 insertions, 9 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");
}
}
diff --git a/extensions/PhabBugz/lib/Project.pm b/extensions/PhabBugz/lib/Project.pm
index c52e1a661..3d93e2f04 100644
--- a/extensions/PhabBugz/lib/Project.pm
+++ b/extensions/PhabBugz/lib/Project.pm
@@ -307,7 +307,7 @@ sub set_policy {
############
sub _build_members {
- my ($self) = @_;
+ my ( $self ) = @_;
return [] unless $self->members_raw;
my @phids;
@@ -317,13 +317,11 @@ sub _build_members {
return [] if !@phids;
- my $users = Bugzilla::Extension::PhabBugz::User->match(
+ return Bugzilla::Extension::PhabBugz::User->match(
{
phids => \@phids
}
);
-
- return [ map { $_->bugzilla_user } @$users ];
}
1;