mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-13 20:55:15 +00:00
Add cron feature (#934)
https://woodpecker-ci.org/docs/usage/cron Co-authored-by: Anbraten <anton@ju60.de> Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
This commit is contained in:
@@ -14,6 +14,7 @@ const (
|
||||
EventPull = "pull_request"
|
||||
EventTag = "tag"
|
||||
EventDeploy = "deployment"
|
||||
EventCron = "cron"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -51,6 +52,7 @@ type (
|
||||
Trusted bool `json:"trusted,omitempty"`
|
||||
Commit Commit `json:"commit,omitempty"`
|
||||
Parent int64 `json:"parent,omitempty"`
|
||||
Cron string `json:"cron,omitempty"`
|
||||
}
|
||||
|
||||
// Commit defines runtime metadata for a commit.
|
||||
|
@@ -26,6 +26,7 @@ type (
|
||||
Environment List
|
||||
Event List
|
||||
Branch List
|
||||
Cron List
|
||||
Status List
|
||||
Matrix Map
|
||||
Local types.BoolTrue
|
||||
@@ -153,6 +154,10 @@ func (c *Constraint) Match(metadata frontend.Metadata) bool {
|
||||
match = match && c.Branch.Match(metadata.Curr.Commit.Branch)
|
||||
}
|
||||
|
||||
if metadata.Curr.Event == frontend.EventCron {
|
||||
match = match && c.Cron.Match(metadata.Curr.Cron)
|
||||
}
|
||||
|
||||
return match
|
||||
}
|
||||
|
||||
|
@@ -459,7 +459,25 @@ func TestConstraints(t *testing.T) {
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
desc: "no constraints, and event get filtered by default default event filter",
|
||||
desc: "filter cron by default constraint",
|
||||
conf: "{}",
|
||||
with: frontend.Metadata{Curr: frontend.Build{Event: frontend.EventCron}},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
desc: "filter cron by matching name",
|
||||
conf: "{ event: cron, cron: job1 }",
|
||||
with: frontend.Metadata{Curr: frontend.Build{Event: frontend.EventCron, Cron: "job1"}},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
desc: "filter cron by name",
|
||||
conf: "{ event: cron, cron: job2 }",
|
||||
with: frontend.Metadata{Curr: frontend.Build{Event: frontend.EventCron, Cron: "job1"}},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
desc: "no constraints, event gets filtered by default event filter",
|
||||
conf: "",
|
||||
with: frontend.Metadata{
|
||||
Curr: frontend.Build{Event: "non-default"},
|
||||
@@ -467,6 +485,7 @@ func TestConstraints(t *testing.T) {
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testdata {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c := parseConstraints(t, test.conf)
|
||||
|
@@ -58,7 +58,9 @@ volumes:
|
||||
tmpfs:
|
||||
- /var/lib/test
|
||||
when:
|
||||
branch: master
|
||||
- branch: master
|
||||
- event: cron
|
||||
cron: job1
|
||||
settings:
|
||||
foo: bar
|
||||
baz: false
|
||||
@@ -116,6 +118,14 @@ func TestUnmarshalContainer(t *testing.T) {
|
||||
Include: []string{"master"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Event: constraint.List{
|
||||
Include: []string{"cron"},
|
||||
},
|
||||
Cron: constraint.List{
|
||||
Include: []string{"job1"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Settings: map[string]interface{}{
|
||||
|
Reference in New Issue
Block a user