common

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package common provides shared domain types and utilities used across all domain packages. It defines common error types, value objects, and domain event patterns following Domain-Driven Design (DDD) and hexagonal architecture principles.

Package common provides shared domain types including domain events. Domain events represent significant occurrences within the domain that other parts of the system may need to react to. This follows the Event-Driven Architecture (EDA) and Domain-Driven Design (DDD) patterns.

Package common provides shared result types for pipeline operations. Result types encapsulate the outcome of processing operations across different pipelines.

Package common provides shared domain value objects and types. Value objects are immutable domain concepts defined by their attributes rather than identity. They encapsulate domain logic and ensure invariants.

Index

Constants

View Source
const (
	// DomainPR represents the pull request domain
	DomainPR = "pr"

	// DomainQualification represents the qualification domain
	DomainQualification = "qualification"

	// DomainDrift represents the drift monitoring domain
	DomainDrift = "drift"

	// DomainConfig represents the configuration domain
	DomainConfig = "config"
)

Variables

This section is empty.

Functions

func IsConflictError

func IsConflictError(err error) bool

IsConflictError checks if an error is a conflict error.

func IsDomainError

func IsDomainError(err error) bool

IsDomainError checks if an error is a domain error.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError checks if an error is a not found error.

func IsPermanentError

func IsPermanentError(err error) bool

IsPermanentError checks if an error represents a permanent failure. Returns false if the error is not a domain error.

func IsStateTransitionError

func IsStateTransitionError(err error) bool

IsStateTransitionError checks if an error is a state transition error.

func IsValidationError

func IsValidationError(err error) bool

IsValidationError checks if an error is a validation error.

Types

type ApplicationName

type ApplicationName struct {
	// contains filtered or unexported fields
}

ApplicationName is a value object representing an ArgoCD application name.

func NewApplicationName

func NewApplicationName(name string) (*ApplicationName, error)

NewApplicationName creates a new application name.

func (*ApplicationName) Equals

func (a *ApplicationName) Equals(other *ApplicationName) bool

Equals checks if two application names are equal.

func (*ApplicationName) Name

func (a *ApplicationName) Name() string

Name returns the application name.

func (*ApplicationName) String

func (a *ApplicationName) String() string

String implements the fmt.Stringer interface.

type BaseEvent

type BaseEvent struct {
	// contains filtered or unexported fields
}

BaseEvent provides common implementation for all domain events. Embed this struct in specific event types to inherit standard event behavior.

func NewBaseEvent

func NewBaseEvent(eventType, aggregateID, aggregateType string, version int) *BaseEvent

NewBaseEvent creates a new base event with standard fields populated. This is used by specific event constructors to create the embedded BaseEvent.

func (*BaseEvent) AggregateID

func (e *BaseEvent) AggregateID() string

AggregateID returns the aggregate identifier.

func (*BaseEvent) AggregateType

func (e *BaseEvent) AggregateType() string

AggregateType returns the aggregate type.

func (*BaseEvent) EventID

func (e *BaseEvent) EventID() string

EventID returns the unique event identifier.

func (*BaseEvent) EventType

func (e *BaseEvent) EventType() string

EventType returns the event type.

func (*BaseEvent) Metadata

func (e *BaseEvent) Metadata() map[string]string

Metadata returns the event metadata.

func (*BaseEvent) OccurredAt

func (e *BaseEvent) OccurredAt() time.Time

OccurredAt returns when the event occurred.

func (*BaseEvent) String

func (e *BaseEvent) String() string

String returns a string representation of the event.

func (*BaseEvent) Version

func (e *BaseEvent) Version() int

Version returns the event schema version.

func (*BaseEvent) WithCausationID

func (e *BaseEvent) WithCausationID(causationID string) *BaseEvent

WithCausationID adds a causation ID to track what caused this event.

func (*BaseEvent) WithCorrelationID

func (e *BaseEvent) WithCorrelationID(correlationID string) *BaseEvent

WithCorrelationID adds a correlation ID to track related events.

func (*BaseEvent) WithMetadata

func (e *BaseEvent) WithMetadata(key, value string) *BaseEvent

WithMetadata adds metadata to the base event. Returns the event for method chaining.

type ClusterIdentifier

type ClusterIdentifier struct {
	// contains filtered or unexported fields
}

ClusterIdentifier is a value object representing an ArgoCD cluster. It encapsulates cluster naming and validation logic.

