Skip to content

Commit 33e0b38

Browse files
authored
Rename context.Query to context.Form (#16562)
1 parent 3705168 commit 33e0b38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+394
-397
lines changed

modules/context/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func genAPILinks(curURL *url.URL, total, pageSize, curPage int) []string {
177177

178178
// SetLinkHeader sets pagination link header by given total number and page size.
179179
func (ctx *APIContext) SetLinkHeader(total, pageSize int) {
180-
links := genAPILinks(ctx.Req.URL, total, pageSize, ctx.QueryInt("page"))
180+
links := genAPILinks(ctx.Req.URL, total, pageSize, ctx.FormInt("page"))
181181

182182
if len(links) > 0 {
183183
ctx.Header().Set("Link", strings.Join(links, ","))

modules/context/context.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -287,41 +287,38 @@ func (ctx *Context) Header() http.Header {
287287
return ctx.Resp.Header()
288288
}
289289

290-
// FIXME: We should differ Query and Form, currently we just use form as query
291-
// Currently to be compatible with macaron, we keep it.
292-
293-
// Query returns request form as string with default
294-
func (ctx *Context) Query(key string, defaults ...string) string {
290+
// Form returns request form as string with default
291+
func (ctx *Context) Form(key string, defaults ...string) string {
295292
return (*Forms)(ctx.Req).MustString(key, defaults...)
296293
}
297294

298-
// QueryTrim returns request form as string with default and trimmed spaces
299-
func (ctx *Context) QueryTrim(key string, defaults ...string) string {
295+
// FormTrim returns request form as string with default and trimmed spaces
296+
func (ctx *Context) FormTrim(key string, defaults ...string) string {
300297
return (*Forms)(ctx.Req).MustTrimmed(key, defaults...)
301298
}
302299

303-
// QueryStrings returns request form as strings with default
304-
func (ctx *Context) QueryStrings(key string, defaults ...[]string) []string {
300+
// FormStrings returns request form as strings with default
301+
func (ctx *Context) FormStrings(key string, defaults ...[]string) []string {
305302
return (*Forms)(ctx.Req).MustStrings(key, defaults...)
306303
}
307304

308-
// QueryInt returns request form as int with default
309-
func (ctx *Context) QueryInt(key string, defaults ...int) int {
305+
// FormInt returns request form as int with default
306+
func (ctx *Context) FormInt(key string, defaults ...int) int {
310307
return (*Forms)(ctx.Req).MustInt(key, defaults...)
311308
}
312309

313-
// QueryInt64 returns request form as int64 with default
314-
func (ctx *Context) QueryInt64(key string, defaults ...int64) int64 {
310+
// FormInt64 returns request form as int64 with default
311+
func (ctx *Context) FormInt64(key string, defaults ...int64) int64 {
315312
return (*Forms)(ctx.Req).MustInt64(key, defaults...)
316313
}
317314

318-
// QueryBool returns request form as bool with default
319-
func (ctx *Context) QueryBool(key string, defaults ...bool) bool {
315+
// FormBool returns request form as bool with default
316+
func (ctx *Context) FormBool(key string, defaults ...bool) bool {
320317
return (*Forms)(ctx.Req).MustBool(key, defaults...)
321318
}
322319

323-
// QueryOptionalBool returns request form as OptionalBool with default
324-
func (ctx *Context) QueryOptionalBool(key string, defaults ...util.OptionalBool) util.OptionalBool {
320+
// FormOptionalBool returns request form as OptionalBool with default
321+
func (ctx *Context) FormOptionalBool(key string, defaults ...util.OptionalBool) util.OptionalBool {
325322
return (*Forms)(ctx.Req).MustOptionalBool(key, defaults...)
326323
}
327324

modules/context/repo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func repoAssignment(ctx *Context, repo *models.Repository) {
346346

347347
// Check access.
348348
if ctx.Repo.Permission.AccessMode == models.AccessModeNone {
349-
if ctx.Query("go-get") == "1" {
349+
if ctx.Form("go-get") == "1" {
350350
EarlyResponseForGoGetMeta(ctx)
351351
return
352352
}
@@ -415,7 +415,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
415415
owner, err = models.GetUserByName(userName)
416416
if err != nil {
417417
if models.IsErrUserNotExist(err) {
418-
if ctx.Query("go-get") == "1" {
418+
if ctx.Form("go-get") == "1" {
419419
EarlyResponseForGoGetMeta(ctx)
420420
return
421421
}
@@ -437,7 +437,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
437437
if err == nil {
438438
RedirectToRepo(ctx, redirectRepoID)
439439
} else if models.IsErrRepoRedirectNotExist(err) {
440-
if ctx.Query("go-get") == "1" {
440+
if ctx.Form("go-get") == "1" {
441441
EarlyResponseForGoGetMeta(ctx)
442442
return
443443
}
@@ -618,7 +618,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
618618
}
619619
}
620620

621-
if ctx.Query("go-get") == "1" {
621+
if ctx.Form("go-get") == "1" {
622622
ctx.Data["GoGetImport"] = ComposeGoGetImport(owner.Name, repo.Name)
623623
prefix := setting.AppURL + path.Join(owner.Name, repo.Name, "src", "branch", ctx.Repo.BranchName)
624624
ctx.Data["GoDocDirectory"] = prefix + "{/dir}"

routers/api/v1/admin/adopt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func ListUnadoptedRepositories(ctx *context.APIContext) {
4242
// "$ref": "#/responses/forbidden"
4343

4444
listOptions := utils.GetListOptions(ctx)
45-
repoNames, count, err := repository.ListUnadoptedRepositories(ctx.Query("query"), &listOptions)
45+
repoNames, count, err := repository.ListUnadoptedRepositories(ctx.Form("query"), &listOptions)
4646
if err != nil {
4747
ctx.InternalServerError(err)
4848
}

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ import (
9393

9494
func sudo() func(ctx *context.APIContext) {
9595
return func(ctx *context.APIContext) {
96-
sudo := ctx.Query("sudo")
96+
sudo := ctx.Form("sudo")
9797
if len(sudo) == 0 {
9898
sudo = ctx.Req.Header.Get("Sudo")
9999
}

routers/api/v1/notify/notifications.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ func getFindNotificationOptions(ctx *context.APIContext) *models.FindNotificatio
3737
UpdatedBeforeUnix: before,
3838
UpdatedAfterUnix: since,
3939
}
40-
if !ctx.QueryBool("all") {
41-
statuses := ctx.QueryStrings("status-types")
40+
if !ctx.FormBool("all") {
41+
statuses := ctx.FormStrings("status-types")
4242
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread", "pinned"})
4343
}
4444

45-
subjectTypes := ctx.QueryStrings("subject-type")
45+
subjectTypes := ctx.FormStrings("subject-type")
4646
if len(subjectTypes) != 0 {
4747
opts.Source = subjectToSource(subjectTypes)
4848
}

routers/api/v1/notify/repo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
171171
// "$ref": "#/responses/empty"
172172

173173
lastRead := int64(0)
174-
qLastRead := strings.Trim(ctx.Query("last_read_at"), " ")
174+
qLastRead := strings.Trim(ctx.Form("last_read_at"), " ")
175175
if len(qLastRead) > 0 {
176176
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
177177
if err != nil {
@@ -189,8 +189,8 @@ func ReadRepoNotifications(ctx *context.APIContext) {
189189
UpdatedBeforeUnix: lastRead,
190190
}
191191

192-
if !ctx.QueryBool("all") {
193-
statuses := ctx.QueryStrings("status-types")
192+
if !ctx.FormBool("all") {
193+
statuses := ctx.FormStrings("status-types")
194194
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread"})
195195
log.Error("%v", opts.Status)
196196
}
@@ -200,7 +200,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
200200
return
201201
}
202202

203-
targetStatus := statusStringToNotificationStatus(ctx.Query("to-status"))
203+
targetStatus := statusStringToNotificationStatus(ctx.Form("to-status"))
204204
if targetStatus == 0 {
205205
targetStatus = models.NotificationStatusRead
206206
}

routers/api/v1/notify/threads.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func ReadThread(ctx *context.APIContext) {
8282
return
8383
}
8484

85-
targetStatus := statusStringToNotificationStatus(ctx.Query("to-status"))
85+
targetStatus := statusStringToNotificationStatus(ctx.Form("to-status"))
8686
if targetStatus == 0 {
8787
targetStatus = models.NotificationStatusRead
8888
}

routers/api/v1/notify/user.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func ReadNotifications(ctx *context.APIContext) {
122122
// "$ref": "#/responses/empty"
123123

124124
lastRead := int64(0)
125-
qLastRead := strings.Trim(ctx.Query("last_read_at"), " ")
125+
qLastRead := strings.Trim(ctx.Form("last_read_at"), " ")
126126
if len(qLastRead) > 0 {
127127
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
128128
if err != nil {
@@ -137,8 +137,8 @@ func ReadNotifications(ctx *context.APIContext) {
137137
UserID: ctx.User.ID,
138138
UpdatedBeforeUnix: lastRead,
139139
}
140-
if !ctx.QueryBool("all") {
141-
statuses := ctx.QueryStrings("status-types")
140+
if !ctx.FormBool("all") {
141+
statuses := ctx.FormStrings("status-types")
142142
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread"})
143143
}
144144
nl, err := models.GetNotifications(opts)
@@ -147,7 +147,7 @@ func ReadNotifications(ctx *context.APIContext) {
147147
return
148148
}
149149

150-
targetStatus := statusStringToNotificationStatus(ctx.Query("to-status"))
150+
targetStatus := statusStringToNotificationStatus(ctx.Form("to-status"))
151151
if targetStatus == 0 {
152152
targetStatus = models.NotificationStatusRead
153153
}

routers/api/v1/org/label.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func ListLabels(ctx *context.APIContext) {
4343
// "200":
4444
// "$ref": "#/responses/LabelList"
4545

46-
labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.Query("sort"), utils.GetListOptions(ctx))
46+
labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.Form("sort"), utils.GetListOptions(ctx))
4747
if err != nil {
4848
ctx.Error(http.StatusInternalServerError, "GetLabelsByOrgID", err)
4949
return

routers/api/v1/org/team.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,9 @@ func SearchTeam(ctx *context.APIContext) {
658658

659659
opts := &models.SearchTeamOptions{
660660
UserID: ctx.User.ID,
661-
Keyword: strings.TrimSpace(ctx.Query("q")),
661+
Keyword: strings.TrimSpace(ctx.Form("q")),
662662
OrgID: ctx.Org.Organization.ID,
663-
IncludeDesc: ctx.Query("include_desc") == "" || ctx.QueryBool("include_desc"),
663+
IncludeDesc: ctx.Form("include_desc") == "" || ctx.FormBool("include_desc"),
664664
ListOptions: listOptions,
665665
}
666666

routers/api/v1/repo/commits.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func GetAllCommits(ctx *context.APIContext) {
147147
listOptions.PageSize = setting.Git.CommitsRangeSize
148148
}
149149

150-
sha := ctx.Query("sha")
150+
sha := ctx.Form("sha")
151151

152152
var baseCommit *git.Commit
153153
if len(sha) == 0 {

routers/api/v1/repo/file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func GetRawFile(ctx *context.APIContext) {
6262

6363
commit := ctx.Repo.Commit
6464

65-
if ref := ctx.QueryTrim("ref"); len(ref) > 0 {
65+
if ref := ctx.FormTrim("ref"); len(ref) > 0 {
6666
var err error
6767
commit, err = ctx.Repo.GitRepo.GetCommit(ref)
6868
if err != nil {
@@ -549,7 +549,7 @@ func GetContents(ctx *context.APIContext) {
549549
}
550550

551551
treePath := ctx.Params("*")
552-
ref := ctx.QueryTrim("ref")
552+
ref := ctx.FormTrim("ref")
553553

554554
if fileList, err := repofiles.GetContentsOrList(ctx.Repo.Repository, treePath, ref); err != nil {
555555
if git.IsErrNotExist(err) {

routers/api/v1/repo/issue.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func SearchIssues(ctx *context.APIContext) {
106106
}
107107

108108
var isClosed util.OptionalBool
109-
switch ctx.Query("state") {
109+
switch ctx.Form("state") {
110110
case "closed":
111111
isClosed = util.OptionalBoolTrue
112112
case "all":
@@ -140,7 +140,7 @@ func SearchIssues(ctx *context.APIContext) {
140140
var issues []*models.Issue
141141
var filteredCount int64
142142

143-
keyword := strings.Trim(ctx.Query("q"), " ")
143+
keyword := strings.Trim(ctx.Form("q"), " ")
144144
if strings.IndexByte(keyword, 0) >= 0 {
145145
keyword = ""
146146
}
@@ -153,7 +153,7 @@ func SearchIssues(ctx *context.APIContext) {
153153
}
154154

155155
var isPull util.OptionalBool
156-
switch ctx.Query("type") {
156+
switch ctx.Form("type") {
157157
case "pulls":
158158
isPull = util.OptionalBoolTrue
159159
case "issues":
@@ -162,21 +162,21 @@ func SearchIssues(ctx *context.APIContext) {
162162
isPull = util.OptionalBoolNone
163163
}
164164

165-
labels := strings.TrimSpace(ctx.Query("labels"))
165+
labels := strings.TrimSpace(ctx.Form("labels"))
166166
var includedLabelNames []string
167167
if len(labels) > 0 {
168168
includedLabelNames = strings.Split(labels, ",")
169169
}
170170

171-
milestones := strings.TrimSpace(ctx.Query("milestones"))
171+
milestones := strings.TrimSpace(ctx.Form("milestones"))
172172
var includedMilestones []string
173173
if len(milestones) > 0 {
174174
includedMilestones = strings.Split(milestones, ",")
175175
}
176176

177177
// this api is also used in UI,
178178
// so the default limit is set to fit UI needs
179-
limit := ctx.QueryInt("limit")
179+
limit := ctx.FormInt("limit")
180180
if limit == 0 {
181181
limit = setting.UI.IssuePagingNum
182182
} else if limit > setting.API.MaxResponseItems {
@@ -188,7 +188,7 @@ func SearchIssues(ctx *context.APIContext) {
188188
if len(keyword) == 0 || len(issueIDs) > 0 || len(includedLabelNames) > 0 || len(includedMilestones) > 0 {
189189
issuesOpt := &models.IssuesOptions{
190190
ListOptions: models.ListOptions{
191-
Page: ctx.QueryInt("page"),
191+
Page: ctx.FormInt("page"),
192192
PageSize: limit,
193193
},
194194
RepoIDs: repoIDs,
@@ -197,23 +197,23 @@ func SearchIssues(ctx *context.APIContext) {
197197
IncludedLabelNames: includedLabelNames,
198198
IncludeMilestones: includedMilestones,
199199
SortType: "priorityrepo",
200-
PriorityRepoID: ctx.QueryInt64("priority_repo_id"),
200+
PriorityRepoID: ctx.FormInt64("priority_repo_id"),
201201
IsPull: isPull,
202202
UpdatedBeforeUnix: before,
203203
UpdatedAfterUnix: since,
204204
}
205205

206206
// Filter for: Created by User, Assigned to User, Mentioning User, Review of User Requested
207-
if ctx.QueryBool("created") {
207+
if ctx.FormBool("created") {
208208
issuesOpt.PosterID = ctx.User.ID
209209
}
210-
if ctx.QueryBool("assigned") {
210+
if ctx.FormBool("assigned") {
211211
issuesOpt.AssigneeID = ctx.User.ID
212212
}
213-
if ctx.QueryBool("mentioned") {
213+
if ctx.FormBool("mentioned") {
214214
issuesOpt.MentionedID = ctx.User.ID
215215
}
216-
if ctx.QueryBool("review_requested") {
216+
if ctx.FormBool("review_requested") {
217217
issuesOpt.ReviewRequestedID = ctx.User.ID
218218
}
219219

@@ -319,7 +319,7 @@ func ListIssues(ctx *context.APIContext) {
319319
}
320320

321321
var isClosed util.OptionalBool
322-
switch ctx.Query("state") {
322+
switch ctx.Form("state") {
323323
case "closed":
324324
isClosed = util.OptionalBoolTrue
325325
case "all":
@@ -331,7 +331,7 @@ func ListIssues(ctx *context.APIContext) {
331331
var issues []*models.Issue
332332
var filteredCount int64
333333

334-
keyword := strings.Trim(ctx.Query("q"), " ")
334+
keyword := strings.Trim(ctx.Form("q"), " ")
335335
if strings.IndexByte(keyword, 0) >= 0 {
336336
keyword = ""
337337
}
@@ -345,7 +345,7 @@ func ListIssues(ctx *context.APIContext) {
345345
}
346346
}
347347

348-
if splitted := strings.Split(ctx.Query("labels"), ","); len(splitted) > 0 {
348+
if splitted := strings.Split(ctx.Form("labels"), ","); len(splitted) > 0 {
349349
labelIDs, err = models.GetLabelIDsInRepoByNames(ctx.Repo.Repository.ID, splitted)
350350
if err != nil {
351351
ctx.Error(http.StatusInternalServerError, "GetLabelIDsInRepoByNames", err)
@@ -354,7 +354,7 @@ func ListIssues(ctx *context.APIContext) {
354354
}
355355

356356
var mileIDs []int64
357-
if part := strings.Split(ctx.Query("milestones"), ","); len(part) > 0 {
357+
if part := strings.Split(ctx.Form("milestones"), ","); len(part) > 0 {
358358
for i := range part {
359359
// uses names and fall back to ids
360360
// non existent milestones are discarded
@@ -386,7 +386,7 @@ func ListIssues(ctx *context.APIContext) {
386386
listOptions := utils.GetListOptions(ctx)
387387

388388
var isPull util.OptionalBool
389-
switch ctx.Query("type") {
389+
switch ctx.Form("type") {
390390
case "pulls":
391391
isPull = util.OptionalBoolTrue
392392
case "issues":
@@ -448,7 +448,7 @@ func ListIssues(ctx *context.APIContext) {
448448
}
449449

450450
func getUserIDForFilter(ctx *context.APIContext, queryName string) int64 {
451-
userName := ctx.Query(queryName)
451+
userName := ctx.Form(queryName)
452452
if len(userName) == 0 {
453453
return 0
454454
}

0 commit comments

Comments
 (0)