@@ -337,57 +337,57 @@ type WhitelistOptions struct {
337337// If ID is 0, it creates a new record. Otherwise, updates existing record.
338338// This function also performs check if whitelist user and team's IDs have been changed
339339// to avoid unnecessary whitelist delete and regenerate.
340- func UpdateProtectBranch (repo * repo_model.Repository , protectBranch * ProtectedBranch , opts WhitelistOptions ) (err error ) {
341- if err = repo .GetOwner (db . DefaultContext ); err != nil {
340+ func UpdateProtectBranch (ctx context. Context , repo * repo_model.Repository , protectBranch * ProtectedBranch , opts WhitelistOptions ) (err error ) {
341+ if err = repo .GetOwner (ctx ); err != nil {
342342 return fmt .Errorf ("GetOwner: %v" , err )
343343 }
344344
345- whitelist , err := updateUserWhitelist (repo , protectBranch .WhitelistUserIDs , opts .UserIDs )
345+ whitelist , err := updateUserWhitelist (ctx , repo , protectBranch .WhitelistUserIDs , opts .UserIDs )
346346 if err != nil {
347347 return err
348348 }
349349 protectBranch .WhitelistUserIDs = whitelist
350350
351- whitelist , err = updateUserWhitelist (repo , protectBranch .MergeWhitelistUserIDs , opts .MergeUserIDs )
351+ whitelist , err = updateUserWhitelist (ctx , repo , protectBranch .MergeWhitelistUserIDs , opts .MergeUserIDs )
352352 if err != nil {
353353 return err
354354 }
355355 protectBranch .MergeWhitelistUserIDs = whitelist
356356
357- whitelist , err = updateApprovalWhitelist (repo , protectBranch .ApprovalsWhitelistUserIDs , opts .ApprovalsUserIDs )
357+ whitelist , err = updateApprovalWhitelist (ctx , repo , protectBranch .ApprovalsWhitelistUserIDs , opts .ApprovalsUserIDs )
358358 if err != nil {
359359 return err
360360 }
361361 protectBranch .ApprovalsWhitelistUserIDs = whitelist
362362
363363 // if the repo is in an organization
364- whitelist , err = updateTeamWhitelist (repo , protectBranch .WhitelistTeamIDs , opts .TeamIDs )
364+ whitelist , err = updateTeamWhitelist (ctx , repo , protectBranch .WhitelistTeamIDs , opts .TeamIDs )
365365 if err != nil {
366366 return err
367367 }
368368 protectBranch .WhitelistTeamIDs = whitelist
369369
370- whitelist , err = updateTeamWhitelist (repo , protectBranch .MergeWhitelistTeamIDs , opts .MergeTeamIDs )
370+ whitelist , err = updateTeamWhitelist (ctx , repo , protectBranch .MergeWhitelistTeamIDs , opts .MergeTeamIDs )
371371 if err != nil {
372372 return err
373373 }
374374 protectBranch .MergeWhitelistTeamIDs = whitelist
375375
376- whitelist , err = updateTeamWhitelist (repo , protectBranch .ApprovalsWhitelistTeamIDs , opts .ApprovalsTeamIDs )
376+ whitelist , err = updateTeamWhitelist (ctx , repo , protectBranch .ApprovalsWhitelistTeamIDs , opts .ApprovalsTeamIDs )
377377 if err != nil {
378378 return err
379379 }
380380 protectBranch .ApprovalsWhitelistTeamIDs = whitelist
381381
382382 // Make sure protectBranch.ID is not 0 for whitelists
383383 if protectBranch .ID == 0 {
384- if _ , err = db .GetEngine (db . DefaultContext ).Insert (protectBranch ); err != nil {
384+ if _ , err = db .GetEngine (ctx ).Insert (protectBranch ); err != nil {
385385 return fmt .Errorf ("Insert: %v" , err )
386386 }
387387 return nil
388388 }
389389
390- if _ , err = db .GetEngine (db . DefaultContext ).ID (protectBranch .ID ).AllCols ().Update (protectBranch ); err != nil {
390+ if _ , err = db .GetEngine (ctx ).ID (protectBranch .ID ).AllCols ().Update (protectBranch ); err != nil {
391391 return fmt .Errorf ("Update: %v" , err )
392392 }
393393
@@ -416,15 +416,15 @@ func IsProtectedBranch(repoID int64, branchName string) (bool, error) {
416416
417417// updateApprovalWhitelist checks whether the user whitelist changed and returns a whitelist with
418418// the users from newWhitelist which have explicit read or write access to the repo.
419- func updateApprovalWhitelist (repo * repo_model.Repository , currentWhitelist , newWhitelist []int64 ) (whitelist []int64 , err error ) {
419+ func updateApprovalWhitelist (ctx context. Context , repo * repo_model.Repository , currentWhitelist , newWhitelist []int64 ) (whitelist []int64 , err error ) {
420420 hasUsersChanged := ! util .IsSliceInt64Eq (currentWhitelist , newWhitelist )
421421 if ! hasUsersChanged {
422422 return currentWhitelist , nil
423423 }
424424
425425 whitelist = make ([]int64 , 0 , len (newWhitelist ))
426426 for _ , userID := range newWhitelist {
427- if reader , err := IsRepoReader (repo , userID ); err != nil {
427+ if reader , err := IsRepoReader (ctx , repo , userID ); err != nil {
428428 return nil , err
429429 } else if ! reader {
430430 continue
@@ -437,19 +437,19 @@ func updateApprovalWhitelist(repo *repo_model.Repository, currentWhitelist, newW
437437
438438// updateUserWhitelist checks whether the user whitelist changed and returns a whitelist with
439439// the users from newWhitelist which have write access to the repo.
440- func updateUserWhitelist (repo * repo_model.Repository , currentWhitelist , newWhitelist []int64 ) (whitelist []int64 , err error ) {
440+ func updateUserWhitelist (ctx context. Context , repo * repo_model.Repository , currentWhitelist , newWhitelist []int64 ) (whitelist []int64 , err error ) {
441441 hasUsersChanged := ! util .IsSliceInt64Eq (currentWhitelist , newWhitelist )
442442 if ! hasUsersChanged {
443443 return currentWhitelist , nil
444444 }
445445
446446 whitelist = make ([]int64 , 0 , len (newWhitelist ))
447447 for _ , userID := range newWhitelist {
448- user , err := user_model .GetUserByID ( userID )
448+ user , err := user_model .GetUserByIDCtx ( ctx , userID )
449449 if err != nil {
450450 return nil , fmt .Errorf ("GetUserByID [user_id: %d, repo_id: %d]: %v" , userID , repo .ID , err )
451451 }
452- perm , err := GetUserRepoPermission (repo , user )
452+ perm , err := GetUserRepoPermission (ctx , repo , user )
453453 if err != nil {
454454 return nil , fmt .Errorf ("GetUserRepoPermission [user_id: %d, repo_id: %d]: %v" , userID , repo .ID , err )
455455 }
@@ -466,13 +466,13 @@ func updateUserWhitelist(repo *repo_model.Repository, currentWhitelist, newWhite
466466
467467// updateTeamWhitelist checks whether the team whitelist changed and returns a whitelist with
468468// the teams from newWhitelist which have write access to the repo.
469- func updateTeamWhitelist (repo * repo_model.Repository , currentWhitelist , newWhitelist []int64 ) (whitelist []int64 , err error ) {
469+ func updateTeamWhitelist (ctx context. Context , repo * repo_model.Repository , currentWhitelist , newWhitelist []int64 ) (whitelist []int64 , err error ) {
470470 hasTeamsChanged := ! util .IsSliceInt64Eq (currentWhitelist , newWhitelist )
471471 if ! hasTeamsChanged {
472472 return currentWhitelist , nil
473473 }
474474
475- teams , err := organization .GetTeamsWithAccessToRepo (repo .OwnerID , repo .ID , perm .AccessModeRead )
475+ teams , err := organization .GetTeamsWithAccessToRepo (ctx , repo .OwnerID , repo .ID , perm .AccessModeRead )
476476 if err != nil {
477477 return nil , fmt .Errorf ("GetTeamsWithAccessToRepo [org_id: %d, repo_id: %d]: %v" , repo .OwnerID , repo .ID , err )
478478 }
0 commit comments