func NewClusterIdentifier

func NewClusterIdentifier(name string) (*ClusterIdentifier, error)

NewClusterIdentifier creates a new cluster identifier.

func (*ClusterIdentifier) Equals

func (c *ClusterIdentifier) Equals(other *ClusterIdentifier) bool

Equals checks if two cluster identifiers are equal.

func (*ClusterIdentifier) Name

func (c *ClusterIdentifier) Name() string

Name returns the cluster name.

func (*ClusterIdentifier) String

func (c *ClusterIdentifier) String() string

String implements the fmt.Stringer interface.

type ConflictError

type ConflictError struct {
	ConflictType string      // Type of conflict (e.g., "duplicate", "concurrent_modification")
	ConflictWith string      // What this entity conflicts with
	Metadata     interface{} // Additional conflict details
	// contains filtered or unexported fields
}

ConflictError represents a domain conflict, such as concurrent modification or duplicate entity creation. These errors may be resolved through retry or manual intervention.

func NewConflictError

func NewConflictError(domain, conflictType, message string, permanent bool, cause error) *ConflictError

NewConflictError creates a conflict error. Conflicts may or may not be permanent depending on the conflict type.

func (ConflictError) Code

func (e ConflictError) Code() string

Code returns the error code.

func (ConflictError) Domain

func (e ConflictError) Domain() string

Domain returns the domain context.

func (*ConflictError) Error

func (e *ConflictError) Error() string

Error implements the error interface with conflict details.

func (ConflictError) IsPermanent

func (e ConflictError) IsPermanent() bool

IsPermanent returns whether this error is permanent.

func (ConflictError) Unwrap

func (e ConflictError) Unwrap() error

Unwrap returns the underlying error.

func (*ConflictError) WithConflictTarget

func (e *ConflictError) WithConflictTarget(target string) *ConflictError

WithConflictTarget specifies what entity this conflicts with.

type DeploymentSyncedEvent

type DeploymentSyncedEvent struct {
	*BaseEvent
	Repository   string    // Repository in "owner/name" format
	PRNumber     int       // Pull request number
	Cluster      string    // Cluster where sync completed
	Application  string    // Application name
	Revision     string    // Deployed git revision
	HealthStatus string    // Application health status
	SyncedAt     time.Time // When sync completed
}

DeploymentSyncedEvent is published when a deployment successfully syncs to the expected state. This marks successful completion of the deployment phase.

func NewDeploymentSyncedEvent

func NewDeploymentSyncedEvent(aggregateID, repository string, prNumber int, cluster, application, revision, healthStatus string) *DeploymentSyncedEvent

NewDeploymentSyncedEvent creates a new deployment synced event.

type DeploymentUnhealthyEvent

type DeploymentUnhealthyEvent struct {
	*BaseEvent
	Repository    string    // Repository in "owner/name" format
	PRNumber      int       // Pull request number
	Cluster       string    // Cluster with unhealthy deployment
	Application   string    // Application name
	HealthStatus  string    // Current health status
	HealthMessage string    // Health check failure details
	DetectedAt    time.Time // When unhealthy status was detected
}

DeploymentUnhealthyEvent is published when a deployment becomes unhealthy.

func NewDeploymentUnhealthyEvent

func NewDeploymentUnhealthyEvent(aggregateID, repository string, prNumber int, cluster, application, healthStatus, healthMessage string) *DeploymentUnhealthyEvent

NewDeploymentUnhealthyEvent creates a new deployment unhealthy event.

type DomainError

type DomainError interface {
	error

	// Domain returns the domain context where this error occurred (e.g., "pr", "qualification", "drift")
	Domain() string

	// Code returns a machine-readable error code for programmatic handling
	Code() string

	// IsPermanent returns true if this error represents a permanent failure
	// that will not resolve with retries (e.g., validation failures, business rule violations)
	IsPermanent() bool

	// Unwrap returns the underlying error if any, enabling error chain traversal
	Unwrap() error
}

DomainError is the base interface for all domain-level errors. Domain errors represent business rule violations or invalid state transitions that occur within the domain layer, independent of infrastructure concerns.

All custom domain errors should implement this interface to enable consistent error handling and classification across the application.

func NewDomainError

func NewDomainError(domain, code, message string, permanent bool, cause error) DomainError

NewDomainError creates a new domain error with the specified parameters. This is the primary constructor for creating domain errors.

