@@ -192,7 +192,7 @@ func UpdateProtectBranch(repo *Repository, protectBranch *ProtectedBranch, opts
192
192
}
193
193
protectBranch .MergeWhitelistUserIDs = whitelist
194
194
195
- whitelist , err = updateUserWhitelist (repo , protectBranch .ApprovalsWhitelistUserIDs , opts .ApprovalsUserIDs )
195
+ whitelist , err = updateApprovalWhitelist (repo , protectBranch .ApprovalsWhitelistUserIDs , opts .ApprovalsUserIDs )
196
196
if err != nil {
197
197
return err
198
198
}
@@ -298,6 +298,27 @@ func (repo *Repository) IsProtectedBranchForMerging(pr *PullRequest, branchName
298
298
return false , nil
299
299
}
300
300
301
+ // updateApprovalWhitelist checks whether the user whitelist changed and returns a whitelist with
302
+ // the users from newWhitelist which have explicit read or write access to the repo.
303
+ func updateApprovalWhitelist (repo * Repository , currentWhitelist , newWhitelist []int64 ) (whitelist []int64 , err error ) {
304
+ hasUsersChanged := ! util .IsSliceInt64Eq (currentWhitelist , newWhitelist )
305
+ if ! hasUsersChanged {
306
+ return currentWhitelist , nil
307
+ }
308
+
309
+ whitelist = make ([]int64 , 0 , len (newWhitelist ))
310
+ for _ , userID := range newWhitelist {
311
+ if reader , err := repo .IsReader (userID ); err != nil {
312
+ return nil , err
313
+ } else if ! reader {
314
+ continue
315
+ }
316
+ whitelist = append (whitelist , userID )
317
+ }
318
+
319
+ return
320
+ }
321
+
301
322
// updateUserWhitelist checks whether the user whitelist changed and returns a whitelist with
302
323
// the users from newWhitelist which have write access to the repo.
303
324
func updateUserWhitelist (repo * Repository , currentWhitelist , newWhitelist []int64 ) (whitelist []int64 , err error ) {
0 commit comments