metadata

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataBranch = "hitch-metadata"
	MetadataFile   = "hitch.json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BranchInfo

type BranchInfo struct {
	CreatedAt            time.Time        `json:"created_at"`
	CreatedBy            string           `json:"created_by,omitempty"`
	PromotedTo           []string         `json:"promoted_to"`
	PromotedHistory      []PromotionEvent `json:"promoted_history,omitempty"`
	MergedToMainAt       *time.Time       `json:"merged_to_main_at,omitempty"`
	MergedToMainBy       string           `json:"merged_to_main_by,omitempty"`
	LastCommitAt         time.Time        `json:"last_commit_at,omitempty"`
	LastCommitSHA        string           `json:"last_commit_sha,omitempty"`
	EligibleForCleanupAt *time.Time       `json:"eligible_for_cleanup_at,omitempty"`
}

BranchInfo tracks the lifecycle of a feature branch

func (*BranchInfo) IsEligibleForCleanup added in v0.1.5

func (b *BranchInfo) IsEligibleForCleanup() bool

IsEligibleForCleanup checks if a branch is eligible for cleanup

type BranchNotFoundError

type BranchNotFoundError struct {
	Branch string
}

BranchNotFoundError is returned when a branch doesn't exist

func (*BranchNotFoundError) Error

func (e *BranchNotFoundError) Error() string

type Config

type Config struct {
	RetentionDaysAfterMerge int       `json:"retention_days_after_merge"`
	StaleDaysNoActivity     int       `json:"stale_days_no_activity"`
	BaseBranch              string    `json:"base_branch"`
	LockTimeoutMinutes      int       `json:"lock_timeout_minutes"`
	AutoRebuildOnPromote    bool      `json:"auto_rebuild_on_promote"`
	ConflictStrategy        string    `json:"conflict_strategy"`
	NotificationWebhooks    []Webhook `json:"notification_webhooks,omitempty"`
}

Config holds global configuration

type CrashDetector added in v0.1.21

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

CrashDetector detects and handles crashes during metadata operations

func NewCrashDetector added in v0.1.21

func NewCrashDetector(stateFile string) *CrashDetector

NewCrashDetector creates a new crash detector

func (*CrashDetector) CompleteOperation added in v0.1.21

func (cd *CrashDetector) CompleteOperation(opID string) error

CompleteOperation marks an operation as completed

func (*CrashDetector) EndSession added in v0.1.21

func (cd *CrashDetector) EndSession() error

EndSession ends the current crash detection session

func (*CrashDetector) GetCrashRecoveryActions added in v0.1.21

func (cd *CrashDetector) GetCrashRecoveryActions() (*CrashRecoveryActions, error)

GetCrashRecoveryActions returns actions needed to recover from a crash

func (*CrashDetector) Heartbeat added in v0.1.21

func (cd *CrashDetector) Heartbeat() error

Heartbeat updates the heartbeat timestamp

func (*CrashDetector) SetEnabled added in v0.1.21

func (cd *CrashDetector) SetEnabled(enabled bool)

SetEnabled enables or disables crash detection

func (*CrashDetector) StartOperation added in v0.1.21

func (cd *CrashDetector) StartOperation(opType, env, user string, context map[string]interface{}) (string, error)

StartOperation starts tracking an operation

func (*CrashDetector) StartSession added in v0.1.21

func (cd *CrashDetector) StartSession() error

StartSession starts a new crash detection session

func (*CrashDetector) UpdateOperation added in v0.1.21

func (cd *CrashDetector) UpdateOperation(opID, status string) error

UpdateOperation updates the status of an operation

type CrashRecoveryActions added in v0.1.21

type CrashRecoveryActions struct {
	SessionID     string       `json:"session_id"`
	CrashTime     time.Time    `json:"crash_time"`
	ProcessID     int          `json:"process_id"`
	StaleEnvs     []string     `json:"stale_envs"`
	FailedOps     []*Operation `json:"failed_ops"`
	InProgressOps []*Operation `json:"in_progress_ops"`
}

CrashRecoveryActions contains recovery actions after a crash

type CrashState added in v0.1.21

type CrashState struct {
	SessionID     string                `json:"session_id"`
	StartTime     time.Time             `json:"start_time"`
	LastHeartbeat time.Time             `json:"last_heartbeat"`
	Operations    map[string]*Operation `json:"operations"`
	LockedEnvs    map[string]string     `json:"locked_envs"` // env -> user
	MetadataHash  string                `json:"metadata_hash"`
	ProcessID     int                   `json:"process_id"`
}

