64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package lanesync
|
|
|
|
import "fmt"
|
|
|
|
type Status string
|
|
|
|
const (
|
|
StatusApplied Status = "applied"
|
|
StatusSkipped Status = "skipped"
|
|
StatusFailed Status = "failed"
|
|
)
|
|
|
|
type Record struct {
|
|
ID string `json:"id"`
|
|
WorkspaceID string `json:"workspace_id"`
|
|
TopicID string `json:"topic_id"`
|
|
DownstreamLaneID string `json:"downstream_lane_id"`
|
|
UpstreamLaneID string `json:"upstream_lane_id"`
|
|
TaskID string `json:"task_id"`
|
|
UpstreamCommit string `json:"upstream_commit"`
|
|
MergeCommit string `json:"merge_commit,omitempty"`
|
|
Status Status `json:"status"`
|
|
ErrorMessage string `json:"error_message,omitempty"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
func ValidateStatus(value Status) error {
|
|
switch value {
|
|
case StatusApplied, StatusSkipped, StatusFailed:
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("invalid lane sync status %q", value)
|
|
}
|
|
}
|
|
|
|
func (r Record) Validate() error {
|
|
if r.WorkspaceID == "" {
|
|
return fmt.Errorf("workspace id is required")
|
|
}
|
|
if r.TopicID == "" {
|
|
return fmt.Errorf("topic id is required")
|
|
}
|
|
if r.DownstreamLaneID == "" {
|
|
return fmt.Errorf("downstream lane id is required")
|
|
}
|
|
if r.UpstreamLaneID == "" {
|
|
return fmt.Errorf("upstream lane id is required")
|
|
}
|
|
if r.TaskID == "" {
|
|
return fmt.Errorf("task id is required")
|
|
}
|
|
if r.UpstreamCommit == "" {
|
|
return fmt.Errorf("upstream commit is required")
|
|
}
|
|
if err := ValidateStatus(r.Status); err != nil {
|
|
return err
|
|
}
|
|
if r.Status == StatusFailed && r.ErrorMessage == "" {
|
|
return fmt.Errorf("failed lane sync must include error_message")
|
|
}
|
|
return nil
|
|
}
|