Refactor StringsToInt64s (#29967)

And close #27176

(cherry picked from commit cdb4d1a8db096d60dba04728924dab85def45b19)
This commit is contained in:
wxiaoguang 2024-03-21 23:07:35 +08:00 committed by Earl Warren
parent f8060bb5d9
commit e5920b4a62
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
12 changed files with 30 additions and 27 deletions

View file

@ -21,6 +21,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
@ -96,13 +97,17 @@ func ListPullRequests(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
labelIDs, err := base.StringsToInt64s(ctx.FormStrings("labels"))
if err != nil {
ctx.Error(http.StatusInternalServerError, "PullRequests", err)
return
}
listOptions := utils.GetListOptions(ctx)
prs, maxResults, err := issues_model.PullRequests(ctx, ctx.Repo.Repository.ID, &issues_model.PullRequestsOptions{
ListOptions: listOptions,
State: ctx.FormTrim("state"),
SortType: ctx.FormTrim("sort"),
Labels: ctx.FormStrings("labels"),
Labels: labelIDs,
MilestoneID: ctx.FormInt64("milestone"),
})
if err != nil {

View file

@ -192,8 +192,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
if len(selectLabels) > 0 {
labelIDs, err = base.StringsToInt64s(strings.Split(selectLabels, ","))
if err != nil {
ctx.ServerError("StringsToInt64s", err)
return
ctx.Flash.Error(ctx.Tr("invalid_data", selectLabels), true)
}
}

View file

@ -529,17 +529,14 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
// Get IDs for labels (a filter option for issues/pulls).
// Required for IssuesOptions.
var labelIDs []int64
selectedLabels := ctx.FormString("labels")
if len(selectedLabels) > 0 && selectedLabels != "0" {
var err error
labelIDs, err = base.StringsToInt64s(strings.Split(selectedLabels, ","))
opts.LabelIDs, err = base.StringsToInt64s(strings.Split(selectedLabels, ","))
if err != nil {
ctx.ServerError("StringsToInt64s", err)
return
ctx.Flash.Error(ctx.Tr("invalid_data", selectedLabels), true)
}
}
opts.LabelIDs = labelIDs
// ------------------------------
// Get issues as defined by opts.

View file

@ -268,8 +268,7 @@ func NotificationSubscriptions(ctx *context.Context) {
var err error
labelIDs, err = base.StringsToInt64s(strings.Split(selectedLabels, ","))
if err != nil {
ctx.ServerError("StringsToInt64s", err)
return
ctx.Flash.Error(ctx.Tr("invalid_data", selectedLabels), true)
}
}