0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-20 21:18:30 +02:00

Apply Go modernization fixes - use strings.CutPrefix instead of HasPrefix+TrimPrefix

This commit is contained in:
Brice Ruth 2025-06-28 16:44:55 -05:00
parent 722ac05f41
commit 695496c100
No known key found for this signature in database
GPG Key ID: 5DFD569B02D44E21

View File

@ -186,32 +186,32 @@ func ListRuns(ctx *context.APIContext, ownerID, repoID int64) {
opts.CreatedBefore = endDate
}
}
} else if strings.HasPrefix(created, ">=") {
} else if after, ok := strings.CutPrefix(created, ">="); ok {
// Greater than or equal format: ">=2023-01-01"
dateStr := strings.TrimPrefix(created, ">=")
dateStr := after
startDate, err := time.Parse("2006-01-02", dateStr)
if err == nil {
opts.CreatedAfter = startDate
}
} else if strings.HasPrefix(created, ">") {
} else if after, ok := strings.CutPrefix(created, ">"); ok {
// Greater than format: ">2023-01-01"
dateStr := strings.TrimPrefix(created, ">")
dateStr := after
startDate, err := time.Parse("2006-01-02", dateStr)
if err == nil {
opts.CreatedAfter = startDate.Add(24 * time.Hour)
}
} else if strings.HasPrefix(created, "<=") {
} else if after, ok := strings.CutPrefix(created, "<="); ok {
// Less than or equal format: "<=2023-12-31"
dateStr := strings.TrimPrefix(created, "<=")
dateStr := after
endDate, err := time.Parse("2006-01-02", dateStr)
if err == nil {
// Set to end of day
endDate = endDate.Add(24*time.Hour - time.Second)
opts.CreatedBefore = endDate
}
} else if strings.HasPrefix(created, "<") {
} else if after, ok := strings.CutPrefix(created, "<"); ok {
// Less than format: "<2023-12-31"
dateStr := strings.TrimPrefix(created, "<")
dateStr := after
endDate, err := time.Parse("2006-01-02", dateStr)
if err == nil {
opts.CreatedBefore = endDate