summaryrefslogtreecommitdiffstats
path: root/models/git
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-12-03 10:48:26 +0800
committerGitHub <noreply@github.com>2022-12-03 10:48:26 +0800
commit0a7d3ff786508284224ada17956a65bb759d9265 (patch)
tree4860fca95c1432ab59c6723ee2b053b1c7d6779d /models/git
parent8698458f48eafeab21014db544aa7160368856e1 (diff)
downloadgitea-0a7d3ff786508284224ada17956a65bb759d9265.tar.gz
gitea-0a7d3ff786508284224ada17956a65bb759d9265.zip
refactor some functions to support ctx as first parameter (#21878)
Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models/git')
-rw-r--r--models/git/branches.go19
-rw-r--r--models/git/branches_test.go4
-rw-r--r--models/git/commit_status.go4
-rw-r--r--models/git/lfs_lock.go2
4 files changed, 12 insertions, 17 deletions
diff --git a/models/git/branches.go b/models/git/branches.go
index 87246ed149..c02ab0a888 100644
--- a/models/git/branches.go
+++ b/models/git/branches.go
@@ -73,10 +73,10 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
}
if !protectBranch.EnableWhitelist {
- if user, err := user_model.GetUserByID(userID); err != nil {
+ if user, err := user_model.GetUserByID(db.DefaultContext, userID); err != nil {
log.Error("GetUserByID: %v", err)
return false
- } else if repo, err := repo_model.GetRepositoryByID(protectBranch.RepoID); err != nil {
+ } else if repo, err := repo_model.GetRepositoryByID(db.DefaultContext, protectBranch.RepoID); err != nil {
log.Error("repo_model.GetRepositoryByID: %v", err)
return false
} else if writeAccess, err := access_model.HasAccessUnit(db.DefaultContext, user, repo, unit.TypeCode, perm.AccessModeWrite); err != nil {
@@ -127,13 +127,8 @@ func IsUserMergeWhitelisted(ctx context.Context, protectBranch *ProtectedBranch,
}
// IsUserOfficialReviewer check if user is official reviewer for the branch (counts towards required approvals)
-func IsUserOfficialReviewer(protectBranch *ProtectedBranch, user *user_model.User) (bool, error) {
- return IsUserOfficialReviewerCtx(db.DefaultContext, protectBranch, user)
-}
-
-// IsUserOfficialReviewerCtx check if user is official reviewer for the branch (counts towards required approvals)
-func IsUserOfficialReviewerCtx(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error) {
- repo, err := repo_model.GetRepositoryByIDCtx(ctx, protectBranch.RepoID)
+func IsUserOfficialReviewer(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error) {
+ repo, err := repo_model.GetRepositoryByID(ctx, protectBranch.RepoID)
if err != nil {
return false, err
}
@@ -375,7 +370,7 @@ func updateUserWhitelist(ctx context.Context, repo *repo_model.Repository, curre
whitelist = make([]int64, 0, len(newWhitelist))
for _, userID := range newWhitelist {
- user, err := user_model.GetUserByIDCtx(ctx, userID)
+ user, err := user_model.GetUserByID(ctx, userID)
if err != nil {
return nil, fmt.Errorf("GetUserByID [user_id: %d, repo_id: %d]: %w", userID, repo.ID, err)
}
@@ -494,8 +489,8 @@ func RemoveDeletedBranchByID(repoID, id int64) (err error) {
// LoadUser loads the user that deleted the branch
// When there's no user found it returns a user_model.NewGhostUser
-func (deletedBranch *DeletedBranch) LoadUser() {
- user, err := user_model.GetUserByID(deletedBranch.DeletedByID)
+func (deletedBranch *DeletedBranch) LoadUser(ctx context.Context) {
+ user, err := user_model.GetUserByID(ctx, deletedBranch.DeletedByID)
if err != nil {
user = user_model.NewGhostUser()
}
diff --git a/models/git/branches_test.go b/models/git/branches_test.go
index 038a4f6686..56f416622e 100644
--- a/models/git/branches_test.go
+++ b/models/git/branches_test.go
@@ -48,13 +48,13 @@ func TestDeletedBranchLoadUser(t *testing.T) {
branch := getDeletedBranch(t, firstBranch)
assert.Nil(t, branch.DeletedBy)
- branch.LoadUser()
+ branch.LoadUser(db.DefaultContext)
assert.NotNil(t, branch.DeletedBy)
assert.Equal(t, "user1", branch.DeletedBy.Name)
branch = getDeletedBranch(t, secondBranch)
assert.Nil(t, branch.DeletedBy)
- branch.LoadUser()
+ branch.LoadUser(db.DefaultContext)
assert.NotNil(t, branch.DeletedBy)
assert.Equal(t, "Ghost", branch.DeletedBy.Name)
}
diff --git a/models/git/commit_status.go b/models/git/commit_status.go
index 928f1771fe..0fb0bc66af 100644
--- a/models/git/commit_status.go
+++ b/models/git/commit_status.go
@@ -114,13 +114,13 @@ func GetNextCommitStatusIndex(ctx context.Context, repoID int64, sha string) (in
func (status *CommitStatus) loadAttributes(ctx context.Context) (err error) {
if status.Repo == nil {
- status.Repo, err = repo_model.GetRepositoryByIDCtx(ctx, status.RepoID)
+ status.Repo, err = repo_model.GetRepositoryByID(ctx, status.RepoID)
if err != nil {
return fmt.Errorf("getRepositoryByID [%d]: %w", status.RepoID, err)
}
}
if status.Creator == nil && status.CreatorID > 0 {
- status.Creator, err = user_model.GetUserByIDCtx(ctx, status.CreatorID)
+ status.Creator, err = user_model.GetUserByID(ctx, status.CreatorID)
if err != nil {
return fmt.Errorf("getUserByID [%d]: %w", status.CreatorID, err)
}
diff --git a/models/git/lfs_lock.go b/models/git/lfs_lock.go
index 3d765ea22b..dc5b0a2ced 100644
--- a/models/git/lfs_lock.go
+++ b/models/git/lfs_lock.go
@@ -167,7 +167,7 @@ func CheckLFSAccessForRepo(ctx context.Context, ownerID int64, repo *repo_model.
if ownerID == 0 {
return ErrLFSUnauthorizedAction{repo.ID, "undefined", mode}
}
- u, err := user_model.GetUserByIDCtx(ctx, ownerID)
+ u, err := user_model.GetUserByID(ctx, ownerID)
if err != nil {
return err
}