@@ -53,18 +53,26 @@ use constant LEGACY_APPROVAL_MAPPING => {
53
53
54
54
# Set approval flags on Phabricator revision bug attachments.
55
55
sub set_attachment_approval_flags {
56
- my ($attachment , $revision , $flag_setter , $phab_user ) = @_ ;
56
+ my ($attachment , $revision , $phab_user ) = @_ ;
57
+ my $bmo_user = $phab_user -> bugzilla_user;
57
58
58
59
my $revision_status_flag_map = {
59
60
' abandoned' => ' -' ,
60
61
' accepted' => ' +' ,
62
+ ' accepted-prior' => ' +' ,
61
63
' changes-planned' => ' X' ,
62
64
' draft' => ' ?' ,
63
65
' needs-review' => ' ?' ,
64
66
' needs-revision' => ' -' ,
65
67
};
66
68
67
- my $status = $revision_status_flag_map -> {$revision -> status};
69
+ # Find the current review status of the revision changer
70
+ my $status = undef ;
71
+ foreach my $reviewer (@{$revision -> reviews}) {
72
+ if ($reviewer -> {user }-> id == $phab_user -> id) {
73
+ $status = $reviewer -> {status };
74
+ }
75
+ }
68
76
69
77
if (!$status ) {
70
78
INFO( " Approval flag status not found for revision status '"
@@ -74,7 +82,7 @@ sub set_attachment_approval_flags {
74
82
}
75
83
76
84
# The repo short name is the appropriate value that aligns with flag names.
77
- my $repo_name = $revision -> repository-> short_name;
85
+ my $repo_name = $revision -> repository-> short_name;
78
86
79
87
# With the move to git some repository short names in Phabricator changed but
80
88
# we want to use the old approval flags so we map the new names to the old if
@@ -110,14 +118,14 @@ sub set_attachment_approval_flags {
110
118
# Set the flag to it's new status. If it already has that status,
111
119
# it will be a non-change. We also need to check to make sure the
112
120
# flag change is allowed.
113
- if (!$flag_setter -> can_change_flag($flag -> type, $flag -> status, $status )) {
121
+ if (!$bmo_user -> can_change_flag($flag -> type, $flag -> status, $status )) {
114
122
INFO(
115
123
" Unable to set existing `$approval_flag_name ` flag to `$status ` due to permissions."
116
124
);
117
125
return ;
118
126
}
119
127
120
- # If setting to + or - then user needs to be a release manager in Phab .
128
+ # If setting to + or - then user needs to be a release manager.
121
129
if (($status eq ' +' || $status eq ' -' ) && !$phab_user -> is_release_manager) {
122
130
INFO(
123
131
" Unable to set existing `$approval_flag_name ` flag to `$status ` due to not being a release manager."
@@ -135,10 +143,18 @@ sub set_attachment_approval_flags {
135
143
if (!@old_flags && $status ne ' X' ) {
136
144
my $approval_flag = Bugzilla::FlagType-> new({name => $approval_flag_name });
137
145
if ($approval_flag ) {
138
- if ($flag_setter -> can_change_flag($approval_flag , ' X' , $status )) {
146
+ # If setting to + then at least one accepted reviewer needs to be a release manager.
147
+ if ($status eq ' +' && !$phab_user -> is_release_manager) {
148
+ INFO(
149
+ " Unable to create new `$approval_flag_name ` flag with status `$status ` due to not being accepted by a release manager."
150
+ );
151
+ return ;
152
+ }
153
+
154
+ if ($bmo_user -> can_change_flag($approval_flag , ' X' , $status )) {
139
155
INFO(" Creating new `$approval_flag_name ` flag with status `$status `" );
140
156
push @new_flags ,
141
- {setter => $flag_setter , status => $status , type_id => $approval_flag -> id,};
157
+ {setter => $bmo_user , status => $status , type_id => $approval_flag -> id,};
142
158
}
143
159
else {
144
160
INFO(
0 commit comments