CrashState represents the state of ongoing operations

type Environment

type Environment struct {
	Base              string    `json:"base"`
	Features          []string  `json:"features"`
	Locked            bool      `json:"locked"`
	LockedBy          string    `json:"locked_by,omitempty"`
	LockedAt          time.Time `json:"locked_at,omitempty"`
	LockedReason      string    `json:"locked_reason,omitempty"`
	LastRebuild       time.Time `json:"last_rebuild,omitempty"`
	LastRebuildCommit string    `json:"last_rebuild_commit,omitempty"`
}

Environment represents a deployment environment (dev, qa, etc.)

type EnvironmentLockedError

type EnvironmentLockedError struct {
	Environment string
	LockedBy    string
	LockedAt    time.Time
}

EnvironmentLockedError is returned when an environment is locked by another user

func (*EnvironmentLockedError) Error

func (e *EnvironmentLockedError) Error() string

type EnvironmentNotFoundError

type EnvironmentNotFoundError struct {
	Environment string
}

EnvironmentNotFoundError is returned when an environment doesn't exist

func (*EnvironmentNotFoundError) Error

func (e *EnvironmentNotFoundError) Error() string

type HookConfig added in v0.1.21

type HookConfig struct {
	Name       string            `json:"name"`
	Type       string            `json:"type"`                  // "builtin" or "command"
	Command    string            `json:"command,omitempty"`     // for type=command
	WorkingDir string            `json:"working_dir,omitempty"` // optional working directory
	Args       []string          `json:"args,omitempty"`        // arguments for the command
	Config     map[string]string `json:"config,omitempty"`      // configuration for builtin hooks
	Required   bool              `json:"required"`              // whether failure should block operation
}

HookConfig represents a single hook configuration

type HooksConfig added in v0.1.21

type HooksConfig struct {
	PrePromote  []HookConfig `json:"pre-promote,omitempty"`
	PostPromote []HookConfig `json:"post-promote,omitempty"`
	PreRelease  []HookConfig `json:"pre-release,omitempty"`
	PostRelease []HookConfig `json:"post-release,omitempty"`
}

HooksConfig represents hook configuration (avoiding circular import)

type InvalidMetadataError

type InvalidMetadataError struct {
	Reason string
	Err    error
}

InvalidMetadataError is returned when metadata format is invalid

func (*InvalidMetadataError) Error

func (e *InvalidMetadataError) Error() string

func (*InvalidMetadataError) Unwrap

func (e *InvalidMetadataError) Unwrap() error

type LockBackup added in v0.1.21

type LockBackup struct {
	Timestamp time.Time            `json:"timestamp"`
	Locks     map[string]LockState `json:"locks"`
	Config    LockRecoveryConfig   `json:"config"`
}

LockBackup represents a backup of lock state for recovery

type LockInfo added in v0.1.21

type LockInfo struct {
	LockedBy string    `json:"locked_by"`
	LockedAt time.Time `json:"locked_at"`
	Reason   string    `json:"reason,omitempty"`
	IsStale  bool      `json:"is_stale"`
}

LockInfo contains information about a lock

type LockManager added in v0.1.21

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

LockManager provides comprehensive lock management with recovery capabilities

func NewLockManager added in v0.1.21

func NewLockManager(meta *Metadata, workingDir string) *LockManager

NewLockManager creates a new lock manager

func (*LockManager) AcquireLock added in v0.1.21

func (lm *LockManager) AcquireLock(req LockRequest) (*LockResult, error)

AcquireLock acquires a lock for an environment with full recovery support

func (*LockManager) EndSession added in v0.1.21

func (lm *LockManager) EndSession() error

EndSession ends the current lock management session

func (*LockManager) GetStatus added in v0.1.21

func (lm *LockManager) GetStatus() (*LockManagerStatus, error)

GetStatus returns the status of the lock manager

func (*LockManager) RecoverLocks added in v0.1.21

func (lm *LockManager) RecoverLocks(userEmail string, force bool) (*RecoveryReport, error)

RecoverLocks attempts to recover from crash or stale locks

func (*LockManager) ReleaseLock added in v0.1.21

func (lm *LockManager) ReleaseLock(envName, userEmail string) error

ReleaseLock releases a lock for an environment with full recovery support

func (*LockManager) SetEnabled added in v0.1.21

