@@ -231,7 +231,7 @@ type CreateReviewOptions struct {
231
231
}
232
232
233
233
// IsOfficialReviewer check if at least one of the provided reviewers can make official reviews in issue (counts towards required approvals)
234
- func IsOfficialReviewer (ctx context.Context , issue * Issue , reviewers ... * user_model.User ) (bool , error ) {
234
+ func IsOfficialReviewer (ctx context.Context , issue * Issue , reviewer * user_model.User ) (bool , error ) {
235
235
pr , err := GetPullRequestByIssueID (ctx , issue .ID )
236
236
if err != nil {
237
237
return false , err
@@ -242,14 +242,21 @@ func IsOfficialReviewer(ctx context.Context, issue *Issue, reviewers ...*user_mo
242
242
return false , err
243
243
}
244
244
if rule == nil {
245
- return false , nil
245
+ // if no rule is found, then user with write access can make official reviews
246
+ err := pr .LoadBaseRepo (ctx )
247
+ if err != nil {
248
+ return false , err
249
+ }
250
+ writeAccess , err := access_model .HasAccessUnit (ctx , reviewer , pr .BaseRepo , unit .TypeCode , perm .AccessModeWrite )
251
+ if err != nil {
252
+ return false , err
253
+ }
254
+ return writeAccess , nil
246
255
}
247
256
248
- for _ , reviewer := range reviewers {
249
- official , err := git_model .IsUserOfficialReviewer (ctx , rule , reviewer )
250
- if official || err != nil {
251
- return official , err
252
- }
257
+ official , err := git_model .IsUserOfficialReviewer (ctx , rule , reviewer )
258
+ if official || err != nil {
259
+ return official , err
253
260
}
254
261
255
262
return false , nil
@@ -578,7 +585,9 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo
578
585
return nil , nil
579
586
}
580
587
581
- official , err := IsOfficialReviewer (ctx , issue , reviewer , doer )
588
+ // if the reviewer is an official reviewer,
589
+ // remove the official flag in the all previous reviews
590
+ official , err := IsOfficialReviewer (ctx , issue , reviewer )
582
591
if err != nil {
583
592
return nil , err
584
593
} else if official {
0 commit comments