Parameters:

  • domain: The domain context (e.g., "pr", "qualification", "drift")
  • code: Machine-readable error code (e.g., "INVALID_TRANSITION", "VALIDATION_FAILED")
  • message: Human-readable error message
  • permanent: Whether the error represents a permanent failure
  • cause: Optional underlying error (can be nil)

type DomainEvent

type DomainEvent interface {
	// EventID returns the unique identifier for this event instance
	EventID() string

	// EventType returns the type/name of this event (e.g., "pr.discovered", "drift.detected")
	EventType() string

	// AggregateID returns the ID of the aggregate that produced this event
	AggregateID() string

	// AggregateType returns the type of aggregate (e.g., "PullRequest", "DriftMonitor")
	AggregateType() string

	// OccurredAt returns when this event occurred
	OccurredAt() time.Time

	// Version returns the event schema version for evolution/compatibility
	Version() int

	// Metadata returns additional event metadata (correlation IDs, causation IDs, etc.)
	Metadata() map[string]string
}

DomainEvent is the base interface for all domain events. Domain events are immutable facts that represent something that has happened in the domain. They enable loose coupling between domain aggregates and support eventual consistency patterns.

All domain events should implement this interface to enable consistent event handling, publishing, and persistence across the application.

type DriftDetectedEvent

type DriftDetectedEvent struct {
	*BaseEvent
	Repository       string    // Repository in "owner/name" format
	PRNumber         int       // Pull request number
	Cluster          string    // Cluster where drift was detected
	Application      string    // Application name with drift
	ExpectedRevision string    // Expected git revision (from merged PR)
	ActualRevision   string    // Actual deployed revision
	DriftType        string    // Type of drift (revision, config, etc.)
	DetectedAt       time.Time // When drift was detected
}

DriftDetectedEvent is published when drift is detected between merged code and deployed state. This indicates the deployment does not match what was merged in the PR.

func NewDriftDetectedEvent

func NewDriftDetectedEvent(aggregateID, repository string, prNumber int, cluster, application, expectedRev, actualRev, driftType string) *DriftDetectedEvent

NewDriftDetectedEvent creates a new drift detected event.

type DriftResolvedEvent

type DriftResolvedEvent struct {
	*BaseEvent
	Repository       string    // Repository in "owner/name" format
	PRNumber         int       // Pull request number
	Cluster          string    // Cluster where drift was resolved
	Application      string    // Application name
	NewRevision      string    // New deployed revision that resolved drift
	ResolvedAt       time.Time // When drift was resolved
	ResolutionMethod string    // How drift was resolved (auto-sync, manual, etc.)
}

DriftResolvedEvent is published when detected drift has been resolved. This indicates the deployment now matches the expected state.

func NewDriftResolvedEvent

func NewDriftResolvedEvent(aggregateID, repository string, prNumber int, cluster, application, newRevision, resolutionMethod string) *DriftResolvedEvent

NewDriftResolvedEvent creates a new drift resolved event.

type EntityStatus

type EntityStatus string

EntityStatus represents the common status of domain entities. This provides a standardized way to track entity lifecycle state.

const (
	// StatusActive indicates the entity is active and being processed
	StatusActive EntityStatus = "active"

	// StatusPending indicates the entity is waiting for processing
	StatusPending EntityStatus = "pending"

	// StatusCompleted indicates the entity has completed its lifecycle
	StatusCompleted EntityStatus = "completed"

	// StatusFailed indicates the entity failed processing
	StatusFailed EntityStatus = "failed"

	// StatusArchived indicates the entity is archived (historical record)
	StatusArchived EntityStatus = "archived"
)

func (EntityStatus) IsTerminal

func (s EntityStatus) IsTerminal() bool

IsTerminal returns true if this status represents a terminal state.

func (EntityStatus) IsValid

func (s EntityStatus) IsValid() bool

IsValid checks if the entity status is valid.

func (EntityStatus) String

func (s EntityStatus) String() string

String returns the string representation of the entity status.

type EventBus

type EventBus interface {
	// Publish publishes a single domain event
	Publish(ctx interface{}, event DomainEvent) error

	// PublishBatch publishes multiple events in a single operation
	PublishBatch(ctx interface{}, events []DomainEvent) error

	// Subscribe registers a handler for specific event types
	Subscribe(eventType string, handler EventHandler) error

	// Unsubscribe removes a handler for specific event types
	Unsubscribe(eventType string, handler EventHandler) error
}

