drone-yaml/yaml/cron.go

50 lines
1.2 KiB
Go
Raw Permalink Normal View History

// Copyright (c) 2019, Drone IO Inc.
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
2019-02-10 20:00:16 +01:00
2019-01-23 00:44:17 +01:00
package yaml
import "errors"
var ErrInvlaidCronBranch = errors.New("yaml: invalid cron branch")
2019-01-23 00:44:17 +01: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 {
Schedule string `json:"schedule,omitempty"`
Branch string `json:"branch,omitempty"`
Deployment CronDeployment `json:"deployment,omitempty" yaml:"deployment"`
2019-01-23 00:44:17 +01: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 == "":
return ErrInvlaidCronBranch
2019-01-23 00:44:17 +01:00
default:
return nil
}
}