updater

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPipeline

func NewPipeline(orchestrator *UpdateOrchestrator) *processor.Pipeline

NewPipeline creates the updater pipeline using the shared processor architecture

Types

type ApplyResult

type ApplyResult struct {
	PackageName    string   `json:"package_name" yaml:"package_name"`
	FilePath       string   `json:"file_path" yaml:"file_path"`
	OldVersion     string   `json:"old_version" yaml:"old_version"`
	NewVersion     string   `json:"new_version" yaml:"new_version"`
	OldEpoch       int64    `json:"old_epoch" yaml:"old_epoch"`
	NewEpoch       int64    `json:"new_epoch" yaml:"new_epoch"`
	UpdatesApplied []string `json:"updates_applied" yaml:"updates_applied"`
	SharedUpdates  []string `json:"shared_updates,omitempty" yaml:"shared_updates,omitempty"`
	BackupCreated  string   `json:"backup_created,omitempty" yaml:"backup_created,omitempty"`
	FileWasWritten bool     `json:"file_was_written" yaml:"file_was_written"`
	IsManual       bool     `json:"is_manual" yaml:"is_manual"`
	Error          string   `json:"error,omitempty" yaml:"error,omitempty"`
}

ApplyResult represents the result of an update application (used by CLI)

type ChecksumHelper

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

ChecksumHelper handles SHA256 calculation for URLs and files

func NewChecksumHelper

func NewChecksumHelper() *ChecksumHelper

NewChecksumHelper creates a new checksum helper

func NewChecksumHelperWithClient

func NewChecksumHelperWithClient(client *http.Client) *ChecksumHelper

NewChecksumHelperWithClient creates a checksum helper with custom HTTP client

func (*ChecksumHelper) CalculateSHA256FromFile

func (ch *ChecksumHelper) CalculateSHA256FromFile(filePath string) (string, error)

CalculateSHA256FromFile calculates SHA256 hash of a local file

func (*ChecksumHelper) CalculateSHA256FromURL

func (ch *ChecksumHelper) CalculateSHA256FromURL(ctx context.Context, url string) (string, error)

CalculateSHA256FromURL downloads content from a URL and calculates its SHA256

type PipelineChange

type PipelineChange struct {
	Type        string `json:"type" yaml:"type"`               // "insert", "update", "remove"
	Index       int    `json:"index" yaml:"index"`             // pipeline index
	Field       string `json:"field" yaml:"field"`             // specific field changed
	OldValue    string `json:"old_value" yaml:"old_value"`     // previous value
	NewValue    string `json:"new_value" yaml:"new_value"`     // new value
	Description string `json:"description" yaml:"description"` // human-readable description
	Reason      string `json:"reason" yaml:"reason"`           // why the change was made
}

PipelineChange represents a modification made to a pipeline

type PipelineProcessor

type PipelineProcessor struct {
	processor.BaseStage
	// contains filtered or unexported fields
}

PipelineProcessor implements ApplyStage for pipeline modifications

func NewPipelineProcessor

func NewPipelineProcessor(orchestrator *UpdateOrchestrator) *PipelineProcessor

func (*PipelineProcessor) Apply

func (*PipelineProcessor) ShouldRun

func (pp *PipelineProcessor) ShouldRun(ctx context.Context, p processor.Processor) (bool, error)

type ProcessorOptions

type ProcessorOptions struct {
	DryRun        bool   `json:"dry_run" yaml:"dry_run"`
	Force         bool   `json:"force" yaml:"force"`
	SharedUpdates bool   `json:"shared_updates" yaml:"shared_updates"`
	BackupSuffix  string `json:"backup_suffix" yaml:"backup_suffix"`
	TempDir       string `json:"temp_dir" yaml:"temp_dir"`
}

ProcessorOptions configures processor behavior

type SharedUpdater

type SharedUpdater struct{}

SharedUpdater handles updates to packages with shared dependencies

func NewSharedUpdater

func NewSharedUpdater() *SharedUpdater

NewSharedUpdater creates a new shared updater

func (*SharedUpdater) GetSharedDependencies

func (su *SharedUpdater) GetSharedDependencies(dirPath string) (map[string][]string, error)

GetSharedDependencies analyzes a directory to find which packages have shared dependencies

func (*SharedUpdater) UpdateSharedDependencies

func (su *SharedUpdater) UpdateSharedDependencies(ctx context.Context, updatedFilePath, updatedPackageName string, opts *ProcessorOptions) ([]string, error)

UpdateSharedDependencies updates packages that depend on the updated package

