diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-03-22 16:22:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-22 16:22:54 +0100 |
commit | 7a550b3af20dad94cf468012a6b817b43b91c1ba (patch) | |
tree | 1b836eabf8e911f35d0446c0cdad053cb3572c79 /routers/api | |
parent | Fix the bug: deploy key with write access can not push (#19010) (diff) | |
download | forgejo-7a550b3af20dad94cf468012a6b817b43b91c1ba.tar.xz forgejo-7a550b3af20dad94cf468012a6b817b43b91c1ba.zip |
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
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/v1/org/org.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_stopwatch.go | 5 | ||||
-rw-r--r-- | routers/api/v1/repo/key.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 2 | ||||
-rw-r--r-- | routers/api/v1/user/gpg_key.go | 2 | ||||
-rw-r--r-- | routers/api/v1/user/repo.go | 3 | ||||
-rw-r--r-- | routers/api/v1/utils/hook.go | 3 |
7 files changed, 8 insertions, 11 deletions
diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index a920b49a84..63cc0e9d39 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -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 { diff --git a/routers/api/v1/repo/issue_stopwatch.go b/routers/api/v1/repo/issue_stopwatch.go index 19ee983b84..382f294346 100644 --- a/routers/api/v1/repo/issue_stopwatch.go +++ b/routers/api/v1/repo/issue_stopwatch.go @@ -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 } diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go index 568f92d7fb..0c780eb97d 100644 --- a/routers/api/v1/repo/key.go +++ b/routers/api/v1/repo/key.go @@ -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 diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 3bb32d75d2..d266b3f4f3 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -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(), diff --git a/routers/api/v1/user/gpg_key.go b/routers/api/v1/user/gpg_key.go index 5e98b21fb8..83122355d0 100644 --- a/routers/api/v1/user/gpg_key.go +++ b/routers/api/v1/user/gpg_key.go @@ -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 diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index 2b933bea15..683c300953 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -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 } diff --git a/routers/api/v1/utils/hook.go b/routers/api/v1/utils/hook.go index 1f0a35ce22..d4d4e05524 100644 --- a/routers/api/v1/utils/hook.go +++ b/routers/api/v1/utils/hook.go @@ -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 } |