func (lm *LockManager) SetEnabled(enabled bool)

SetEnabled enables or disables the lock manager

func (*LockManager) StartSession added in v0.1.21

func (lm *LockManager) StartSession() error

StartSession starts a new lock management session

type LockManagerStatus added in v0.1.21

type LockManagerStatus struct {
	Enabled            bool                   `json:"enabled"`
	SessionActive      bool                   `json:"session_active"`
	CurrentLocks       map[string]LockInfo    `json:"current_locks"`
	BackupInfo         map[string]interface{} `json:"backup_info,omitempty"`
	PanicRecoveryStats map[string]interface{} `json:"panic_recovery_stats,omitempty"`
}

LockManagerStatus contains the status of the lock manager

type LockRecoveryConfig added in v0.1.21

type LockRecoveryConfig struct {
	BackupInterval   time.Duration `json:"backup_interval"`
	MaxBackups       int           `json:"max_backups"`
	StaleLockTimeout time.Duration `json:"stale_lock_timeout"`
	CrashDetection   bool          `json:"crash_detection"`
	AutoRecovery     bool          `json:"auto_recovery"`
}

LockRecoveryConfig contains configuration for lock recovery

type LockRecoveryManager added in v0.1.21

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

LockRecoveryManager handles lock recovery operations

func NewLockRecoveryManager added in v0.1.21

func NewLockRecoveryManager(meta *Metadata, backupDir string) *LockRecoveryManager

NewLockRecoveryManager creates a new lock recovery manager

func (*LockRecoveryManager) CreateBackup added in v0.1.21

func (lrm *LockRecoveryManager) CreateBackup() error

CreateBackup creates a backup of current lock state

func (*LockRecoveryManager) DetectStaleLocks added in v0.1.21

func (lrm *LockRecoveryManager) DetectStaleLocks() ([]string, error)

DetectStaleLocks identifies locks that may be stale due to crashes

func (*LockRecoveryManager) GetBackupInfo added in v0.1.21

func (lrm *LockRecoveryManager) GetBackupInfo() (map[string]interface{}, error)

GetBackupInfo returns information about existing backups

func (*LockRecoveryManager) RecoverFromBackup added in v0.1.21

func (lrm *LockRecoveryManager) RecoverFromBackup() error

RecoverFromBackup attempts to recover lock state from the latest backup

func (*LockRecoveryManager) RecoverStaleLocks added in v0.1.21

func (lrm *LockRecoveryManager) RecoverStaleLocks(userEmail string, force bool) ([]string, error)

RecoverStaleLocks attempts to recover from stale locks

func (*LockRecoveryManager) SetConfig added in v0.1.21

func (lrm *LockRecoveryManager) SetConfig(config LockRecoveryConfig)

SetConfig updates the lock recovery configuration

func (*LockRecoveryManager) StartAutoBackup added in v0.1.21

func (lrm *LockRecoveryManager) StartAutoBackup()

StartAutoBackup starts automatic backup goroutine

func (*LockRecoveryManager) ValidateLockState added in v0.1.21

func (lrm *LockRecoveryManager) ValidateLockState() error

ValidateLockState checks for lock consistency issues

type LockRequest added in v0.1.21

type LockRequest struct {
	Environment string
	User        string
	Reason      string
	Timeout     time.Duration
	Force       bool
}

LockRequest represents a lock acquisition request

type LockResult added in v0.1.21

type LockResult struct {
	Success       bool
	Message       string
	LockAcquired  bool
	WasStale      bool
	RecoveredFrom []string
}

LockResult represents the result of a lock operation

type LockState added in v0.1.21

type LockState struct {
	Environment string    `json:"environment"`
	Locked      bool      `json:"locked"`
	LockedBy    string    `json:"locked_by,omitempty"`
	LockedAt    time.Time `json:"locked_at,omitempty"`
	Reason      string    `json:"reason,omitempty"`
}

LockState represents the state of a single lock

type MetaInfo

type MetaInfo struct {
	InitializedAt  time.Time `json:"initialized_at"`
	InitializedBy  string    `json:"initialized_by,omitempty"`
	LastModifiedAt time.Time `json:"last_modified_at"`
	LastModifiedBy string    `json:"last_modified_by,omitempty"`
	LastCommand    string    `json:"last_command,omitempty"`
	HitchVersion   string    `json:"hitch_version"`
}

MetaInfo contains metadata about the metadata itself