type UpdateOrchestrator

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

UpdateOrchestrator manages the package update pipeline using a stage-based architecture It replaces the previous Updater with a cleaner separation of concerns and proper logging context throughout the entire process.

func NewOrchestrator

func NewOrchestrator() *UpdateOrchestrator

NewOrchestrator creates a new update orchestrator with default HTTP timeout

func NewOrchestratorWithTimeout

func NewOrchestratorWithTimeout(httpTimeout time.Duration) *UpdateOrchestrator

NewOrchestratorWithTimeout creates a new update orchestrator with a custom HTTP timeout

func (*UpdateOrchestrator) GetServiceClients

func (o *UpdateOrchestrator) GetServiceClients() (anitya *anitya.Client, github *githubClient.Client, git *git.Client, http *http.Client)

GetServiceClients returns the service clients for use by stages

func (*UpdateOrchestrator) GetVersionComponents

func (o *UpdateOrchestrator) GetVersionComponents() (*VersionFilter, *VersionComparator)

GetVersionComponents returns the version filtering and comparison components

func (*UpdateOrchestrator) ProcessMultipleApplies

func (o *UpdateOrchestrator) ProcessMultipleApplies(ctx context.Context, filePaths []string, options ProcessorOptions) ([]*UpdaterProcessor, error)

ProcessMultipleApplies processes multiple packages for updates

func (*UpdateOrchestrator) ProcessMultipleChecks

func (o *UpdateOrchestrator) ProcessMultipleChecks(ctx context.Context, filePaths []string) ([]*UpdaterProcessor, error)

ProcessMultipleChecks processes multiple packages for update checking

func (*UpdateOrchestrator) ProcessPackageApply

func (o *UpdateOrchestrator) ProcessPackageApply(ctx context.Context, filePath string, options ProcessorOptions) (*UpdaterProcessor, error)

ProcessPackageApply runs the full pipeline (check + apply) for a package This includes checking for updates and applying them if found

func (*UpdateOrchestrator) ProcessPackageCheck

func (o *UpdateOrchestrator) ProcessPackageCheck(ctx context.Context, filePath string) (*UpdaterProcessor, error)

ProcessPackageCheck runs only the check pipeline for a package This loads the configuration and determines if updates are available

func (*UpdateOrchestrator) ProcessPackageCheckWithConfig

func (o *UpdateOrchestrator) ProcessPackageCheckWithConfig(ctx context.Context, filePath string, cfg *melange.Configuration, originalContent []byte) (*UpdaterProcessor, error)

ProcessPackageCheckWithConfig runs check pipeline with pre-loaded configuration

type UpdateResult

type UpdateResult struct {
	PackageName    string `json:"package_name" yaml:"package_name"`
	FilePath       string `json:"file_path" yaml:"file_path"`
	CurrentVersion string `json:"current_version" yaml:"current_version"`
	LatestVersion  string `json:"latest_version" yaml:"latest_version"`
	HasUpdate      bool   `json:"has_update" yaml:"has_update"`
	UpdateSource   string `json:"update_source" yaml:"update_source"`
	IsManual       bool   `json:"is_manual" yaml:"is_manual"`
	Error          string `json:"error,omitempty" yaml:"error,omitempty"`
}

UpdateResult represents the result of an update check (used by CLI)

type UpdaterProcessor

type UpdaterProcessor struct {
	processor.BaseProcessor

	// Update-specific state
	UpdateAvailable bool             `json:"update_available"`
	CurrentVersion  string           `json:"current_version"`
	LatestVersion   string           `json:"latest_version"`
	UpdateSource    string           `json:"update_source"`
	IsManual        bool             `json:"is_manual"`
	VersionChanged  bool             `json:"version_changed"`
	PipelineChanges []PipelineChange `json:"pipeline_changes"`
}

UpdaterProcessor extends BaseProcessor for updater-specific functionality

func NewUpdaterProcessor

func NewUpdaterProcessor(filePath, packageName, currentVersion string, currentEpoch int64) *UpdaterProcessor

NewUpdaterProcessor creates a new updater processor extending BaseProcessor

func (*UpdaterProcessor) AddPipelineChange

func (p *UpdaterProcessor) AddPipelineChange(change PipelineChange)

AddPipelineChange records a pipeline modification

func (*UpdaterProcessor) GetCurrentVersion

func (p *UpdaterProcessor) GetCurrentVersion() string

GetCurrentVersion returns the current version (override to use local field)

func (*UpdaterProcessor) GetLatestVersion

