2021-09-19 12:00:00 +00:00
|
|
|
// Copyright (c) 2019, Drone IO Inc.
|
|
|
|
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
|
2019-02-10 19:00:16 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
package yaml
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
2023-02-08 09:14:20 +00:00
|
|
|
var ErrInvlaidCronBranch = errors.New("yaml: invalid cron branch")
|
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
type (
|
|
|
|
// Cron is a resource that defines a cron job, used
|
|
|
|
// to execute pipelines at scheduled intervals.
|
|
|
|
Cron struct {
|
|
|
|
Version string `json:"version,omitempty"`
|
|
|
|
Kind string `json:"kind,omitempty"`
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
|
|
|
|
Spec CronSpec `json:"spec,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// CronSpec defines the cron job.
|
|
|
|
CronSpec struct {
|
2023-02-08 09:14:20 +00:00
|
|
|
Schedule string `json:"schedule,omitempty"`
|
|
|
|
Branch string `json:"branch,omitempty"`
|
|
|
|
Deployment CronDeployment `json:"deployment,omitempty" yaml:"deployment"`
|
2019-01-22 23:44:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CronDeployment defines a cron job deployment.
|
|
|
|
CronDeployment struct {
|
|
|
|
Target string `json:"target,omitempty"`
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetVersion returns the resource version.
|
|
|
|
func (c *Cron) GetVersion() string { return c.Version }
|
|
|
|
|
|
|
|
// GetKind returns the resource kind.
|
|
|
|
func (c *Cron) GetKind() string { return c.Kind }
|
|
|
|
|
|
|
|
// Validate returns an error if the cron is invalid.
|
|
|
|
func (c Cron) Validate() error {
|
|
|
|
switch {
|
|
|
|
case c.Spec.Branch == "":
|
2023-02-08 09:14:20 +00:00
|
|
|
return ErrInvlaidCronBranch
|
2019-01-22 23:44:17 +00:00
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|