EventBus defines the interface for publishing domain events. This abstraction allows the domain layer to publish events without depending on specific infrastructure (e.g., Kafka, NATS, in-memory).

NOTE: This interface is defined for future use. Implementation will be added in Phase 2 of the hexagonal architecture refactoring.

type EventHandler

type EventHandler func(ctx interface{}, event DomainEvent) error

EventHandler is the callback function for processing domain events. Handlers should be idempotent since events may be delivered more than once.

type EventStore

type EventStore interface {
	// Append appends events to an aggregate's event stream
	Append(ctx interface{}, aggregateID string, events []DomainEvent) error

	// Load loads all events for an aggregate in order
	Load(ctx interface{}, aggregateID string) ([]DomainEvent, error)

	// LoadFromVersion loads events from a specific version onwards
	LoadFromVersion(ctx interface{}, aggregateID string, version int) ([]DomainEvent, error)
}

EventStore defines the interface for persisting domain events. This enables event sourcing patterns where entity state is derived from a sequence of events rather than stored directly.

NOTE: This interface is defined for future use. Implementation will be added in Phase 2+ of the hexagonal architecture refactoring.

type GitRevision

type GitRevision struct {
	// contains filtered or unexported fields
}

GitRevision is a value object representing a Git commit SHA. It ensures valid SHA format and provides comparison utilities.

func NewGitRevision

func NewGitRevision(sha string) (*GitRevision, error)

NewGitRevision creates a new Git revision. Accepts both full (40 char) and abbreviated (7+ char) SHAs.

func (*GitRevision) Equals

func (g *GitRevision) Equals(other *GitRevision) bool

Equals checks if two Git revisions are equal. This performs case-insensitive comparison since Git SHAs are hex.

func (*GitRevision) HasPrefix

func (g *GitRevision) HasPrefix(prefix string) bool

HasPrefix checks if this SHA starts with the given prefix. Useful for comparing abbreviated SHAs with full SHAs.

func (*GitRevision) IsFull

func (g *GitRevision) IsFull() bool

IsFull returns true if this is a full 40-character SHA.

func (*GitRevision) SHA

func (g *GitRevision) SHA() string

SHA returns the Git SHA.

func (*GitRevision) ShortSHA

func (g *GitRevision) ShortSHA() string

ShortSHA returns the abbreviated SHA (first 7 characters).

func (*GitRevision) String

func (g *GitRevision) String() string

String implements the fmt.Stringer interface.

type LabelKey

type LabelKey struct {
	// contains filtered or unexported fields
}

LabelKey is a value object representing a GitHub label key. It enforces valid label naming conventions.

func NewLabelKey

func NewLabelKey(key string) (*LabelKey, error)

NewLabelKey creates a new label key.

func (*LabelKey) Equals

func (l *LabelKey) Equals(other *LabelKey) bool

Equals checks if two label keys are equal.

func (*LabelKey) HasPrefix

func (l *LabelKey) HasPrefix(prefix string) bool

HasPrefix checks if the label key has the given prefix.

func (*LabelKey) Key

func (l *LabelKey) Key() string

Key returns the label key.

func (*LabelKey) String

func (l *LabelKey) String() string

String implements the fmt.Stringer interface.

type NotFoundError

type NotFoundError struct {
	EntityType string      // Type of entity (e.g., "PullRequest", "DriftMonitor")
	EntityID   string      // Identifier of the missing entity
	Metadata   interface{} // Additional context (e.g., repository, filters)
	// contains filtered or unexported fields
}

NotFoundError represents a domain entity that could not be found. This error indicates that a requested entity does not exist in the domain.

func NewNotFoundError

func NewNotFoundError(domain, entityType, entityID string) *NotFoundError

NewNotFoundError creates a not found error. Not found errors are permanent since the entity does not exist.

func (NotFoundError) Code

func (e NotFoundError) Code() string

Code returns the error code.

func (NotFoundError) Domain

func (e NotFoundError) Domain() string

Domain returns the domain context.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

Error implements the error interface with entity information.

func (NotFoundError) IsPermanent

func (e NotFoundError) IsPermanent() bool

IsPermanent returns whether this error is permanent.

func (NotFoundError) Unwrap

func (e NotFoundError) Unwrap() error

Unwrap returns the underlying error.

func (*NotFoundError) WithMetadata

func (e *NotFoundError) WithMetadata(metadata interface{}) *NotFoundError

