@@ -67,19 +67,19 @@ func (protectBranch *ProtectedBranch) IsProtected() bool {
67
67
}
68
68
69
69
// 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 {
71
71
if ! protectBranch .CanPush {
72
72
return false
73
73
}
74
74
75
75
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 {
77
77
log .Error ("GetUserByID: %v" , err )
78
78
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 {
80
80
log .Error ("repo_model.GetRepositoryByID: %v" , err )
81
81
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 {
83
83
log .Error ("HasAccessUnit: %v" , err )
84
84
return false
85
85
} else {
@@ -95,7 +95,7 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
95
95
return false
96
96
}
97
97
98
- in , err := organization .IsUserInTeams (db . DefaultContext , userID , protectBranch .WhitelistTeamIDs )
98
+ in , err := organization .IsUserInTeams (ctx , userID , protectBranch .WhitelistTeamIDs )
99
99
if err != nil {
100
100
log .Error ("IsUserInTeams: %v" , err )
101
101
return false
@@ -320,19 +320,19 @@ func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, prote
320
320
}
321
321
322
322
// GetProtectedBranches get all protected branches
323
- func GetProtectedBranches (repoID int64 ) ([]* ProtectedBranch , error ) {
323
+ func GetProtectedBranches (ctx context. Context , repoID int64 ) ([]* ProtectedBranch , error ) {
324
324
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 })
326
326
}
327
327
328
328
// 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 ) {
330
330
protectedBranch := & ProtectedBranch {
331
331
RepoID : repoID ,
332
332
BranchName : branchName ,
333
333
}
334
334
335
- has , err := db .GetEngine (db . DefaultContext ).Exist (protectedBranch )
335
+ has , err := db .GetEngine (ctx ).Exist (protectedBranch )
336
336
if err != nil {
337
337
return true , err
338
338
}
@@ -413,13 +413,13 @@ func updateTeamWhitelist(ctx context.Context, repo *repo_model.Repository, curre
413
413
}
414
414
415
415
// 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 ) {
417
417
protectedBranch := & ProtectedBranch {
418
418
RepoID : repoID ,
419
419
ID : id ,
420
420
}
421
421
422
- if affected , err := db .GetEngine (db . DefaultContext ).Delete (protectedBranch ); err != nil {
422
+ if affected , err := db .GetEngine (ctx ).Delete (protectedBranch ); err != nil {
423
423
return err
424
424
} else if affected != 1 {
425
425
return fmt .Errorf ("delete protected branch ID(%v) failed" , id )
@@ -440,28 +440,28 @@ type DeletedBranch struct {
440
440
}
441
441
442
442
// 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 {
444
444
deletedBranch := & DeletedBranch {
445
445
RepoID : repoID ,
446
446
Name : branchName ,
447
447
Commit : commit ,
448
448
DeletedByID : deletedByID ,
449
449
}
450
450
451
- _ , err := db .GetEngine (db . DefaultContext ).Insert (deletedBranch )
451
+ _ , err := db .GetEngine (ctx ).Insert (deletedBranch )
452
452
return err
453
453
}
454
454
455
455
// GetDeletedBranches returns all the deleted branches
456
- func GetDeletedBranches (repoID int64 ) ([]* DeletedBranch , error ) {
456
+ func GetDeletedBranches (ctx context. Context , repoID int64 ) ([]* DeletedBranch , error ) {
457
457
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 )
459
459
}
460
460
461
461
// 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 ) {
463
463
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 )
465
465
if err != nil {
466
466
return nil , err
467
467
}
@@ -472,13 +472,13 @@ func GetDeletedBranchByID(repoID, id int64) (*DeletedBranch, error) {
472
472
}
473
473
474
474
// 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 ) {
476
476
deletedBranch := & DeletedBranch {
477
477
RepoID : repoID ,
478
478
ID : id ,
479
479
}
480
480
481
- if affected , err := db .GetEngine (db . DefaultContext ).Delete (deletedBranch ); err != nil {
481
+ if affected , err := db .GetEngine (ctx ).Delete (deletedBranch ); err != nil {
482
482
return err
483
483
} else if affected != 1 {
484
484
return fmt .Errorf ("remove deleted branch ID(%v) failed" , id )
@@ -498,8 +498,8 @@ func (deletedBranch *DeletedBranch) LoadUser(ctx context.Context) {
498
498
}
499
499
500
500
// 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 ))
503
503
return err
504
504
}
505
505
@@ -509,7 +509,7 @@ func RemoveOldDeletedBranches(ctx context.Context, olderThan time.Duration) {
509
509
log .Trace ("Doing: DeletedBranchesCleanup" )
510
510
511
511
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 ))
513
513
if err != nil {
514
514
log .Error ("DeletedBranchesCleanup: %v" , err )
515
515
}
@@ -526,19 +526,19 @@ type RenamedBranch struct {
526
526
}
527
527
528
528
// 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 ) {
530
530
branch = & RenamedBranch {
531
531
RepoID : repoID ,
532
532
From : from ,
533
533
}
534
- exist , err = db .GetEngine (db . DefaultContext ).Get (branch )
534
+ exist , err = db .GetEngine (ctx ).Get (branch )
535
535
536
536
return branch , exist , err
537
537
}
538
538
539
539
// 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 )
542
542
if err != nil {
543
543
return err
544
544
}
0 commit comments