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