WithMetadata adds metadata to the not found error.

type OperationError

type OperationError struct {
	Operation string            // Name of the operation that failed
	Context   map[string]string // Additional operation context
	// contains filtered or unexported fields
}

OperationError represents an error that occurred during a domain operation. This is a general-purpose error for operations that don't fit other categories.

func NewOperationError

func NewOperationError(domain, operation, message string, permanent bool, cause error) *OperationError

NewOperationError creates an operation error.

func (OperationError) Code

func (e OperationError) Code() string

Code returns the error code.

func (OperationError) Domain

func (e OperationError) Domain() string

Domain returns the domain context.

func (*OperationError) Error

func (e *OperationError) Error() string

Error implements the error interface with operation details.

func (OperationError) IsPermanent

func (e OperationError) IsPermanent() bool

IsPermanent returns whether this error is permanent.

func (OperationError) Unwrap

func (e OperationError) Unwrap() error

Unwrap returns the underlying error.

func (*OperationError) WithContext

func (e *OperationError) WithContext(key, value string) *OperationError

WithContext adds context to the operation error.

type PRDiscoveredEvent

type PRDiscoveredEvent struct {
	*BaseEvent
	Repository   string // Repository in "owner/name" format
	PRNumber     int    // Pull request number
	PRTitle      string // Pull request title
	Author       string // PR author username
	SourceBranch string // Source branch name
	TargetBranch string // Target branch name
}

PRDiscoveredEvent is published when a new PR is discovered by the operator. This marks the beginning of the PR lifecycle in the cd-operator.

func NewPRDiscoveredEvent

func NewPRDiscoveredEvent(aggregateID, repository string, prNumber int, prTitle, author, sourceBranch, targetBranch string) *PRDiscoveredEvent

NewPRDiscoveredEvent creates a new PR discovered event.

type PRIdentifier

type PRIdentifier struct {
	// contains filtered or unexported fields
}

PRIdentifier is a value object representing a unique pull request. It combines repository and PR number to uniquely identify any PR.

func NewPRIdentifier

func NewPRIdentifier(repository *RepositoryIdentifier, number int) (*PRIdentifier, error)

NewPRIdentifier creates a new PR identifier. Returns an error if the PR number is invalid (must be positive).

func ParsePRIdentifier

func ParsePRIdentifier(fullID string) (*PRIdentifier, error)

ParsePRIdentifier parses a PR identifier from "owner/name#number" format.

func (*PRIdentifier) Equals

func (p *PRIdentifier) Equals(other *PRIdentifier) bool

Equals checks if two PR identifiers are equal.

func (*PRIdentifier) FullID

func (p *PRIdentifier) FullID() string

FullID returns the full PR identifier in "owner/name#number" format.

func (*PRIdentifier) Number

func (p *PRIdentifier) Number() int

Number returns the PR number.

func (*PRIdentifier) Repository

func (p *PRIdentifier) Repository() *RepositoryIdentifier

Repository returns the repository identifier.

func (*PRIdentifier) String

func (p *PRIdentifier) String() string

String implements the fmt.Stringer interface.

type PRMergeFailedEvent

type PRMergeFailedEvent struct {
	*BaseEvent
	Repository    string // Repository in "owner/name" format
	PRNumber      int    // Pull request number
	FailureReason string // Why the merge failed
	Retryable     bool   // Whether merge can be retried
}

PRMergeFailedEvent is published when a PR merge attempt fails.

func NewPRMergeFailedEvent

func NewPRMergeFailedEvent(aggregateID, repository string, prNumber int, failureReason string, retryable bool) *PRMergeFailedEvent

NewPRMergeFailedEvent creates a new merge failed event.

type PRMergedEvent

type PRMergedEvent struct {
	*BaseEvent
	Repository     string    // Repository in "owner/name" format
	PRNumber       int       // Pull request number
	MergeCommitSHA string    // SHA of the merge commit
	MergedBy       string    // Username who/what merged the PR
	MergedAt       time.Time // When the PR was merged
	TargetBranch   string    // Branch the PR was merged into
}

PRMergedEvent is published when a PR is successfully merged. This marks the transition from the PR pipeline to the drift monitoring pipeline.

func NewPRMergedEvent

func NewPRMergedEvent(aggregateID, repository string, prNumber int, mergeCommitSHA, mergedBy, targetBranch string, mergedAt time.Time) *PRMergedEvent

NewPRMergedEvent creates a new PR merged event.

