diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-05-20 22:08:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-20 22:08:52 +0800 |
commit | fd7d83ace60258acf7139c4c787aa8af75b7ba8c (patch) | |
tree | 50038348ec10485f72344f3ac80324e04abc1283 /modules/context/repo.go | |
parent | d81e31ad7826a81fc7139f329f250594610a274b (diff) | |
download | gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.tar.gz gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.zip |
Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context
* remove some unnecessary wrap functions
Diffstat (limited to 'modules/context/repo.go')
-rw-r--r-- | modules/context/repo.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go index eb773dfb2e..539b111f15 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -16,6 +16,7 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" access_model "code.gitea.io/gitea/models/perm/access" repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" @@ -116,7 +117,7 @@ type CanCommitToBranchResults struct { // CanCommitToBranch returns true if repository is editable and user has proper access level // and branch is not protected for push func (r *Repository) CanCommitToBranch(ctx context.Context, doer *user_model.User) (CanCommitToBranchResults, error) { - protectedBranch, err := models.GetProtectedBranchBy(r.Repository.ID, r.BranchName) + protectedBranch, err := models.GetProtectedBranchBy(ctx, r.Repository.ID, r.BranchName) if err != nil { return CanCommitToBranchResults{}, err } @@ -159,7 +160,7 @@ func (r *Repository) CanUseTimetracker(issue *models.Issue, user *user_model.Use // Checking for following: // 1. Is timetracker enabled // 2. Is the user a contributor, admin, poster or assignee and do the repository policies require this? - isAssigned, _ := models.IsUserAssignedToIssue(issue, user) + isAssigned, _ := models.IsUserAssignedToIssue(db.DefaultContext, issue, user) return r.Repository.IsTimetrackerEnabled() && (!r.Repository.AllowOnlyContributorsToTrackTime() || r.Permission.CanWriteIssuesOrPulls(issue.IsPull) || issue.IsPoster(user.ID) || isAssigned) } @@ -278,7 +279,7 @@ func RetrieveBaseRepo(ctx *Context, repo *repo_model.Repository) { // RetrieveTemplateRepo retrieves template repository used to generate this repository func RetrieveTemplateRepo(ctx *Context, repo *repo_model.Repository) { // Non-generated repository will not return error in this method. - templateRepo, err := repo_model.GetTemplateRepo(repo) + templateRepo, err := repo_model.GetTemplateRepo(ctx, repo) if err != nil { if repo_model.IsErrRepoNotExist(err) { repo.TemplateID = 0 @@ -385,11 +386,12 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) { return } if finishedMigrating { - ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID) + ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(ctx, repo.ID) if err != nil { ctx.ServerError("GetMirrorByRepoID", err) return } + ctx.Repo.Mirror.Repo = ctx.Repo.Repository ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval ctx.Data["Mirror"] = ctx.Repo.Mirror @@ -451,7 +453,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) { owner = ctx.Doer } else { - owner, err = user_model.GetUserByName(userName) + owner, err = user_model.GetUserByName(ctx, userName) if err != nil { if user_model.IsErrUserNotExist(err) { if ctx.FormString("go-get") == "1" { @@ -587,7 +589,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { if ctx.IsSigned { ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx.Doer.ID, repo.ID) - ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx.Doer.ID, repo.ID) + ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx, ctx.Doer.ID, repo.ID) } if repo.IsFork { |