1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-30 22:28:37 +00:00

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>
This commit is contained in:
Lunny Xiao
2022-12-03 10:48:26 +08:00
committed by GitHub
parent 8698458f48
commit 0a7d3ff786
145 changed files with 360 additions and 369 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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()

View File

@@ -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

View File

@@ -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

View File

@@ -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,
}