type PRQualificationFailedEvent

type PRQualificationFailedEvent struct {
	*BaseEvent
	Repository      string   // Repository in "owner/name" format
	PRNumber        int      // Pull request number
	FailedValidator string   // Primary validator that failed
	FailureReasons  []string // Detailed failure reasons
	Retryable       bool     // Whether qualification can be retried after changes
}

PRQualificationFailedEvent is published when a PR fails qualification checks. This indicates the PR cannot be auto-merged in its current state.

func NewPRQualificationFailedEvent

func NewPRQualificationFailedEvent(aggregateID, repository string, prNumber int, failedValidator string, retryable bool) *PRQualificationFailedEvent

NewPRQualificationFailedEvent creates a new qualification failed event.

type PRQualifiedEvent

type PRQualifiedEvent struct {
	*BaseEvent
	Repository      string            // Repository in "owner/name" format
	PRNumber        int               // Pull request number
	LayoutType      string            // Detected layout type (standard, tmc, etc.)
	Validators      []string          // List of validators that passed
	ExtractedLabels map[string]string // Dynamic labels extracted during qualification
}

PRQualifiedEvent is published when a PR passes all qualification checks. This indicates the PR is ready for auto-merge.

func NewPRQualifiedEvent

func NewPRQualifiedEvent(aggregateID, repository string, prNumber int, layoutType string) *PRQualifiedEvent

NewPRQualifiedEvent creates a new PR qualified event.

type ProcessResult

type ProcessResult[T any] struct {
	// Success indicates whether the processing completed without errors.
	// True means the operation succeeded; false means it failed.
	Success bool

	// Error contains any error that occurred during processing.
	// Nil if Success is true.
	Error error

	// Duration is how long the processing took from start to completion.
	Duration time.Duration

	// Data contains domain-specific result data for this pipeline.
	// The type of data depends on which pipeline produced the result:
	//   - PR Pipeline: includes action, PR, state transition, next actions
	//   - Drift Pipeline: includes drift detection details, deployed SHA, health status
	Data T

	// Metadata contains additional contextual information about the processing.
	// This can include debugging info, timestamps, resource IDs, etc.
	// Keys should be descriptive strings (e.g., "retry_count", "cluster_name").
	Metadata map[string]interface{}
}

ProcessResult represents the generic result of processing a pipeline work item. This provides a standard structure for capturing success/failure, duration, and metadata across different pipeline implementations (PR pipeline, drift pipeline, etc.).

Generic type parameter T allows each pipeline to include domain-specific result data while maintaining a consistent result structure.

func NewProcessResult

func NewProcessResult[T any](success bool, data T) *ProcessResult[T]

NewProcessResult creates a new process result with the given success status and data. This is a convenience constructor that initializes the metadata map.

func (*ProcessResult[T]) GetMetadata

func (r *ProcessResult[T]) GetMetadata(key string) interface{}

GetMetadata retrieves a metadata value by key. Returns nil if the key does not exist.

func (*ProcessResult[T]) HasMetadata

func (r *ProcessResult[T]) HasMetadata(key string) bool

HasMetadata checks if a metadata key exists.

func (*ProcessResult[T]) IsFailure

func (r *ProcessResult[T]) IsFailure() bool

IsFailure returns true if processing failed. This is a convenience method equivalent to checking !r.Success.

func (*ProcessResult[T]) IsSuccess

func (r *ProcessResult[T]) IsSuccess() bool

IsSuccess returns true if processing succeeded. This is a convenience method equivalent to checking r.Success.

func (*ProcessResult[T]) WithDuration

func (r *ProcessResult[T]) WithDuration(duration time.Duration) *ProcessResult[T]

WithDuration sets the processing duration. Returns the result for method chaining.

func (*ProcessResult[T]) WithError

func (r *ProcessResult[T]) WithError(err error) *ProcessResult[T]

WithError sets the error and marks the result as failed. Returns the result for method chaining.

func (*ProcessResult[T]) WithMetadata

func (r *ProcessResult[T]) WithMetadata(key string, value interface{}) *ProcessResult[T]

WithMetadata adds a metadata key-value pair. Returns the result for method chaining.

type RepositoryIdentifier

type RepositoryIdentifier struct {
	// contains filtered or unexported fields
}

RepositoryIdentifier is a value object representing a Git repository. It ensures valid repository identifiers and provides consistent formatting.

