@@ -53,28 +53,46 @@ use constant LEGACY_APPROVAL_MAPPING => {
5353
5454# Set approval flags on Phabricator revision bug attachments.
5555sub set_attachment_approval_flags {
56- my ($attachment , $revision , $flag_setter , $phab_user ) = @_ ;
56+ my ($attachment , $revision , $phab_user , $is_new ) = @_ ;
57+ my $bmo_user = $phab_user -> bugzilla_user;
5758
5859 my $revision_status_flag_map = {
5960 ' abandoned' => ' -' ,
6061 ' accepted' => ' +' ,
62+ ' accepted-prior' => ' +' ,
6163 ' changes-planned' => ' X' ,
6264 ' draft' => ' ?' ,
6365 ' needs-review' => ' ?' ,
6466 ' needs-revision' => ' -' ,
6567 };
6668
67- my $status = $revision_status_flag_map -> {$revision -> status};
69+ # Find the current review status of the revision changer
70+ my $status = undef ;
71+ my $reviewer_status = undef ;
72+
73+ if ($is_new ) {
74+ $reviewer_status = $revision -> status;
75+ $status = $revision_status_flag_map -> {$reviewer_status };
76+ }
77+ else {
78+ foreach my $reviewer (@{$revision -> reviews}) {
79+ if ($reviewer -> {user }-> id == $phab_user -> id) {
80+ $reviewer_status = $reviewer -> {status };
81+ $status = $revision_status_flag_map -> {$reviewer_status };
82+ last ;
83+ }
84+ }
85+ }
6886
6987 if (!$status ) {
7088 INFO( " Approval flag status not found for revision status '"
71- . $revision -> status
89+ . $reviewer_status
7290 . " '" );
7391 return ;
7492 }
7593
7694 # The repo short name is the appropriate value that aligns with flag names.
77- my $repo_name = $revision -> repository-> short_name;
95+ my $repo_name = $revision -> repository-> short_name;
7896
7997 # With the move to git some repository short names in Phabricator changed but
8098 # we want to use the old approval flags so we map the new names to the old if
@@ -89,7 +107,7 @@ sub set_attachment_approval_flags {
89107 INFO( ' Setting revision D'
90108 . $revision -> id
91109 . ' with '
92- . $revision -> status
110+ . $reviewer_status
93111 . ' status to '
94112 . $approval_flag_name
95113 . $status );
@@ -103,14 +121,14 @@ sub set_attachment_approval_flags {
103121 # Set the flag to it's new status. If it already has that status,
104122 # it will be a non-change. We also need to check to make sure the
105123 # flag change is allowed.
106- if (!$flag_setter -> can_change_flag($flag -> type, $flag -> status, $status )) {
124+ if (!$bmo_user -> can_change_flag($flag -> type, $flag -> status, $status )) {
107125 INFO(
108126 " Unable to set existing `$approval_flag_name ` flag to `$status ` due to permissions."
109127 );
110128 return ;
111129 }
112130
113- # If setting to + or - then user needs to be a release manager in Phab .
131+ # If setting to + then the Phabricator user needs to be a release manager.
114132 if (($status eq ' +' || $status eq ' -' ) && !$phab_user -> is_release_manager) {
115133 INFO(
116134 " Unable to set existing `$approval_flag_name ` flag to `$status ` due to not being a release manager."
@@ -128,10 +146,19 @@ sub set_attachment_approval_flags {
128146 if (!@old_flags && $status ne ' X' ) {
129147 my $approval_flag = Bugzilla::FlagType-> new({name => $approval_flag_name });
130148 if ($approval_flag ) {
131- if ($flag_setter -> can_change_flag($approval_flag , ' X' , $status )) {
149+
150+ # If setting to + then at least one accepted reviewer needs to be a release manager.
151+ if ($status eq ' +' && !$phab_user -> is_release_manager) {
152+ INFO(
153+ " Unable to create new `$approval_flag_name ` flag with status `$status ` due to not being accepted by a release manager."
154+ );
155+ return ;
156+ }
157+
158+ if ($bmo_user -> can_change_flag($approval_flag , ' X' , $status )) {
132159 INFO(" Creating new `$approval_flag_name ` flag with status `$status `" );
133160 push @new_flags ,
134- {setter => $flag_setter , status => $status , type_id => $approval_flag -> id,};
161+ {setter => $bmo_user , status => $status , type_id => $approval_flag -> id,};
135162 }
136163 else {
137164 INFO(
0 commit comments