1
0
Fork 0
woodpecker-pipeline-transform/drone/conditions.go
2022-07-30 03:48:03 +03:00

51 lines
1.2 KiB
Go

// Copyright 2022 Lauris BH. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package drone
import (
"codeberg.org/lafriks/woodpecker-pipeline-transform/core"
)
type Conditions struct {
Conditions core.Strings `yaml:"-"`
Include core.Strings `yaml:"include,omitempty"`
Exclude core.Strings `yaml:"exclude,omitempty"`
}
func (c *Conditions) UnmarshalYAML(unmarshal func(interface{}) error) error {
v := &struct {
Include core.Strings `yaml:"include,omitempty"`
Exclude core.Strings `yaml:"exclude,omitempty"`
}{}
if err := unmarshal(v); err == nil {
if c == nil {
c = &Conditions{}
}
c.Include = v.Include
c.Exclude = v.Exclude
return nil
}
v2 := make(core.Strings, 0)
if err := unmarshal(&v2); err != nil {
return err
}
if c == nil {
c = &Conditions{}
}
c.Conditions = v2
return nil
}
type When struct {
Branch *Conditions `yaml:"branch"`
Event core.Strings `yaml:"event"`
Refs *Conditions `yaml:"refs"`
Repositories *Conditions `yaml:"repo"`
Instance *Conditions `yaml:"instance"`
Status core.Strings `yaml:"status"`
Target *Conditions `yaml:"target"`
Cron *Conditions `yaml:"cron"`
}