1
0
Fork 0
forked from forgejo/forgejo

Use ctx instead of db.DefaultContext in some packages(routers/services/modules) (#19163)

* Remove `db.DefaultContext` usage in routers, use `ctx` directly

* Use `ctx` directly if there is one, remove some `db.DefaultContext` in `services`

* Use ctx instead of db.DefaultContext for `cmd` and some `modules` packages

* fix incorrect context usage
This commit is contained in:
wxiaoguang 2022-03-22 23:22:54 +08:00 committed by GitHub
parent 2b55422cd7
commit 7a550b3af2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 117 additions and 124 deletions

View file

@ -346,7 +346,7 @@ func Edit(ctx *context.APIContext) {
if form.RepoAdminChangeTeamAccess != nil {
org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess
}
if err := user_model.UpdateUserCols(db.DefaultContext, org.AsUser(),
if err := user_model.UpdateUserCols(ctx, org.AsUser(),
"full_name", "description", "website", "location",
"visibility", "repo_admin_change_team_access",
); err != nil {

View file

@ -9,7 +9,6 @@ import (
"net/http"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/routers/api/v1/utils"
@ -56,7 +55,7 @@ func StartIssueStopwatch(ctx *context.APIContext) {
return
}
if err := models.CreateIssueStopwatch(db.DefaultContext, ctx.Doer, issue); err != nil {
if err := models.CreateIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
return
}
@ -105,7 +104,7 @@ func StopIssueStopwatch(ctx *context.APIContext) {
return
}
if err := models.FinishIssueStopwatch(db.DefaultContext, ctx.Doer, issue); err != nil {
if err := models.FinishIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
return
}

View file

@ -87,7 +87,7 @@ func ListDeployKeys(ctx *context.APIContext) {
Fingerprint: ctx.FormString("fingerprint"),
}
keys, err := asymkey_model.ListDeployKeys(db.DefaultContext, opts)
keys, err := asymkey_model.ListDeployKeys(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return

View file

@ -217,7 +217,7 @@ func Search(ctx *context.APIContext) {
results := make([]*api.Repository, len(repos))
for i, repo := range repos {
if err = repo.GetOwner(db.DefaultContext); err != nil {
if err = repo.GetOwner(ctx); err != nil {
ctx.JSON(http.StatusInternalServerError, api.SearchError{
OK: false,
Error: err.Error(),

View file

@ -18,7 +18,7 @@ import (
)
func listGPGKeys(ctx *context.APIContext, uid int64, listOptions db.ListOptions) {
keys, err := asymkey_model.ListGPGKeys(db.DefaultContext, uid, listOptions)
keys, err := asymkey_model.ListGPGKeys(ctx, uid, listOptions)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ListGPGKeys", err)
return

View file

@ -8,7 +8,6 @@ import (
"net/http"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/perm"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
@ -124,7 +123,7 @@ func ListMyRepos(ctx *context.APIContext) {
results := make([]*api.Repository, len(repos))
for i, repo := range repos {
if err = repo.GetOwner(db.DefaultContext); err != nil {
if err = repo.GetOwner(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "GetOwner", err)
return
}

View file

@ -9,7 +9,6 @@ import (
"net/http"
"strings"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
@ -164,7 +163,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
if err := w.UpdateEvent(); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateEvent", err)
return nil, false
} else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
} else if err := webhook.CreateWebhook(ctx, w); err != nil {
ctx.Error(http.StatusInternalServerError, "CreateWebhook", err)
return nil, false
}