diff options
Diffstat (limited to 'extensions/PhabBugz/bin/update_project_members.pl')
-rwxr-xr-x | extensions/PhabBugz/bin/update_project_members.pl | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/extensions/PhabBugz/bin/update_project_members.pl b/extensions/PhabBugz/bin/update_project_members.pl index 06cc55626..bdc054e1a 100755 --- a/extensions/PhabBugz/bin/update_project_members.pl +++ b/extensions/PhabBugz/bin/update_project_members.pl @@ -20,9 +20,11 @@ use Bugzilla::Constants; use Bugzilla::Error; use Bugzilla::Group; -use Bugzilla::Extension::PhabBugz::Project; use Bugzilla::Extension::PhabBugz::Util qw( - get_phab_bmo_ids + create_project + get_members_by_bmo_id + get_project_phid + set_project_members ); Bugzilla->usage_mode(USAGE_MODE_CMDLINE); @@ -53,22 +55,23 @@ unless ($phab_sync_groups = Bugzilla->params->{phabricator_sync_groups}) { my $sync_groups = Bugzilla::Group->match({ name => [ split('[,\s]+', $phab_sync_groups) ] }); foreach my $group (@$sync_groups) { + my @users = get_group_members($group); + # Create group project if one does not yet exist my $phab_project_name = 'bmo-' . $group->name; - my $project = Bugzilla::Extension::PhabBugz::Project->new({ - name => $phab_project_name - }); - if (!$project->id) { - $project = Bugzilla::Extension::PhabBugz::Project->create({ - name => $phab_project_name, - description => 'BMO Security Group for ' . $group->name - }); + my $project_phid = get_project_phid($phab_project_name); + if (!$project_phid) { + $project_phid = create_project($phab_project_name, 'BMO Security Group for ' . $group->name); } - my @group_members = get_group_members($group); + # Get the internal user ids for the bugzilla group members + my $phab_user_ids = []; + if (@users) { + $phab_user_ids = get_members_by_bmo_id(\@users); + } - $project->set_members(\@group_members); - $project->update(); + # Set the project members to the exact list + set_project_members($project_phid, $phab_user_ids); } sub get_group_members { @@ -81,13 +84,5 @@ sub get_group_members { $users{$user->id} = $user; } } - - # Look up the phab ids for these users - my $phab_users = get_phab_bmo_ids({ ids => [ keys %users ] }); - foreach my $phab_user (@{ $phab_users }) { - $users{$phab_user->{id}}->{phab_phid} = $phab_user->{phid}; - } - - # We only need users who have accounts in phabricator - return grep { $_->phab_phid } values %users; -}
\ No newline at end of file + return values %users; +} |