Skip to content

Commit 6d5f307

Browse files
committed
Remove db.DefaultContext usage in routers, use ctx directly
1 parent 80fd255 commit 6d5f307

25 files changed

+55
-65
lines changed

routers/api/v1/org/org.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func Edit(ctx *context.APIContext) {
346346
if form.RepoAdminChangeTeamAccess != nil {
347347
org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess
348348
}
349-
if err := user_model.UpdateUserCols(db.DefaultContext, org.AsUser(),
349+
if err := user_model.UpdateUserCols(ctx, org.AsUser(),
350350
"full_name", "description", "website", "location",
351351
"visibility", "repo_admin_change_team_access",
352352
); err != nil {

routers/api/v1/repo/issue_stopwatch.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net/http"
1010

1111
"code.gitea.io/gitea/models"
12-
"code.gitea.io/gitea/models/db"
1312
"code.gitea.io/gitea/modules/context"
1413
"code.gitea.io/gitea/modules/convert"
1514
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -56,7 +55,7 @@ func StartIssueStopwatch(ctx *context.APIContext) {
5655
return
5756
}
5857

59-
if err := models.CreateIssueStopwatch(db.DefaultContext, ctx.Doer, issue); err != nil {
58+
if err := models.CreateIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
6059
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
6160
return
6261
}
@@ -105,7 +104,7 @@ func StopIssueStopwatch(ctx *context.APIContext) {
105104
return
106105
}
107106

108-
if err := models.FinishIssueStopwatch(db.DefaultContext, ctx.Doer, issue); err != nil {
107+
if err := models.FinishIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
109108
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
110109
return
111110
}

routers/api/v1/repo/key.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func ListDeployKeys(ctx *context.APIContext) {
8787
Fingerprint: ctx.FormString("fingerprint"),
8888
}
8989

90-
keys, err := asymkey_model.ListDeployKeys(db.DefaultContext, opts)
90+
keys, err := asymkey_model.ListDeployKeys(ctx, opts)
9191
if err != nil {
9292
ctx.InternalServerError(err)
9393
return
@@ -144,7 +144,7 @@ func GetDeployKey(ctx *context.APIContext) {
144144
// "200":
145145
// "$ref": "#/responses/DeployKey"
146146

147-
key, err := asymkey_model.GetDeployKeyByID(db.DefaultContext, ctx.ParamsInt64(":id"))
147+
key, err := asymkey_model.GetDeployKeyByID(ctx, ctx.ParamsInt64(":id"))
148148
if err != nil {
149149
if asymkey_model.IsErrDeployKeyNotExist(err) {
150150
ctx.NotFound()

routers/api/v1/repo/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func Search(ctx *context.APIContext) {
217217

218218
results := make([]*api.Repository, len(repos))
219219
for i, repo := range repos {
220-
if err = repo.GetOwner(db.DefaultContext); err != nil {
220+
if err = repo.GetOwner(ctx); err != nil {
221221
ctx.JSON(http.StatusInternalServerError, api.SearchError{
222222
OK: false,
223223
Error: err.Error(),

routers/api/v1/user/gpg_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
func listGPGKeys(ctx *context.APIContext, uid int64, listOptions db.ListOptions) {
21-
keys, err := asymkey_model.ListGPGKeys(db.DefaultContext, uid, listOptions)
21+
keys, err := asymkey_model.ListGPGKeys(ctx, uid, listOptions)
2222
if err != nil {
2323
ctx.Error(http.StatusInternalServerError, "ListGPGKeys", err)
2424
return

routers/api/v1/user/repo.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"net/http"
99

1010
"code.gitea.io/gitea/models"
11-
"code.gitea.io/gitea/models/db"
1211
"code.gitea.io/gitea/models/perm"
1312
user_model "code.gitea.io/gitea/models/user"
1413
"code.gitea.io/gitea/modules/context"
@@ -124,7 +123,7 @@ func ListMyRepos(ctx *context.APIContext) {
124123

125124
results := make([]*api.Repository, len(repos))
126125
for i, repo := range repos {
127-
if err = repo.GetOwner(db.DefaultContext); err != nil {
126+
if err = repo.GetOwner(ctx); err != nil {
128127
ctx.Error(http.StatusInternalServerError, "GetOwner", err)
129128
return
130129
}

routers/api/v1/utils/hook.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net/http"
1010
"strings"
1111

12-
"code.gitea.io/gitea/models/db"
1312
"code.gitea.io/gitea/models/webhook"
1413
"code.gitea.io/gitea/modules/context"
1514
"code.gitea.io/gitea/modules/convert"
@@ -164,7 +163,7 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
164163
if err := w.UpdateEvent(); err != nil {
165164
ctx.Error(http.StatusInternalServerError, "UpdateEvent", err)
166165
return nil, false
167-
} else if err := webhook.CreateWebhook(db.DefaultContext, w); err != nil {
166+
} else if err := webhook.CreateWebhook(ctx, w); err != nil {
168167
ctx.Error(http.StatusInternalServerError, "CreateWebhook", err)
169168
return nil, false
170169
}

routers/web/auth/auth.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func resetLocale(ctx *context.Context, u *user_model.User) error {
107107
// If the user does not have a locale set, we save the current one.
108108
if len(u.Language) == 0 {
109109
u.Language = ctx.Locale.Language()
110-
if err := user_model.UpdateUserCols(db.DefaultContext, u, "language"); err != nil {
110+
if err := user_model.UpdateUserCols(ctx, u, "language"); err != nil {
111111
return err
112112
}
113113
}
@@ -333,7 +333,7 @@ func handleSignInFull(ctx *context.Context, u *user_model.User, remember, obeyRe
333333
// If the user does not have a locale set, we save the current one.
334334
if len(u.Language) == 0 {
335335
u.Language = ctx.Locale.Language()
336-
if err := user_model.UpdateUserCols(db.DefaultContext, u, "language"); err != nil {
336+
if err := user_model.UpdateUserCols(ctx, u, "language"); err != nil {
337337
ctx.ServerError("UpdateUserCols Language", fmt.Errorf("Error updating user language [user: %d, locale: %s]", u.ID, u.Language))
338338
return setting.AppSubURL + "/"
339339
}
@@ -350,7 +350,7 @@ func handleSignInFull(ctx *context.Context, u *user_model.User, remember, obeyRe
350350

351351
// Register last login
352352
u.SetLastLogin()
353-
if err := user_model.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil {
353+
if err := user_model.UpdateUserCols(ctx, u, "last_login_unix"); err != nil {
354354
ctx.ServerError("UpdateUserCols", err)
355355
return setting.AppSubURL + "/"
356356
}
@@ -606,7 +606,7 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth.
606606
u.IsAdmin = true
607607
u.IsActive = true
608608
u.SetLastLogin()
609-
if err := user_model.UpdateUserCols(db.DefaultContext, u, "is_admin", "is_active", "last_login_unix"); err != nil {
609+
if err := user_model.UpdateUserCols(ctx, u, "is_admin", "is_active", "last_login_unix"); err != nil {
610610
ctx.ServerError("UpdateUser", err)
611611
return
612612
}
@@ -733,7 +733,7 @@ func handleAccountActivation(ctx *context.Context, user *user_model.User) {
733733
ctx.ServerError("UpdateUser", err)
734734
return
735735
}
736-
if err := user_model.UpdateUserCols(db.DefaultContext, user, "is_active", "rands"); err != nil {
736+
if err := user_model.UpdateUserCols(ctx, user, "is_active", "rands"); err != nil {
737737
if user_model.IsErrUserNotExist(err) {
738738
ctx.NotFound("UpdateUserCols", err)
739739
} else {

routers/web/auth/oauth.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616

1717
"code.gitea.io/gitea/models"
1818
"code.gitea.io/gitea/models/auth"
19-
"code.gitea.io/gitea/models/db"
2019
user_model "code.gitea.io/gitea/models/user"
2120
"code.gitea.io/gitea/modules/base"
2221
"code.gitea.io/gitea/modules/context"
@@ -1021,7 +1020,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model
10211020
cols = append(cols, "is_admin", "is_restricted")
10221021
}
10231022

1024-
if err := user_model.UpdateUserCols(db.DefaultContext, u, cols...); err != nil {
1023+
if err := user_model.UpdateUserCols(ctx, u, cols...); err != nil {
10251024
ctx.ServerError("UpdateUserCols", err)
10261025
return
10271026
}
@@ -1048,7 +1047,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model
10481047

10491048
changed := setUserGroupClaims(source, u, &gothUser)
10501049
if changed {
1051-
if err := user_model.UpdateUserCols(db.DefaultContext, u, "is_admin", "is_restricted"); err != nil {
1050+
if err := user_model.UpdateUserCols(ctx, u, "is_admin", "is_restricted"); err != nil {
10521051
ctx.ServerError("UpdateUserCols", err)
10531052
return
10541053
}

routers/web/auth/password.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net/http"
1010

1111
"code.gitea.io/gitea/models/auth"
12-
"code.gitea.io/gitea/models/db"
1312
user_model "code.gitea.io/gitea/models/user"
1413
"code.gitea.io/gitea/modules/base"
1514
"code.gitea.io/gitea/modules/context"
@@ -232,7 +231,7 @@ func ResetPasswdPost(ctx *context.Context) {
232231
return
233232
}
234233
u.MustChangePassword = false
235-
if err := user_model.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil {
234+
if err := user_model.UpdateUserCols(ctx, u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil {
236235
ctx.ServerError("UpdateUser", err)
237236
return
238237
}
@@ -327,7 +326,7 @@ func MustChangePasswordPost(ctx *context.Context) {
327326

328327
u.MustChangePassword = false
329328

330-
if err := user_model.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil {
329+
if err := user_model.UpdateUserCols(ctx, u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil {
331330
ctx.ServerError("UpdateUser", err)
332331
return
333332
}

routers/web/org/org_labels.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func InitializeLabels(ctx *context.Context) {
100100
return
101101
}
102102

103-
if err := models.InitializeLabels(db.DefaultContext, ctx.Org.Organization.ID, form.TemplateName, true); err != nil {
103+
if err := models.InitializeLabels(ctx, ctx.Org.Organization.ID, form.TemplateName, true); err != nil {
104104
if models.IsErrIssueLabelTemplateLoad(err) {
105105
originalErr := err.(models.ErrIssueLabelTemplateLoad).OriginalError
106106
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))

routers/web/repo/compare.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"strings"
1919

2020
"code.gitea.io/gitea/models"
21-
"code.gitea.io/gitea/models/db"
2221
repo_model "code.gitea.io/gitea/models/repo"
2322
"code.gitea.io/gitea/models/unit"
2423
user_model "code.gitea.io/gitea/models/user"
@@ -269,7 +268,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
269268
}
270269
return nil
271270
}
272-
if err := ci.HeadRepo.GetOwner(db.DefaultContext); err != nil {
271+
if err := ci.HeadRepo.GetOwner(ctx); err != nil {
273272
if user_model.IsErrUserNotExist(err) {
274273
ctx.NotFound("GetUserByName", nil)
275274
} else {

routers/web/repo/http.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
"code.gitea.io/gitea/models"
2323
"code.gitea.io/gitea/models/auth"
24-
"code.gitea.io/gitea/models/db"
2524
"code.gitea.io/gitea/models/perm"
2625
repo_model "code.gitea.io/gitea/models/repo"
2726
"code.gitea.io/gitea/models/unit"
@@ -159,7 +158,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) {
159158

160159
// don't allow anonymous pulls if organization is not public
161160
if isPublicPull {
162-
if err := repo.GetOwner(db.DefaultContext); err != nil {
161+
if err := repo.GetOwner(ctx); err != nil {
163162
ctx.ServerError("GetOwner", err)
164163
return
165164
}

routers/web/repo/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
19441944
}
19451945
if reviewID < 0 {
19461946
// negative reviewIDs represent team requests
1947-
if err := issue.Repo.GetOwner(db.DefaultContext); err != nil {
1947+
if err := issue.Repo.GetOwner(ctx); err != nil {
19481948
ctx.ServerError("issue.Repo.GetOwner", err)
19491949
return
19501950
}

routers/web/repo/issue_content_history.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"strings"
1313

1414
"code.gitea.io/gitea/models"
15-
"code.gitea.io/gitea/models/db"
1615
issuesModel "code.gitea.io/gitea/models/issues"
1716
"code.gitea.io/gitea/models/unit"
1817
"code.gitea.io/gitea/modules/context"
@@ -32,7 +31,7 @@ func GetContentHistoryOverview(ctx *context.Context) {
3231
}
3332

3433
lang := ctx.Locale.Language()
35-
editedHistoryCountMap, _ := issuesModel.QueryIssueContentHistoryEditedCountMap(db.DefaultContext, issue.ID)
34+
editedHistoryCountMap, _ := issuesModel.QueryIssueContentHistoryEditedCountMap(ctx, issue.ID)
3635
ctx.JSON(http.StatusOK, map[string]interface{}{
3736
"i18n": map[string]interface{}{
3837
"textEdited": i18n.Tr(lang, "repo.issues.content_history.edited"),
@@ -52,7 +51,7 @@ func GetContentHistoryList(ctx *context.Context) {
5251
return
5352
}
5453

55-
items, _ := issuesModel.FetchIssueContentHistoryList(db.DefaultContext, issue.ID, commentID)
54+
items, _ := issuesModel.FetchIssueContentHistoryList(ctx, issue.ID, commentID)
5655

5756
// render history list to HTML for frontend dropdown items: (name, value)
5857
// name is HTML of "avatar + userName + userAction + timeSince"
@@ -119,7 +118,7 @@ func GetContentHistoryDetail(ctx *context.Context) {
119118
}
120119

121120
historyID := ctx.FormInt64("history_id")
122-
history, prevHistory, err := issuesModel.GetIssueContentHistoryAndPrev(db.DefaultContext, historyID)
121+
history, prevHistory, err := issuesModel.GetIssueContentHistoryAndPrev(ctx, historyID)
123122
if err != nil {
124123
ctx.JSON(http.StatusNotFound, map[string]interface{}{
125124
"message": "Can not find the content history",
@@ -196,7 +195,7 @@ func SoftDeleteContentHistory(ctx *context.Context) {
196195
return
197196
}
198197
}
199-
if history, err = issuesModel.GetIssueContentHistoryByID(db.DefaultContext, historyID); err != nil {
198+
if history, err = issuesModel.GetIssueContentHistoryByID(ctx, historyID); err != nil {
200199
log.Error("can not get issue content history %v. err=%v", historyID, err)
201200
return
202201
}
@@ -209,7 +208,7 @@ func SoftDeleteContentHistory(ctx *context.Context) {
209208
return
210209
}
211210

212-
err = issuesModel.SoftDeleteIssueContentHistory(db.DefaultContext, historyID)
211+
err = issuesModel.SoftDeleteIssueContentHistory(ctx, historyID)
213212
log.Debug("soft delete issue content history. issue=%d, comment=%d, history=%d", issue.ID, commentID, historyID)
214213
ctx.JSON(http.StatusOK, map[string]interface{}{
215214
"ok": err == nil,

routers/web/repo/issue_label.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func InitializeLabels(ctx *context.Context) {
3939
return
4040
}
4141

42-
if err := models.InitializeLabels(db.DefaultContext, ctx.Repo.Repository.ID, form.TemplateName, false); err != nil {
42+
if err := models.InitializeLabels(ctx, ctx.Repo.Repository.ID, form.TemplateName, false); err != nil {
4343
if models.IsErrIssueLabelTemplateLoad(err) {
4444
originalErr := err.(models.ErrIssueLabelTemplateLoad).OriginalError
4545
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))

routers/web/repo/pull.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository {
9999
return nil
100100
}
101101

102-
if err := forkRepo.GetOwner(db.DefaultContext); err != nil {
102+
if err := forkRepo.GetOwner(ctx); err != nil {
103103
ctx.ServerError("GetOwner", err)
104104
return nil
105105
}
@@ -1255,7 +1255,7 @@ func CleanUpPullRequest(ctx *context.Context) {
12551255
} else if err = pr.LoadBaseRepo(); err != nil {
12561256
ctx.ServerError("LoadBaseRepo", err)
12571257
return
1258-
} else if err = pr.HeadRepo.GetOwner(db.DefaultContext); err != nil {
1258+
} else if err = pr.HeadRepo.GetOwner(ctx); err != nil {
12591259
ctx.ServerError("HeadRepo.GetOwner", err)
12601260
return
12611261
}

routers/web/repo/repo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func RedirectDownload(ctx *context.Context) {
353353
)
354354
tagNames := []string{vTag}
355355
curRepo := ctx.Repo.Repository
356-
releases, err := models.GetReleasesByRepoIDAndNames(db.DefaultContext, curRepo.ID, tagNames)
356+
releases, err := models.GetReleasesByRepoIDAndNames(ctx, curRepo.ID, tagNames)
357357
if err != nil {
358358
if repo_model.IsErrAttachmentNotExist(err) {
359359
ctx.Error(http.StatusNotFound)
@@ -394,7 +394,7 @@ func Download(ctx *context.Context) {
394394
return
395395
}
396396

397-
archiver, err := repo_model.GetRepoArchiver(db.DefaultContext, aReq.RepoID, aReq.Type, aReq.CommitID)
397+
archiver, err := repo_model.GetRepoArchiver(ctx, aReq.RepoID, aReq.Type, aReq.CommitID)
398398
if err != nil {
399399
ctx.ServerError("models.GetRepoArchiver", err)
400400
return
@@ -424,7 +424,7 @@ func Download(ctx *context.Context) {
424424
return
425425
}
426426
times++
427-
archiver, err = repo_model.GetRepoArchiver(db.DefaultContext, aReq.RepoID, aReq.Type, aReq.CommitID)
427+
archiver, err = repo_model.GetRepoArchiver(ctx, aReq.RepoID, aReq.Type, aReq.CommitID)
428428
if err != nil {
429429
ctx.ServerError("archiver_service.StartArchive", err)
430430
return
@@ -480,7 +480,7 @@ func InitiateDownload(ctx *context.Context) {
480480
return
481481
}
482482

483-
archiver, err := repo_model.GetRepoArchiver(db.DefaultContext, aReq.RepoID, aReq.Type, aReq.CommitID)
483+
archiver, err := repo_model.GetRepoArchiver(ctx, aReq.RepoID, aReq.Type, aReq.CommitID)
484484
if err != nil {
485485
ctx.ServerError("archiver_service.StartArchive", err)
486486
return

routers/web/repo/setting.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ func SettingsPost(ctx *context.Context) {
595595
ctx.Error(http.StatusNotFound)
596596
return
597597
}
598-
if err := repo.GetOwner(db.DefaultContext); err != nil {
598+
if err := repo.GetOwner(ctx); err != nil {
599599
ctx.ServerError("Convert Fork", err)
600600
return
601601
}
@@ -1055,7 +1055,7 @@ func DeployKeys(ctx *context.Context) {
10551055
ctx.Data["PageIsSettingsKeys"] = true
10561056
ctx.Data["DisableSSH"] = setting.SSH.Disabled
10571057

1058-
keys, err := asymkey_model.ListDeployKeys(db.DefaultContext, &asymkey_model.ListDeployKeysOptions{RepoID: ctx.Repo.Repository.ID})
1058+
keys, err := asymkey_model.ListDeployKeys(ctx, &asymkey_model.ListDeployKeysOptions{RepoID: ctx.Repo.Repository.ID})
10591059
if err != nil {
10601060
ctx.ServerError("ListDeployKeys", err)
10611061
return
@@ -1071,7 +1071,7 @@ func DeployKeysPost(ctx *context.Context) {
10711071
ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys")
10721072
ctx.Data["PageIsSettingsKeys"] = true
10731073

1074-
keys, err := asymkey_model.ListDeployKeys(db.DefaultContext, &asymkey_model.ListDeployKeysOptions{RepoID: ctx.Repo.Repository.ID})
1074+
keys, err := asymkey_model.ListDeployKeys(ctx, &asymkey_model.ListDeployKeysOptions{RepoID: ctx.Repo.Repository.ID})
10751075
if err != nil {
10761076
ctx.ServerError("ListDeployKeys", err)
10771077
return

0 commit comments

Comments
 (0)