Skip to content

Commit 83a960d

Browse files
committed
Bug 1960099 - When a revision has enters the needs-review state with a reviewer group assigned, query Phab for list of group users and update the reviewer
1 parent 5687006 commit 83a960d

File tree

4 files changed

+223
-128
lines changed

4 files changed

+223
-128
lines changed

extensions/PhabBugz/Extension.pm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ sub db_schema_abstract_schema {
118118
],
119119
INDEXES => [phabbugz_idx => {FIELDS => ['name'], TYPE => 'UNIQUE',},],
120120
};
121+
$args->{'schema'}->{'phab_reviewer_rotation'} = {
122+
FIELDS => [
123+
id => {TYPE => 'INTSERIAL', NOTNULL => 1, PRIMARYKEY => 1,},
124+
project_phid => {TYPE => 'VARCHAR(255)', NOTNULL => 1,},
125+
user_phid => {TYPE => 'VARCHAR(255)', NOTNULL => 1,},
126+
]
127+
};
121128
}
122129

123130
sub install_filesystem {

extensions/PhabBugz/lib/Feed.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use Bugzilla::Extension::PhabBugz::Util qw(
4242
request
4343
set_attachment_approval_flags
4444
set_phab_user
45+
set_reviewer_rotation
4546
);
4647

4748
has 'is_daemon' => (is => 'rw', default => 0);
@@ -726,6 +727,10 @@ sub process_revision_change {
726727
$bug->update($timestamp);
727728
$revision->update();
728729

730+
### Phabricator Reviewer Rotation
731+
# This should happen after all of the above changes and Herald has had a chance to run.
732+
set_reviewer_rotation($revision);
733+
729734
# Email changes for this revisions bug and also for any other
730735
# bugs that previously had these revision attachments
731736
foreach my $bug_id ($revision->bug_id, keys %other_bugs) {

extensions/PhabBugz/lib/Revision.pm

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,17 @@ has bug => (is => 'lazy', isa => Object);
5757
has uplift_request => (is => 'ro', isa => Maybe[ArrayRef | Dict [ slurpy Any ]]);
5858
has author => (is => 'lazy', isa => Object);
5959
has repository => (is => 'lazy', isa => Maybe[PhabRepo]);
60-
has reviews =>
61-
(is => 'lazy', isa => ArrayRef [Dict [user => PhabUser | PhabProject, status => Str]]);
60+
has reviews => (
61+
is => 'lazy',
62+
isa => ArrayRef [
63+
Dict [
64+
user => PhabUser | PhabProject,
65+
status => Str,
66+
is_blocking => Bool,
67+
is_project => Bool
68+
]
69+
]
70+
);
6271
has subscribers => (is => 'lazy', isa => ArrayRef [PhabUser]);
6372
has projects => (is => 'lazy', isa => ArrayRef [Project]);
6473
has reviewers_raw => (
@@ -87,6 +96,7 @@ has reviewers_extra_raw => (
8796
Dict [reviewerPHID => Str, voidedPHID => Maybe [Str], diffPHID => Maybe [Str]]
8897
]
8998
);
99+
has stack_graph => (is => 'lazy', isa => Tuple[ArrayRef, ArrayRef]);
90100

91101
sub new_from_query {
92102
my ($class, $params) = @_;
@@ -299,15 +309,6 @@ sub update {
299309
return $result;
300310
}
301311

302-
#########################
303-
# Accessors #
304-
#########################
305-
306-
sub secured_title {
307-
my ($self) = @_;
308-
return $self->is_private ? '(secure)' : $self->title;
309-
}
310-
311312
#########################
312313
# Builders #
313314
#########################
@@ -334,26 +335,26 @@ sub _build_author {
334335
sub _build_reviews {
335336
my ($self) = @_;
336337

337-
my %by_phid = map { $_->{reviewerPHID} => $_ } @{$self->reviewers_raw};
338-
my @users;
339-
foreach my $phid (keys %by_phid) {
340-
if ($phid =~ /^PHID-PROJ/) {
341-
push(@users,
342-
Bugzilla::Extension::PhabBugz::Project->new_from_query({phids => [$phid]}));
338+
my @reviewers;
339+
foreach my $raw (@{$self->reviewers_raw}) {
340+
my $reviewer_data = {
341+
is_blocking => ($raw->{isBlocking} ? 1 : 0),
342+
is_project => 0,
343+
status => $raw->{status},
344+
};
345+
346+
my $reviewer_phid = $raw->{reviewerPHID};
347+
if ($reviewer_phid =~ /^PHID-PROJ/) {
348+
$reviewer_data->{user} = Bugzilla::Extension::PhabBugz::Project->new_from_query({phids => [$reviewer_phid]});
349+
$reviewer_data->{is_project} = 1;
343350
}
344-
elsif ($phid =~ /^PHID-USER/) {
345-
push(@users,
346-
Bugzilla::Extension::PhabBugz::User->new_from_query({phids => [$phid]}));
351+
elsif ($reviewer_phid =~ /^PHID-USER/) {
352+
$reviewer_data->{user} = Bugzilla::Extension::PhabBugz::User->new_from_query({phids => [$reviewer_phid]});
347353
}
348-
}
349-
350-
my @reviewers;
351-
foreach my $user (@users) {
352-
my $reviewer_data = {user => $user, status => $by_phid{$user->phid}{status}};
353354

354355
# Set to accepted-prior if the diffs reviewer are different and the reviewer status is accepted
355356
foreach my $reviewer_extra (@{$self->reviewers_extra_raw}) {
356-
if ($reviewer_extra->{reviewerPHID} eq $user->phid) {
357+
if ($reviewer_extra->{reviewerPHID} eq $reviewer_phid) {
357358
if ($reviewer_extra->{diffPHID}) {
358359
if ( $reviewer_data->{status} eq 'accepted'
359360
&& $reviewer_extra->{diffPHID} ne $self->diff_phid)
@@ -422,6 +423,22 @@ sub _build_repository {
422423
return undef;
423424
}
424425

426+
sub _build_stack_graph {
427+
my ($self) = @_;
428+
429+
my @phids = keys %{$self->stack_graph_raw};
430+
my @edges = ();
431+
432+
foreach my $node (@phids) {
433+
my $predecessors = $self->stack_graph_raw->{$node};
434+
foreach my $predecessor (@{$predecessors}) {
435+
push @edges, [$node, $predecessor];
436+
}
437+
}
438+
439+
return (\@phids, \@edges);
440+
}
441+
425442
#########################
426443
# Mutators #
427444
#########################
@@ -512,8 +529,6 @@ sub make_private {
512529
$self->set_policy('view', $new_policy->phid);
513530
$self->set_policy('edit', $new_policy->phid);
514531

515-
$self->{view_policy} = $new_policy->phid;
516-
517532
return $self;
518533
}
519534

@@ -528,8 +543,6 @@ sub make_public {
528543
$self->set_policy('view', 'public');
529544
$self->set_policy('edit', ($editbugs ? $editbugs->phid : 'users'));
530545

531-
$self->{view_policy} = 'public';
532-
533546
my @current_group_projects
534547
= grep { $_->name =~ /^(bmo-.*|secure-revision)$/ } @{$self->projects};
535548
foreach my $project (@current_group_projects) {
@@ -539,11 +552,6 @@ sub make_public {
539552
return $self;
540553
}
541554

542-
sub is_private {
543-
my ($self) = @_;
544-
return $self->{view_policy} eq 'public' ? 0 : 1;
545-
}
546-
547555
sub set_private_project_tags {
548556
my ($self, $project_names) = @_;
549557

0 commit comments

Comments
 (0)