func NewRepositoryIdentifier

func NewRepositoryIdentifier(owner, name string) (*RepositoryIdentifier, error)

NewRepositoryIdentifier creates a new repository identifier. Returns an error if owner or name are invalid according to GitHub naming rules.

func ParseRepositoryIdentifier

func ParseRepositoryIdentifier(fullName string) (*RepositoryIdentifier, error)

ParseRepositoryIdentifier parses a repository identifier from "owner/name" format.

func (*RepositoryIdentifier) Equals

Equals checks if two repository identifiers are equal. This is case-sensitive as GitHub repository names are case-sensitive.

func (*RepositoryIdentifier) FullName

func (r *RepositoryIdentifier) FullName() string

FullName returns the full repository identifier in "owner/name" format.

func (*RepositoryIdentifier) Name

func (r *RepositoryIdentifier) Name() string

Name returns the repository name.

func (*RepositoryIdentifier) Owner

func (r *RepositoryIdentifier) Owner() string

Owner returns the repository owner.

func (*RepositoryIdentifier) String

func (r *RepositoryIdentifier) String() string

String implements the fmt.Stringer interface.

type StateTransitionError

type StateTransitionError struct {
	FromState string // The current state
	ToState   string // The attempted target state
	Reason    string // Why the transition is invalid
	// contains filtered or unexported fields
}

StateTransitionError represents an invalid state transition attempt. This error occurs when attempting to move an entity from one state to another in a way that violates the state machine rules.

func NewStateTransitionError

func NewStateTransitionError(domain, fromState, toState, reason string, cause error) *StateTransitionError

NewStateTransitionError creates a state transition error. State transition errors are permanent since they represent invalid state machine operations.

func (StateTransitionError) Code

func (e StateTransitionError) Code() string

Code returns the error code.

func (StateTransitionError) Domain

func (e StateTransitionError) Domain() string

Domain returns the domain context.

func (*StateTransitionError) Error

func (e *StateTransitionError) Error() string

Error implements the error interface with state information.

func (StateTransitionError) IsPermanent

func (e StateTransitionError) IsPermanent() bool

IsPermanent returns whether this error is permanent.

func (StateTransitionError) Unwrap

func (e StateTransitionError) Unwrap() error

Unwrap returns the underlying error.

type StateTransitionEvent

type StateTransitionEvent struct {
	*BaseEvent
	Repository     string    // Repository in "owner/name" format
	PRNumber       int       // Pull request number
	FromState      string    // Previous state
	ToState        string    // New state
	Reason         string    // Why the transition occurred
	Actor          string    // Who/what triggered the transition (user, system, etc.)
	TransitionedAt time.Time // When the transition occurred
}

StateTransitionEvent is published whenever a PR or deployment transitions between states. This provides audit trail and enables state change notifications.

func NewStateTransitionEvent

func NewStateTransitionEvent(aggregateID, repository string, prNumber int, fromState, toState, reason, actor string) *StateTransitionEvent

NewStateTransitionEvent creates a new state transition event.

type ValidationError

type ValidationError struct {
	ValidatorName string            // Name of the validator that failed
	FieldName     string            // Field that failed validation (if applicable)
	Value         interface{}       // The invalid value (if safe to include)
	Constraints   map[string]string // Violated constraints (e.g., "min": "5", "max": "100")
	// contains filtered or unexported fields
}

ValidationError represents a domain validation failure. This error indicates that an entity, value object, or operation violated business rules or invariants. Validation errors are always permanent.

func NewValidationError

func NewValidationError(domain, validatorName, message string, cause error) *ValidationError

NewValidationError creates a validation error. Validation errors are always permanent since they represent business rule violations.

func (ValidationError) Code

func (e ValidationError) Code() string

Code returns the error code.

func (ValidationError) Domain

func (e ValidationError) Domain() string

Domain returns the domain context.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface with enhanced detail.

func (ValidationError) IsPermanent

func (e ValidationError) IsPermanent() bool

IsPermanent returns whether this error is permanent.

func (ValidationError) Unwrap

func (e ValidationError) Unwrap() error

Unwrap returns the underlying error.

func (*ValidationError) WithConstraint

func (e *ValidationError) WithConstraint(name, value string) *ValidationError

WithConstraint adds a constraint violation detail.

func (*ValidationError) WithField

func (e *ValidationError) WithField(fieldName string, value interface{}) *ValidationError

WithField adds field information to the validation error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL