2017-06-10 11:22:27 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2017-06-10 14:07:31 +00:00
|
|
|
"fmt"
|
2017-06-10 11:22:27 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const KeelDefaultPort = 9300
|
2017-06-11 22:33:14 +00:00
|
|
|
const KeelPolicyLabel = "keel.observer/policy"
|
2017-06-10 11:22:27 +00:00
|
|
|
|
|
|
|
type Repository struct {
|
2017-06-10 14:07:31 +00:00
|
|
|
Host string `json:"host,omitempty"`
|
2017-06-10 11:22:27 +00:00
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Tag string `json:"tag,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Event struct {
|
|
|
|
Repository Repository `json:"repository,omitempty"`
|
|
|
|
CreatedAt time.Time `json:"createdAt,omitempty"`
|
2017-06-14 22:04:30 +00:00
|
|
|
// optional field to identify trigger
|
|
|
|
TriggerName string `json:"triggerName,omitempty"`
|
2017-06-10 11:22:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Version struct {
|
|
|
|
Major int64
|
|
|
|
Minor int64
|
|
|
|
Patch int64
|
|
|
|
PreRelease string
|
|
|
|
Metadata string
|
|
|
|
}
|
|
|
|
|
2017-06-10 14:07:31 +00:00
|
|
|
func (v Version) String() string {
|
|
|
|
return fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch)
|
|
|
|
}
|
|
|
|
|
2017-06-10 11:22:27 +00:00
|
|
|
// PolicyType - policy type
|
|
|
|
type PolicyType int
|
|
|
|
|
2017-06-10 14:07:31 +00:00
|
|
|
// ParsePolicy - parse policy type
|
|
|
|
func ParsePolicy(policy string) PolicyType {
|
|
|
|
switch policy {
|
|
|
|
case "all":
|
|
|
|
return PolicyTypeAll
|
|
|
|
case "major":
|
|
|
|
return PolicyTypeMajor
|
|
|
|
case "minor":
|
|
|
|
return PolicyTypeMinor
|
|
|
|
case "patch":
|
|
|
|
return PolicyTypePatch
|
|
|
|
default:
|
|
|
|
return PolicyTypeUnknown
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-10 11:22:27 +00:00
|
|
|
func (t PolicyType) String() string {
|
|
|
|
switch t {
|
2017-06-10 14:07:31 +00:00
|
|
|
case PolicyTypeUnknown:
|
|
|
|
return "unknown"
|
2017-06-10 11:22:27 +00:00
|
|
|
case PolicyTypeAll:
|
|
|
|
return "all"
|
|
|
|
case PolicyTypeMajor:
|
|
|
|
return "major"
|
|
|
|
case PolicyTypeMinor:
|
|
|
|
return "minor"
|
|
|
|
case PolicyTypePatch:
|
|
|
|
return "patch"
|
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// available policies
|
|
|
|
const (
|
2017-06-10 14:07:31 +00:00
|
|
|
PolicyTypeUnknown = iota
|
2017-06-10 11:22:27 +00:00
|
|
|
PolicyTypeAll
|
|
|
|
PolicyTypeMajor
|
|
|
|
PolicyTypeMinor
|
|
|
|
PolicyTypePatch
|
|
|
|
)
|