Skip to content

Commit 28821a6

Browse files
committed
Use ctx.FormString / ctx.FormStrings to cache url values
1 parent b522893 commit 28821a6

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

routers/api/v1/shared/action.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ func ListJobs(ctx *context.APIContext, ownerID, repoID, runID int64) {
3737
RunID: runID,
3838
ListOptions: utils.GetListOptions(ctx),
3939
}
40-
if statuses, ok := ctx.Req.URL.Query()["status"]; ok {
41-
for _, status := range statuses {
42-
values, err := convertToInternal(status)
43-
if err != nil {
44-
ctx.APIError(http.StatusBadRequest, fmt.Errorf("Invalid status %s", status))
45-
return
46-
}
47-
opts.Statuses = append(opts.Statuses, values...)
40+
for _, status := range ctx.FormStrings("status") {
41+
values, err := convertToInternal(status)
42+
if err != nil {
43+
ctx.APIError(http.StatusBadRequest, fmt.Errorf("Invalid status %s", status))
44+
return
4845
}
46+
opts.Statuses = append(opts.Statuses, values...)
4947
}
5048

5149
jobs, total, err := db.FindAndCount[actions_model.ActionRunJob](ctx, opts)
@@ -127,31 +125,29 @@ func ListRuns(ctx *context.APIContext, ownerID, repoID int64) {
127125
ListOptions: utils.GetListOptions(ctx),
128126
}
129127

130-
if event := ctx.Req.URL.Query().Get("event"); event != "" {
128+
if event := ctx.FormString("event"); event != "" {
131129
opts.TriggerEvent = webhook.HookEventType(event)
132130
}
133-
if branch := ctx.Req.URL.Query().Get("branch"); branch != "" {
131+
if branch := ctx.FormString("branch"); branch != "" {
134132
opts.Ref = string(git.RefNameFromBranch(branch))
135133
}
136-
if statuses, ok := ctx.Req.URL.Query()["status"]; ok {
137-
for _, status := range statuses {
138-
values, err := convertToInternal(status)
139-
if err != nil {
140-
ctx.APIError(http.StatusBadRequest, fmt.Errorf("Invalid status %s", status))
141-
return
142-
}
143-
opts.Status = append(opts.Status, values...)
134+
for _, status := range ctx.FormStrings("status") {
135+
values, err := convertToInternal(status)
136+
if err != nil {
137+
ctx.APIError(http.StatusBadRequest, fmt.Errorf("Invalid status %s", status))
138+
return
144139
}
140+
opts.Status = append(opts.Status, values...)
145141
}
146-
if actor := ctx.Req.URL.Query().Get("actor"); actor != "" {
142+
if actor := ctx.FormString("actor"); actor != "" {
147143
user, err := user_model.GetUserByName(ctx, actor)
148144
if err != nil {
149145
ctx.APIErrorInternal(err)
150146
return
151147
}
152148
opts.TriggerUserID = user.ID
153149
}
154-
if headSHA := ctx.Req.URL.Query().Get("head_sha"); headSHA != "" {
150+
if headSHA := ctx.FormString("head_sha"); headSHA != "" {
155151
opts.CommitSHA = headSHA
156152
}
157153

0 commit comments

Comments
 (0)