type Metadata

type Metadata struct {
	Version      string                 `json:"version"`
	Environments map[string]Environment `json:"environments"`
	Branches     map[string]BranchInfo  `json:"branches"`
	Config       Config                 `json:"config"`
	Hooks        *HooksConfig           `json:"hooks,omitempty"`
	Meta         MetaInfo               `json:"metadata"`
	// contains filtered or unexported fields
}

Metadata represents the complete hitch.json structure

func NewMetadata

func NewMetadata(environments []string, baseBranch string, user string) *Metadata

NewMetadata creates a new Metadata structure with defaults

func (*Metadata) AddBranchToEnvironment

func (m *Metadata) AddBranchToEnvironment(env string, branch string, user string) error

AddBranchToEnvironment adds a branch to an environment's feature list (thread-safe)

func (*Metadata) IsEnvironmentLocked

func (m *Metadata) IsEnvironmentLocked(env string) bool

IsEnvironmentLocked checks if an environment is locked

func (*Metadata) IsLockStale

func (m *Metadata) IsLockStale(env string) bool

IsLockStale checks if a lock is older than the timeout (thread-safe)

func (*Metadata) IsLockStaleUnsafe added in v0.1.21

func (m *Metadata) IsLockStaleUnsafe(env string) bool

IsLockStaleUnsafe checks if a lock is older than the timeout (unsafe, assumes mutex held)

func (*Metadata) IsLockedByUser

func (m *Metadata) IsLockedByUser(env string, user string) bool

IsLockedByUser checks if an environment is locked by a specific user

func (*Metadata) LockEnvironment

func (m *Metadata) LockEnvironment(env string, user string, reason string) error

LockEnvironment locks an environment (thread-safe)

func (*Metadata) RemoveBranchFromEnvironment

func (m *Metadata) RemoveBranchFromEnvironment(env string, branch string, user string) error

RemoveBranchFromEnvironment removes a branch from an environment's feature list

func (*Metadata) UnlockEnvironment

func (m *Metadata) UnlockEnvironment(env string) error

UnlockEnvironment unlocks an environment (thread-safe)

func (*Metadata) UnlockEnvironmentUnsafe added in v0.1.21

func (m *Metadata) UnlockEnvironmentUnsafe(env string) error

UnlockEnvironmentUnsafe unlocks an environment without locking (assumes caller holds mutex)

func (*Metadata) UpdateMeta

func (m *Metadata) UpdateMeta(user, command string)

UpdateMeta updates the metadata modification tracking

type MetadataReadError

type MetadataReadError struct {
	Reason string
	Err    error
}

MetadataReadError is returned when metadata cannot be read

func (*MetadataReadError) Error

func (e *MetadataReadError) Error() string

func (*MetadataReadError) Unwrap

func (e *MetadataReadError) Unwrap() error

type MetadataWriteError

type MetadataWriteError struct {
	Reason string
	Err    error
}

MetadataWriteError is returned when metadata cannot be written

func (*MetadataWriteError) Error

func (e *MetadataWriteError) Error() string

func (*MetadataWriteError) Unwrap

func (e *MetadataWriteError) Unwrap() error

type Operation added in v0.1.21

type Operation struct {
	ID          string                 `json:"id"`
	Type        string                 `json:"type"` // lock, unlock, promote, demote, rebuild, cleanup
	Environment string                 `json:"environment,omitempty"`
	User        string                 `json:"user"`
	StartTime   time.Time              `json:"start_time"`
	Status      string                 `json:"status"` // starting, in_progress, completing, completed, failed
	Context     map[string]interface{} `json:"context,omitempty"`
}

Operation represents an ongoing operation

type PanicInfo added in v0.1.21

type PanicInfo struct {
	Timestamp time.Time   `json:"timestamp"`
	Message   string      `json:"message"`
	Stack     []string    `json:"stack"`
	Operation string      `json:"operation"`
	Context   interface{} `json:"context,omitempty"`
}

PanicInfo contains information about a recovered panic

type PanicRecovery added in v0.1.21

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

PanicRecovery handles panic recovery for metadata operations

func NewPanicRecovery added in v0.1.21

func NewPanicRecovery() *PanicRecovery

NewPanicRecovery creates a new panic recovery handler

func (*PanicRecovery) ClearPanicLog added in v0.1.21

func (pr *PanicRecovery) ClearPanicLog()

ClearPanicLog clears the panic log