func (p *UpdaterProcessor) GetLatestVersion() string

GetLatestVersion returns the latest version

func (*UpdaterProcessor) GetNewEpoch

func (p *UpdaterProcessor) GetNewEpoch() int64

GetNewEpoch returns the new epoch (delegate to base processor)

func (*UpdaterProcessor) GetOldEpoch

func (p *UpdaterProcessor) GetOldEpoch() int64

GetOldEpoch returns the old epoch (for compatibility)

func (*UpdaterProcessor) HasChanges

func (p *UpdaterProcessor) HasChanges() bool

HasChanges returns true if any changes were made to the package

func (*UpdaterProcessor) IsVersionChanged

func (p *UpdaterProcessor) IsVersionChanged() bool

IsVersionChanged returns true if version was changed

func (*UpdaterProcessor) SetUpdateResult

func (p *UpdaterProcessor) SetUpdateResult(hasUpdate bool, latestVersion, source string, isManual bool)

SetUpdateResult updates the processor with check results

func (*UpdaterProcessor) SetVersionUpdate

func (p *UpdaterProcessor) SetVersionUpdate(old, new string)

SetVersionUpdate marks that the version was updated (implements Processor interface)

func (*UpdaterProcessor) Summary

func (p *UpdaterProcessor) Summary() string

Summary returns a brief summary of the processing results

func (*UpdaterProcessor) WithPipeline

func (p *UpdaterProcessor) WithPipeline(stage string, index int) *slog.Logger

WithPipeline creates a child logger for a specific pipeline operation

func (*UpdaterProcessor) WithStage

func (p *UpdaterProcessor) WithStage(stage string) *slog.Logger

WithStage creates a child logger for a specific processing stage

type VersionApplier

type VersionApplier struct {
	processor.BaseStage
}

VersionApplier implements ApplyStage for version updates

func NewVersionApplier

func NewVersionApplier() *VersionApplier

func (*VersionApplier) Apply

func (*VersionApplier) ShouldRun

func (va *VersionApplier) ShouldRun(ctx context.Context, p processor.Processor) (bool, error)

type VersionChecker

type VersionChecker struct {
	processor.BaseStage
	// contains filtered or unexported fields
}

VersionChecker implements CheckStage for the shared processor architecture

func NewVersionChecker

func NewVersionChecker(orchestrator *UpdateOrchestrator) *VersionChecker

func (*VersionChecker) Check

type VersionComparator

type VersionComparator struct {
}

VersionComparator handles version comparison logic

func NewVersionComparator

func NewVersionComparator() *VersionComparator

NewVersionComparator creates a new version comparator

func (*VersionComparator) ApplyTransform

func (vc *VersionComparator) ApplyTransform(version, match, replace string) (string, error)

ApplyTransform applies a regex-based transformation to a version string

func (*VersionComparator) Compare

func (vc *VersionComparator) Compare(v1, v2 string) (int, error)

Compare compares two versions, returning: -1 if v1 < v2

0 if v1 == v2
1 if v1 > v2

func (*VersionComparator) FilterPreReleases

func (vc *VersionComparator) FilterPreReleases(versions []string, enablePreReleases bool) []string

FilterPreReleases filters out pre-release versions unless enabled

func (*VersionComparator) IsNewer

func (vc *VersionComparator) IsNewer(currentVersion, newVersion string) (bool, error)

IsNewer returns true if newVersion is newer than currentVersion

func (*VersionComparator) IsValidVersion

func (vc *VersionComparator) IsValidVersion(version string, allowPreRelease bool) bool

IsValidVersion checks if a version is valid semver and handles pre-release filtering

func (*VersionComparator) MatchesIgnorePattern

func (vc *VersionComparator) MatchesIgnorePattern(version string, patterns []string) (bool, error)

MatchesIgnorePattern checks if a version matches any of the ignore patterns

type VersionFilter

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

VersionFilter handles version filtering logic based on update configuration

func NewVersionFilter

func NewVersionFilter() *VersionFilter

NewVersionFilter creates a new version filter

func (*VersionFilter) ProcessVersion

func (vf *VersionFilter) ProcessVersion(version string, updateConfig *melange.Update) (string, bool, error)

ProcessVersion processes a single version through all the update configuration rules

func (*VersionFilter) ProcessVersionWithLogger

func (vf *VersionFilter) ProcessVersionWithLogger(version string, updateConfig *melange.Update, logger *slog.Logger) (string, bool, error)

ProcessVersionWithLogger processes a single version with a specific logger for context

Jump to

Keyboard shortcuts

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