@@ -67,19 +67,19 @@ func (protectBranch *ProtectedBranch) IsProtected() bool {
6767}
6868
6969// CanUserPush returns if some user could push to this protected branch
70- func (protectBranch * ProtectedBranch ) CanUserPush (userID int64 ) bool {
70+ func (protectBranch * ProtectedBranch ) CanUserPush (ctx context. Context , userID int64 ) bool {
7171 if ! protectBranch .CanPush {
7272 return false
7373 }
7474
7575 if ! protectBranch .EnableWhitelist {
76- if user , err := user_model .GetUserByID (db . DefaultContext , userID ); err != nil {
76+ if user , err := user_model .GetUserByID (ctx , userID ); err != nil {
7777 log .Error ("GetUserByID: %v" , err )
7878 return false
79- } else if repo , err := repo_model .GetRepositoryByID (db . DefaultContext , protectBranch .RepoID ); err != nil {
79+ } else if repo , err := repo_model .GetRepositoryByID (ctx , protectBranch .RepoID ); err != nil {
8080 log .Error ("repo_model.GetRepositoryByID: %v" , err )
8181 return false
82- } else if writeAccess , err := access_model .HasAccessUnit (db . DefaultContext , user , repo , unit .TypeCode , perm .AccessModeWrite ); err != nil {
82+ } else if writeAccess , err := access_model .HasAccessUnit (ctx , user , repo , unit .TypeCode , perm .AccessModeWrite ); err != nil {
8383 log .Error ("HasAccessUnit: %v" , err )
8484 return false
8585 } else {
@@ -95,7 +95,7 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
9595 return false
9696 }
9797
98- in , err := organization .IsUserInTeams (db . DefaultContext , userID , protectBranch .WhitelistTeamIDs )
98+ in , err := organization .IsUserInTeams (ctx , userID , protectBranch .WhitelistTeamIDs )
9999 if err != nil {
100100 log .Error ("IsUserInTeams: %v" , err )
101101 return false
@@ -320,19 +320,19 @@ func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, prote
320320}
321321
322322// GetProtectedBranches get all protected branches
323- func GetProtectedBranches (repoID int64 ) ([]* ProtectedBranch , error ) {
323+ func GetProtectedBranches (ctx context. Context , repoID int64 ) ([]* ProtectedBranch , error ) {
324324 protectedBranches := make ([]* ProtectedBranch , 0 )
325- return protectedBranches , db .GetEngine (db . DefaultContext ).Find (& protectedBranches , & ProtectedBranch {RepoID : repoID })
325+ return protectedBranches , db .GetEngine (ctx ).Find (& protectedBranches , & ProtectedBranch {RepoID : repoID })
326326}
327327
328328// IsProtectedBranch checks if branch is protected
329- func IsProtectedBranch (repoID int64 , branchName string ) (bool , error ) {
329+ func IsProtectedBranch (ctx context. Context , repoID int64 , branchName string ) (bool , error ) {
330330 protectedBranch := & ProtectedBranch {
331331 RepoID : repoID ,
332332 BranchName : branchName ,
333333 }
334334
335- has , err := db .GetEngine (db . DefaultContext ).Exist (protectedBranch )
335+ has , err := db .GetEngine (ctx ).Exist (protectedBranch )
336336 if err != nil {
337337 return true , err
338338 }
@@ -413,13 +413,13 @@ func updateTeamWhitelist(ctx context.Context, repo *repo_model.Repository, curre
413413}
414414
415415// DeleteProtectedBranch removes ProtectedBranch relation between the user and repository.
416- func DeleteProtectedBranch (repoID , id int64 ) (err error ) {
416+ func DeleteProtectedBranch (ctx context. Context , repoID , id int64 ) (err error ) {
417417 protectedBranch := & ProtectedBranch {
418418 RepoID : repoID ,
419419 ID : id ,
420420 }
421421
422- if affected , err := db .GetEngine (db . DefaultContext ).Delete (protectedBranch ); err != nil {
422+ if affected , err := db .GetEngine (ctx ).Delete (protectedBranch ); err != nil {
423423 return err
424424 } else if affected != 1 {
425425 return fmt .Errorf ("delete protected branch ID(%v) failed" , id )
@@ -440,28 +440,28 @@ type DeletedBranch struct {
440440}
441441
442442// AddDeletedBranch adds a deleted branch to the database
443- func AddDeletedBranch (repoID int64 , branchName , commit string , deletedByID int64 ) error {
443+ func AddDeletedBranch (ctx context. Context , repoID int64 , branchName , commit string , deletedByID int64 ) error {
444444 deletedBranch := & DeletedBranch {
445445 RepoID : repoID ,
446446 Name : branchName ,
447447 Commit : commit ,
448448 DeletedByID : deletedByID ,
449449 }
450450
451- _ , err := db .GetEngine (db . DefaultContext ).Insert (deletedBranch )
451+ _ , err := db .GetEngine (ctx ).Insert (deletedBranch )
452452 return err
453453}
454454
455455// GetDeletedBranches returns all the deleted branches
456- func GetDeletedBranches (repoID int64 ) ([]* DeletedBranch , error ) {
456+ func GetDeletedBranches (ctx context. Context , repoID int64 ) ([]* DeletedBranch , error ) {
457457 deletedBranches := make ([]* DeletedBranch , 0 )
458- return deletedBranches , db .GetEngine (db . DefaultContext ).Where ("repo_id = ?" , repoID ).Desc ("deleted_unix" ).Find (& deletedBranches )
458+ return deletedBranches , db .GetEngine (ctx ).Where ("repo_id = ?" , repoID ).Desc ("deleted_unix" ).Find (& deletedBranches )
459459}
460460
461461// GetDeletedBranchByID get a deleted branch by its ID
462- func GetDeletedBranchByID (repoID , id int64 ) (* DeletedBranch , error ) {
462+ func GetDeletedBranchByID (ctx context. Context , repoID , id int64 ) (* DeletedBranch , error ) {
463463 deletedBranch := & DeletedBranch {}
464- has , err := db .GetEngine (db . DefaultContext ).Where ("repo_id = ?" , repoID ).And ("id = ?" , id ).Get (deletedBranch )
464+ has , err := db .GetEngine (ctx ).Where ("repo_id = ?" , repoID ).And ("id = ?" , id ).Get (deletedBranch )
465465 if err != nil {
466466 return nil , err
467467 }
@@ -472,13 +472,13 @@ func GetDeletedBranchByID(repoID, id int64) (*DeletedBranch, error) {
472472}
473473
474474// RemoveDeletedBranchByID removes a deleted branch from the database
475- func RemoveDeletedBranchByID (repoID , id int64 ) (err error ) {
475+ func RemoveDeletedBranchByID (ctx context. Context , repoID , id int64 ) (err error ) {
476476 deletedBranch := & DeletedBranch {
477477 RepoID : repoID ,
478478 ID : id ,
479479 }
480480
481- if affected , err := db .GetEngine (db . DefaultContext ).Delete (deletedBranch ); err != nil {
481+ if affected , err := db .GetEngine (ctx ).Delete (deletedBranch ); err != nil {
482482 return err
483483 } else if affected != 1 {
484484 return fmt .Errorf ("remove deleted branch ID(%v) failed" , id )
@@ -498,8 +498,8 @@ func (deletedBranch *DeletedBranch) LoadUser(ctx context.Context) {
498498}
499499
500500// RemoveDeletedBranchByName removes all deleted branches
501- func RemoveDeletedBranchByName (repoID int64 , branch string ) error {
502- _ , err := db .GetEngine (db . DefaultContext ).Where ("repo_id=? AND name=?" , repoID , branch ).Delete (new (DeletedBranch ))
501+ func RemoveDeletedBranchByName (ctx context. Context , repoID int64 , branch string ) error {
502+ _ , err := db .GetEngine (ctx ).Where ("repo_id=? AND name=?" , repoID , branch ).Delete (new (DeletedBranch ))
503503 return err
504504}
505505
@@ -509,7 +509,7 @@ func RemoveOldDeletedBranches(ctx context.Context, olderThan time.Duration) {
509509 log .Trace ("Doing: DeletedBranchesCleanup" )
510510
511511 deleteBefore := time .Now ().Add (- olderThan )
512- _ , err := db .GetEngine (db . DefaultContext ).Where ("deleted_unix < ?" , deleteBefore .Unix ()).Delete (new (DeletedBranch ))
512+ _ , err := db .GetEngine (ctx ).Where ("deleted_unix < ?" , deleteBefore .Unix ()).Delete (new (DeletedBranch ))
513513 if err != nil {
514514 log .Error ("DeletedBranchesCleanup: %v" , err )
515515 }
@@ -526,19 +526,19 @@ type RenamedBranch struct {
526526}
527527
528528// FindRenamedBranch check if a branch was renamed
529- func FindRenamedBranch (repoID int64 , from string ) (branch * RenamedBranch , exist bool , err error ) {
529+ func FindRenamedBranch (ctx context. Context , repoID int64 , from string ) (branch * RenamedBranch , exist bool , err error ) {
530530 branch = & RenamedBranch {
531531 RepoID : repoID ,
532532 From : from ,
533533 }
534- exist , err = db .GetEngine (db . DefaultContext ).Get (branch )
534+ exist , err = db .GetEngine (ctx ).Get (branch )
535535
536536 return branch , exist , err
537537}
538538
539539// RenameBranch rename a branch
540- func RenameBranch (repo * repo_model.Repository , from , to string , gitAction func (isDefault bool ) error ) (err error ) {
541- ctx , committer , err := db .TxContext (db . DefaultContext )
540+ func RenameBranch (ctx context. Context , repo * repo_model.Repository , from , to string , gitAction func (isDefault bool ) error ) (err error ) {
541+ ctx , committer , err := db .TxContext (ctx )
542542 if err != nil {
543543 return err
544544 }
0 commit comments