func (*PanicRecovery) GetPanicLog added in v0.1.21

func (pr *PanicRecovery) GetPanicLog() []PanicInfo

GetPanicLog returns the panic log

func (*PanicRecovery) GetRecoveryStats added in v0.1.21

func (pr *PanicRecovery) GetRecoveryStats() map[string]interface{}

GetRecoveryStats returns recovery statistics

func (*PanicRecovery) SafeLockOperation added in v0.1.21

func (pr *PanicRecovery) SafeLockOperation(meta *Metadata, envName, userEmail, reason string) error

SafeLockOperation performs a lock operation with panic recovery

func (*PanicRecovery) SafeMetadataOperation added in v0.1.21

func (pr *PanicRecovery) SafeMetadataOperation(operation string, fn func() error) error

SafeMetadataOperation performs a metadata operation with panic recovery

func (*PanicRecovery) SafeUnlockOperation added in v0.1.21

func (pr *PanicRecovery) SafeUnlockOperation(meta *Metadata, envName string) error

SafeUnlockOperation performs an unlock operation with panic recovery

func (*PanicRecovery) SetEnabled added in v0.1.21

func (pr *PanicRecovery) SetEnabled(enabled bool)

SetEnabled enables or disables panic recovery

func (*PanicRecovery) SetMaxRecoveries added in v0.1.21

func (pr *PanicRecovery) SetMaxRecoveries(max int)

SetMaxRecoveries sets the maximum number of recoveries allowed

func (*PanicRecovery) WithLockRecovery added in v0.1.21

func (pr *PanicRecovery) WithLockRecovery(meta *Metadata, operation string, envName string, fn func() error) (err error)

WithLockRecovery executes a function with panic recovery and automatic lock cleanup

func (*PanicRecovery) WithRecovery added in v0.1.21

func (pr *PanicRecovery) WithRecovery(operation string, context interface{}, fn func() error) (err error)

WithRecovery executes a function with panic recovery

type PromotionEvent

type PromotionEvent struct {
	Environment string     `json:"environment"`
	PromotedAt  time.Time  `json:"promoted_at"`
	PromotedBy  string     `json:"promoted_by,omitempty"`
	DemotedAt   *time.Time `json:"demoted_at,omitempty"`
	DemotedBy   string     `json:"demoted_by,omitempty"`
}

PromotionEvent records a single promotion/demotion event

type Reader

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

Reader handles reading metadata from the hitch-metadata branch

func NewReader

func NewReader(repo *git.Repository) *Reader

NewReader creates a new metadata reader

func (*Reader) Exists

func (r *Reader) Exists() bool

Exists checks if the hitch-metadata branch exists

func (*Reader) Read

func (r *Reader) Read() (*Metadata, error)

Read reads the metadata from the hitch-metadata branch. Returns the Metadata struct containing environment configurations and feature lists. Returns a MetadataReadError if the hitch-metadata branch doesn't exist.

type RecoveryReport added in v0.1.21

type RecoveryReport struct {
	Timestamp      time.Time `json:"timestamp"`
	RecoveredLocks []string  `json:"recovered_locks"`
	FailedRecovers []string  `json:"failed_recovers"`
	ValidatedLocks []string  `json:"validated_locks"`
	IssuesFound    []string  `json:"issues_found"`
}

RecoveryReport contains the results of a lock recovery operation

type Webhook

type Webhook struct {
	URL     string            `json:"url"`
	Events  []string          `json:"events"`
	Headers map[string]string `json:"headers,omitempty"`
}

Webhook represents a notification webhook configuration

type Writer

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

Writer handles writing metadata to the hitch-metadata branch

func NewWriter

func NewWriter(repo *git.Repository) *Writer

NewWriter creates a new metadata writer

func (*Writer) GetLastCommitHash added in v0.1.21

func (w *Writer) GetLastCommitHash() string

GetLastCommitHash returns the hash of the last commit written by this writer

func (*Writer) Write

func (w *Writer) Write(m *Metadata, commitMessage string, author string, authorEmail string) error

Write writes metadata to the hitch-metadata branch It uses optimistic concurrency control with force-with-lease nolint:gocyclo // Complex function due to sophisticated uncommitted changes handling workflow

func (*Writer) WriteInitial

func (w *Writer) WriteInitial(m *Metadata, author string, authorEmail string) error

WriteInitial creates the hitch-metadata branch and writes initial metadata

Jump to

Keyboard shortcuts

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