1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2026-06-03 16:35:37 +02:00

Trim white spaces for cron create/update (#6690)

This commit is contained in:
6543
2026-06-02 10:31:53 +02:00
committed by GitHub
parent b724f35852
commit ede1fcd45b
+38 -29
View File
@@ -18,6 +18,7 @@ import (
"errors"
"net/http"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
@@ -126,11 +127,11 @@ func PostCron(c *gin.Context) {
}
cron := &model.Cron{
RepoID: repo.ID,
Name: in.Name,
Name: strings.TrimSpace(in.Name),
CreatorID: user.ID,
Schedule: in.Schedule,
Timezone: in.Timezone,
Branch: in.Branch,
Schedule: strings.TrimSpace(in.Schedule),
Timezone: strings.TrimSpace(in.Timezone),
Branch: strings.TrimSpace(in.Branch),
Variables: in.Variables,
Enabled: in.Enabled,
}
@@ -142,7 +143,7 @@ func PostCron(c *gin.Context) {
return
}
nextExec, err := cron_scheduler.CalcNewNext(in.Schedule, in.Timezone, time.Now())
nextExec, err := cron_scheduler.CalcNewNext(cron.Schedule, cron.Timezone, time.Now())
if err != nil {
c.String(http.StatusBadRequest, "Error inserting cron. schedule could not parsed: %s", err)
return
@@ -151,7 +152,7 @@ func PostCron(c *gin.Context) {
if in.Branch != "" {
// check if branch exists on forge
_, err := _forge.BranchHead(c, user, repo, in.Branch)
_, err := _forge.BranchHead(c, user, repo, cron.Branch)
if err != nil {
c.String(http.StatusBadRequest, "Error inserting cron. branch not resolved: %s", err)
return
@@ -209,35 +210,43 @@ func PatchCron(c *gin.Context) {
handleDBError(c, err)
return
}
if in.Branch != nil && *in.Branch != "" {
// check if branch exists on forge
_, err := _forge.BranchHead(c, user, repo, *in.Branch)
if err != nil {
c.String(http.StatusBadRequest, "Error inserting cron. branch not resolved: %s", err)
return
if in.Branch != nil {
if branch := strings.TrimSpace(*in.Branch); branch != "" {
// check if branch exists on forge
_, err := _forge.BranchHead(c, user, repo, branch)
if err != nil {
c.String(http.StatusBadRequest, "Error inserting cron. branch not resolved: %s", err)
return
}
cron.Branch = branch
}
cron.Branch = *in.Branch
}
if in.Timezone != nil && *in.Timezone != "" {
cron.Timezone = *in.Timezone
nextExec, err := cron_scheduler.CalcNewNext(cron.Schedule, cron.Timezone, time.Now())
if err != nil {
c.String(http.StatusBadRequest, "Error inserting cron. schedule could not parsed: %s", err)
return
if in.Timezone != nil {
if tz := strings.TrimSpace(*in.Timezone); tz != "" {
nextExec, err := cron_scheduler.CalcNewNext(cron.Schedule, tz, time.Now())
if err != nil {
c.String(http.StatusBadRequest, "Error inserting cron. schedule could not parsed: %s", err)
return
}
cron.Timezone = tz
cron.NextExec = nextExec.Unix()
}
cron.NextExec = nextExec.Unix()
}
if in.Schedule != nil && *in.Schedule != "" {
cron.Schedule = *in.Schedule
nextExec, err := cron_scheduler.CalcNewNext(cron.Schedule, cron.Timezone, time.Now())
if err != nil {
c.String(http.StatusBadRequest, "Error inserting cron. schedule could not parsed: %s", err)
return
if in.Schedule != nil {
if schedule := strings.TrimSpace(*in.Schedule); schedule != "" {
nextExec, err := cron_scheduler.CalcNewNext(schedule, cron.Timezone, time.Now())
if err != nil {
c.String(http.StatusBadRequest, "Error inserting cron. schedule could not parsed: %s", err)
return
}
cron.Schedule = schedule
cron.NextExec = nextExec.Unix()
}
cron.NextExec = nextExec.Unix()
}
if in.Name != nil && *in.Name != "" {
cron.Name = *in.Name
if in.Name != nil {
if name := strings.TrimSpace(*in.Name); name != "" {
cron.Name = name
}
}
if in.Enabled != nil {
cron.Enabled = *in.Enabled