chore(repo): reinitialize repository
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
package task
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Status string
|
||||
|
||||
const (
|
||||
StatusDraft Status = "draft"
|
||||
StatusReady Status = "ready"
|
||||
StatusRunning Status = "running"
|
||||
StatusBlocked Status = "blocked"
|
||||
StatusSucceeded Status = "succeeded"
|
||||
StatusFailed Status = "failed"
|
||||
StatusCancelled Status = "cancelled"
|
||||
)
|
||||
|
||||
type Kind string
|
||||
|
||||
const (
|
||||
KindExecution Kind = "execution"
|
||||
KindGate Kind = "gate"
|
||||
KindVerification Kind = "verification"
|
||||
KindMilestone Kind = "milestone"
|
||||
)
|
||||
|
||||
type Record struct {
|
||||
ID string `json:"id"`
|
||||
WorkspaceID string `json:"workspace_id"`
|
||||
TopicID string `json:"topic_id"`
|
||||
LaneID string `json:"lane_id"`
|
||||
Title string `json:"title"`
|
||||
BodyMarkdown string `json:"body_markdown"`
|
||||
AcceptanceMarkdown string `json:"acceptance_markdown,omitempty"`
|
||||
Kind Kind `json:"kind"`
|
||||
Deliverables []string `json:"deliverables,omitempty"`
|
||||
BatchKey string `json:"batch_key,omitempty"`
|
||||
Status Status `json:"status"`
|
||||
Priority int `json:"priority"`
|
||||
TaskOrder int `json:"task_order"`
|
||||
CreatedByRoleName string `json:"created_by_role_name"`
|
||||
BlockingReasonMarkdown string `json:"blocking_reason_markdown,omitempty"`
|
||||
ResultSummaryMarkdown string `json:"result_summary_markdown,omitempty"`
|
||||
AssignedRunID string `json:"assigned_run_id,omitempty"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
StartedAt string `json:"started_at,omitempty"`
|
||||
CompletedAt string `json:"completed_at,omitempty"`
|
||||
}
|
||||
|
||||
type Dependency struct {
|
||||
TaskID string `json:"task_id"`
|
||||
DependsOnTaskID string `json:"depends_on_task_id"`
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
ID string `json:"id"`
|
||||
TaskID string `json:"task_id"`
|
||||
EventType string `json:"event_type"`
|
||||
BodyMarkdown string `json:"body_markdown,omitempty"`
|
||||
CreatedByRoleName string `json:"created_by_role_name"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
func ValidateStatus(value Status) error {
|
||||
switch value {
|
||||
case StatusDraft, StatusReady, StatusRunning, StatusBlocked, StatusSucceeded, StatusFailed, StatusCancelled:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("invalid task status %q", value)
|
||||
}
|
||||
}
|
||||
|
||||
func ValidateKind(value Kind) error {
|
||||
switch value {
|
||||
case KindExecution, KindGate, KindVerification, KindMilestone:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("invalid task kind %q", value)
|
||||
}
|
||||
}
|
||||
|
||||
func NormalizeRecord(value Record) Record {
|
||||
if value.Kind == "" {
|
||||
value.Kind = KindExecution
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func (r Record) Validate() error {
|
||||
r = NormalizeRecord(r)
|
||||
if r.WorkspaceID == "" {
|
||||
return fmt.Errorf("workspace id is required")
|
||||
}
|
||||
if r.TopicID == "" {
|
||||
return fmt.Errorf("topic id is required")
|
||||
}
|
||||
if r.LaneID == "" {
|
||||
return fmt.Errorf("lane id is required")
|
||||
}
|
||||
if r.Title == "" {
|
||||
return fmt.Errorf("task title is required")
|
||||
}
|
||||
if r.BodyMarkdown == "" {
|
||||
return fmt.Errorf("task body is required")
|
||||
}
|
||||
if r.CreatedByRoleName == "" {
|
||||
return fmt.Errorf("created by role is required")
|
||||
}
|
||||
if err := ValidateKind(r.Kind); err != nil {
|
||||
return err
|
||||
}
|
||||
return ValidateStatus(r.Status)
|
||||
}
|
||||
|
||||
func (d Dependency) Validate() error {
|
||||
if d.TaskID == "" {
|
||||
return fmt.Errorf("task id is required")
|
||||
}
|
||||
if d.DependsOnTaskID == "" {
|
||||
return fmt.Errorf("depends_on task id is required")
|
||||
}
|
||||
if d.TaskID == d.DependsOnTaskID {
|
||||
return fmt.Errorf("task cannot depend on itself")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e Event) Validate() error {
|
||||
if e.TaskID == "" {
|
||||
return fmt.Errorf("task id is required")
|
||||
}
|
||||
if e.EventType == "" {
|
||||
return fmt.Errorf("event type is required")
|
||||
}
|
||||
if e.CreatedByRoleName == "" {
|
||||
return fmt.Errorf("created by role is required")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user