diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-12-03 10:48:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-03 10:48:26 +0800 |
commit | 0a7d3ff786508284224ada17956a65bb759d9265 (patch) | |
tree | 4860fca95c1432ab59c6723ee2b053b1c7d6779d /routers/web/repo | |
parent | 8698458f48eafeab21014db544aa7160368856e1 (diff) | |
download | gitea-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 'routers/web/repo')
-rw-r--r-- | routers/web/repo/attachment.go | 2 | ||||
-rw-r--r-- | routers/web/repo/branch.go | 2 | ||||
-rw-r--r-- | routers/web/repo/compare.go | 4 | ||||
-rw-r--r-- | routers/web/repo/issue.go | 10 | ||||
-rw-r--r-- | routers/web/repo/pull.go | 10 | ||||
-rw-r--r-- | routers/web/repo/release.go | 4 | ||||
-rw-r--r-- | routers/web/repo/repo.go | 4 | ||||
-rw-r--r-- | routers/web/repo/view.go | 2 | ||||
-rw-r--r-- | routers/web/repo/webhook.go | 2 |
9 files changed, 20 insertions, 20 deletions
diff --git a/routers/web/repo/attachment.go b/routers/web/repo/attachment.go index d12fa60daf..656e40f878 100644 --- a/routers/web/repo/attachment.go +++ b/routers/web/repo/attachment.go @@ -94,7 +94,7 @@ func GetAttachment(ctx *context.Context) { return } - repository, unitType, err := repo_service.LinkedRepository(attach) + repository, unitType, err := repo_service.LinkedRepository(ctx, attach) if err != nil { ctx.ServerError("LinkedRepository", err) return diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index 61fb24d058..18bb06ed1a 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -337,7 +337,7 @@ func getDeletedBranches(ctx *context.Context) ([]*Branch, error) { } for i := range deletedBranches { - deletedBranches[i].LoadUser() + deletedBranches[i].LoadUser(ctx) branches = append(branches, &Branch{ Name: deletedBranches[i].Name, IsDeleted: true, diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index a9d6eea1eb..b2d8f8645d 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -269,7 +269,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { ci.HeadRepo = baseRepo } } else { - ci.HeadRepo, err = repo_model.GetRepositoryByOwnerAndName(headInfosSplit[0], headInfosSplit[1]) + ci.HeadRepo, err = repo_model.GetRepositoryByOwnerAndName(ctx, headInfosSplit[0], headInfosSplit[1]) if err != nil { if repo_model.IsErrRepoNotExist(err) { ctx.NotFound("GetRepositoryByOwnerAndName", nil) @@ -339,7 +339,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { // forked from var rootRepo *repo_model.Repository if baseRepo.IsFork { - err = baseRepo.GetBaseRepo() + err = baseRepo.GetBaseRepo(ctx) if err != nil { if !repo_model.IsErrRepoNotExist(err) { ctx.ServerError("Unable to find root repo", err) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 2a0a849b5b..a531e83206 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1007,7 +1007,7 @@ func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull // Check if the passed assignees actually exists and is assignable for _, aID := range assigneeIDs { - assignee, err := user_model.GetUserByID(aID) + assignee, err := user_model.GetUserByID(ctx, aID) if err != nil { ctx.ServerError("GetUserByID", err) return nil, nil, 0, 0 @@ -1679,7 +1679,7 @@ func ViewIssue(ctx *context.Context) { } ctx.Data["DefaultSquashMergeMessage"] = defaultSquashMergeMessage - if err = pull.LoadProtectedBranch(); err != nil { + if err = pull.LoadProtectedBranch(ctx); err != nil { ctx.ServerError("LoadProtectedBranch", err) return } @@ -2062,7 +2062,7 @@ func UpdateIssueAssignee(ctx *context.Context) { return } default: - assignee, err := user_model.GetUserByID(assigneeID) + assignee, err := user_model.GetUserByID(ctx, assigneeID) if err != nil { ctx.ServerError("GetUserByID", err) return @@ -2173,7 +2173,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { continue } - reviewer, err := user_model.GetUserByID(reviewID) + reviewer, err := user_model.GetUserByID(ctx, reviewID) if err != nil { if user_model.IsErrUserNotExist(err) { log.Warn( @@ -3027,7 +3027,7 @@ func filterXRefComments(ctx *context.Context, issue *issues_model.Issue) error { if issues_model.CommentTypeIsRef(c.Type) && c.RefRepoID != issue.RepoID && c.RefRepoID != 0 { var err error // Set RefRepo for description in template - c.RefRepo, err = repo_model.GetRepositoryByID(c.RefRepoID) + c.RefRepo, err = repo_model.GetRepositoryByID(ctx, c.RefRepoID) if err != nil { return err } diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 682bc64ca2..bea6bfe433 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -78,7 +78,7 @@ var pullRequestTemplateCandidates = []string{ } func getRepository(ctx *context.Context, repoID int64) *repo_model.Repository { - repo, err := repo_model.GetRepositoryByID(repoID) + repo, err := repo_model.GetRepositoryByID(ctx, repoID) if err != nil { if repo_model.IsErrRepoNotExist(err) { ctx.NotFound("GetRepositoryByID", nil) @@ -159,7 +159,7 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository { if !traverseParentRepo.IsFork { break } - traverseParentRepo, err = repo_model.GetRepositoryByID(traverseParentRepo.ForkID) + traverseParentRepo, err = repo_model.GetRepositoryByID(ctx, traverseParentRepo.ForkID) if err != nil { ctx.ServerError("GetRepositoryByID", err) return nil @@ -227,7 +227,7 @@ func ForkPost(ctx *context.Context) { if !traverseParentRepo.IsFork { break } - traverseParentRepo, err = repo_model.GetRepositoryByID(traverseParentRepo.ForkID) + traverseParentRepo, err = repo_model.GetRepositoryByID(ctx, traverseParentRepo.ForkID) if err != nil { ctx.ServerError("GetRepositoryByID", err) return @@ -427,7 +427,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C setMergeTarget(ctx, pull) - if err := pull.LoadProtectedBranch(); err != nil { + if err := pull.LoadProtectedBranch(ctx); err != nil { ctx.ServerError("LoadProtectedBranch", err) return nil } @@ -739,7 +739,7 @@ func ViewPullFiles(ctx *context.Context) { return } - if err = pull.LoadProtectedBranch(); err != nil { + if err = pull.LoadProtectedBranch(ctx); err != nil { ctx.ServerError("LoadProtectedBranch", err) return } diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index 9ef44eb582..0aa1fde8de 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -156,7 +156,7 @@ func releasesOrTags(ctx *context.Context, isTagList bool) { for _, r := range releases { if r.Publisher, ok = cacheUsers[r.PublisherID]; !ok { - r.Publisher, err = user_model.GetUserByID(r.PublisherID) + r.Publisher, err = user_model.GetUserByID(ctx, r.PublisherID) if err != nil { if user_model.IsErrUserNotExist(err) { r.Publisher = user_model.NewGhostUser() @@ -223,7 +223,7 @@ func SingleRelease(ctx *context.Context) { return } - release.Publisher, err = user_model.GetUserByID(release.PublisherID) + release.Publisher, err = user_model.GetUserByID(ctx, release.PublisherID) if err != nil { if user_model.IsErrUserNotExist(err) { release.Publisher = user_model.NewGhostUser() diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 0a8a1eb4e8..c57564d334 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -83,7 +83,7 @@ func checkContextUser(ctx *context.Context, uid int64) *user_model.User { return ctx.Doer } - org, err := user_model.GetUserByID(uid) + org, err := user_model.GetUserByID(ctx, uid) if user_model.IsErrUserNotExist(err) { return ctx.Doer } @@ -149,7 +149,7 @@ func Create(ctx *context.Context) { ctx.Data["repo_template_name"] = ctx.Tr("repo.template_select") templateID := ctx.FormInt64("template_id") if templateID > 0 { - templateRepo, err := repo_model.GetRepositoryByID(templateID) + templateRepo, err := repo_model.GetRepositoryByID(ctx, templateID) if err == nil && access_model.CheckRepoUnitUser(ctx, templateRepo, ctxUser, unit.TypeCode) { ctx.Data["repo_template"] = templateID ctx.Data["repo_template_name"] = templateRepo.Name diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index c7f97410ff..fa4eb6d61f 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -457,7 +457,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st return } if lfsLock != nil { - u, err := user_model.GetUserByID(lfsLock.OwnerID) + u, err := user_model.GetUserByID(ctx, lfsLock.OwnerID) if err != nil { ctx.ServerError("GetTreePathLock", err) return diff --git a/routers/web/repo/webhook.go b/routers/web/repo/webhook.go index 677fbc92ed..18d71c6435 100644 --- a/routers/web/repo/webhook.go +++ b/routers/web/repo/webhook.go @@ -684,7 +684,7 @@ func TestWebhook(ctx *context.Context) { Commits: []*api.PayloadCommit{apiCommit}, TotalCommits: 1, HeadCommit: apiCommit, - Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone), + Repo: convert.ToRepo(ctx, ctx.Repo.Repository, perm.AccessModeNone), Pusher: apiUser, Sender: apiUser, } |