version

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package version provides utilities for semantic versioning

Package version provides utilities for semantic versioning

Index

Constants

View Source
const FrameworkVersion = "0.1.0"

Current version of the framework

Variables

This section is empty.

Functions

func Compare

func Compare(v1, v2 Version) int

Compare compares two versions Returns:

-1 if v1 < v2
 0 if v1 == v2
+1 if v1 > v2

func ComputeHash

func ComputeHash(content []byte) string

ComputeHash computes the SHA-256 hash of a file

func Equal

func Equal(v1, v2 Version) bool

Equal checks if two versions are equal

func FormatVersionDiff

func FormatVersionDiff(oldV, newV Version) string

FormatVersionDiff formats the difference between versions

func GetFileExtension

func GetFileExtension(path string) string

GetFileExtension gets the extension of a file

func GreaterThan

func GreaterThan(v1, v2 Version) bool

GreaterThan checks if v1 is greater than v2

func IsBinaryFile

func IsBinaryFile(path string) bool

IsBinaryFile checks if a file is a binary file based on its extension

func IsCodeFile

func IsCodeFile(path string) bool

IsCodeFile checks if a file is a code file based on its extension

func IsConfigFile

func IsConfigFile(path string) bool

IsConfigFile checks if a file is a configuration file based on its extension

func IsPluginVersionCompatible

func IsPluginVersionCompatible(pluginVersion, minFrameworkVersion, maxFrameworkVersion string) (bool, error)

IsPluginVersionCompatible checks if a plugin version is compatible with the framework

func IsTextFile

func IsTextFile(path string) bool

IsTextFile checks if a file is a text file based on its extension

func LessThan

func LessThan(v1, v2 Version) bool

LessThan checks if v1 is less than v2

func ReadFileContent

func ReadFileContent(r io.Reader, maxSize int64) ([]byte, error)

ReadFileContent reads the content of a file from a reader

Types

type AnalysisResult

type AnalysisResult struct {
	// LocalVersion is the local version
	LocalVersion *Version

	// RemoteVersion is the remote version
	RemoteVersion *Version

	// Diff is the difference between local and remote versions
	Diff *DiffResult

	// DependencyGraph is the dependency graph
	DependencyGraph *DependencyGraph

	// UpdateRequired indicates if an update is required
	UpdateRequired bool

	// ImpactedItems are the items impacted by the update
	ImpactedItems []string

	// AnalysisTime is the time the analysis was performed
	AnalysisTime time.Time
}

AnalysisResult represents the result of a version analysis

type Analyzer

type Analyzer struct {
	// Options are the analyzer options
	Options *AnalyzerOptions

	// LocalRepo is the local repository
	LocalRepo interfaces.Repository

	// RemoteRepo is the remote repository
	RemoteRepo interfaces.Repository

	// DependencyGraph is the dependency graph
	DependencyGraph *DependencyGraph
}

Analyzer analyzes template and module versions

func NewAnalyzer

func NewAnalyzer(localRepo, remoteRepo interfaces.Repository, options *AnalyzerOptions) *Analyzer

NewAnalyzer creates a new version analyzer

func (*Analyzer) AnalyzeAll

func (a *Analyzer) AnalyzeAll(ctx context.Context) (map[string]*AnalysisResult, error)

AnalyzeAll analyzes all templates and modules

func (*Analyzer) AnalyzeModule

func (a *Analyzer) AnalyzeModule(ctx context.Context, modulePath string) (*AnalysisResult, error)

AnalyzeModule analyzes a module

func (*Analyzer) AnalyzeTemplate

func (a *Analyzer) AnalyzeTemplate(ctx context.Context, templatePath string) (*AnalysisResult, error)

AnalyzeTemplate analyzes a template

type AnalyzerOptions

type AnalyzerOptions struct {
	// DiffOptions are the options for file diffing
	DiffOptions *DiffOptions

	// IncludeDependencies determines if dependencies should be analyzed
	IncludeDependencies bool

	// MaxConcurrentOperations is the maximum number of concurrent operations
	MaxConcurrentOperations int

	// Timeout is the timeout for operations
	Timeout time.Duration

	// TemplatePatterns are the patterns for template files
	TemplatePatterns []string

	// ModulePatterns are the patterns for module files
	ModulePatterns []string
}

AnalyzerOptions represents options for the version analyzer

func DefaultAnalyzerOptions

func DefaultAnalyzerOptions() *AnalyzerOptions

DefaultAnalyzerOptions returns the default analyzer options

type ContentDiff

type ContentDiff struct {
	// Path is the path to the file
	Path string

	// Type is the type of difference
	Type DiffType

	// Chunks is the list of changed chunks
	Chunks []*DiffChunk
}

ContentDiff represents a difference between two file contents

type Dependency

type Dependency struct {
	// Node is the dependency node
	Node *DependencyNode

	// VersionConstraint is the version constraint for the dependency
	VersionConstraint string

	// IsOptional indicates if the dependency is optional
	IsOptional bool

	// IsCompatible indicates if the dependency is compatible
	IsCompatible bool
}

Dependency represents a dependency between two nodes

type DependencyGraph

type DependencyGraph struct {
	// Nodes is the list of nodes in the graph
	Nodes map[string]*DependencyNode

	// RootNodes is the list of nodes with no dependents
	RootNodes []*DependencyNode

	// LeafNodes is the list of nodes with no dependencies
	LeafNodes []*DependencyNode
}

DependencyGraph represents a graph of dependencies

func NewDependencyGraph

func NewDependencyGraph() *DependencyGraph

NewDependencyGraph creates a new dependency graph

func (*DependencyGraph) AddDependency

func (g *DependencyGraph) AddDependency(fromID, toID, versionConstraint string, isOptional bool) error

AddDependency adds a dependency between two nodes

func (*DependencyGraph) AddNode

func (g *DependencyGraph) AddNode(id, name, nodeType string, version *Version, metadata map[string]interface{}) *DependencyNode

AddNode adds a node to the graph

func (*DependencyGraph) GetAllNodes

func (g *DependencyGraph) GetAllNodes() []*DependencyNode

GetAllNodes gets all nodes in the graph

func (*DependencyGraph) GetDependencies

func (g *DependencyGraph) GetDependencies(id string) ([]*DependencyNode, error)

GetDependencies gets all dependencies of a node

func (*DependencyGraph) GetDependents

func (g *DependencyGraph) GetDependents(id string) ([]*DependencyNode, error)

GetDependents gets all nodes that depend on a node

func (*DependencyGraph) GetImpactedNodes

func (g *DependencyGraph) GetImpactedNodes(id string) ([]*DependencyNode, error)

GetImpactedNodes gets all nodes that would be impacted by a change to a node

func (*DependencyGraph) GetIncompatibleDependencies

func (g *DependencyGraph) GetIncompatibleDependencies() []*Dependency

GetIncompatibleDependencies gets all incompatible dependencies in the graph

func (*DependencyGraph) GetNode

func (g *DependencyGraph) GetNode(id string) *DependencyNode

GetNode gets a node by ID

func (*DependencyGraph) GetNodesByType

func (g *DependencyGraph) GetNodesByType(nodeType string) []*DependencyNode

GetNodesByType gets all nodes of a specific type

func (*DependencyGraph) GetTopologicalOrder

func (g *DependencyGraph) GetTopologicalOrder() ([]*DependencyNode, error)

GetTopologicalOrder returns the nodes in topological order

func (*DependencyGraph) GetTransitiveDependencies

func (g *DependencyGraph) GetTransitiveDependencies(id string) ([]*DependencyNode, error)

GetTransitiveDependencies gets all transitive dependencies of a node

func (*DependencyGraph) GetTransitiveDependents

func (g *DependencyGraph) GetTransitiveDependents(id string) ([]*DependencyNode, error)

GetTransitiveDependents gets all transitive dependents of a node

func (*DependencyGraph) RemoveDependency

func (g *DependencyGraph) RemoveDependency(fromID, toID string) error

RemoveDependency removes a dependency between two nodes

func (*DependencyGraph) RemoveNode

func (g *DependencyGraph) RemoveNode(id string) bool

RemoveNode removes a node from the graph

type DependencyNode

type DependencyNode struct {
	// ID is the unique identifier for the node
	ID string

	// Name is the name of the node
	Name string

	// Version is the version of the node
	Version *Version

	// Type is the type of the node (e.g., "template", "module")
	Type string

	// Dependencies is the list of dependencies
	Dependencies []*Dependency

	// Dependents is the list of nodes that depend on this node
	Dependents []*DependencyNode

	// Metadata is additional metadata for the node
	Metadata map[string]interface{}
}

DependencyNode represents a node in the dependency graph

type DiffChunk

type DiffChunk struct {
	// OldStart is the starting line number in the old file (1-based)
	OldStart int

	// OldLines is the number of lines in the old file
	OldLines int

	// NewStart is the starting line number in the new file (1-based)
	NewStart int

	// NewLines is the number of lines in the new file
	NewLines int

	// Content is the content of the chunk
	Content []string
}

DiffChunk represents a chunk of a content difference

type DiffOptions

type DiffOptions struct {
	// IgnoreWhitespace ignores whitespace changes
	IgnoreWhitespace bool

	// IgnoreCase ignores case changes
	IgnoreCase bool

	// IgnoreLineEndings ignores line ending changes
	IgnoreLineEndings bool

	// MaxContentSize is the maximum content size to diff in bytes
	MaxContentSize int64

	// IncludeContent includes content diffs
	IncludeContent bool

	// IncludeUnchanged includes unchanged files
	IncludeUnchanged bool
}

DiffOptions represents options for differential analysis

func DefaultDiffOptions

func DefaultDiffOptions() *DiffOptions

DefaultDiffOptions returns the default diff options

type DiffResult

type DiffResult struct {
	// FileDiffs is the list of file differences
	FileDiffs []*FileDiff

	// ContentDiffs is the list of content differences
	ContentDiffs []*ContentDiff

	// OldVersion is the old version
	OldVersion *Version

	// NewVersion is the new version
	NewVersion *Version

	// DiffTime is the time the diff was performed
	DiffTime time.Time
}

DiffResult represents the result of a differential analysis

func DiffFiles

func DiffFiles(oldFiles, newFiles []*FileInfo, options *DiffOptions) *DiffResult

DiffFiles compares two sets of files and returns the differences

func (*DiffResult) GetChangeSummary

func (r *DiffResult) GetChangeSummary() string

GetChangeSummary returns a summary of the changes

func (*DiffResult) GetChangedFiles

func (r *DiffResult) GetChangedFiles() []*FileDiff

GetChangedFiles returns a list of changed files

func (*DiffResult) GetChangedPaths

func (r *DiffResult) GetChangedPaths() []string

GetChangedPaths returns a list of changed file paths

func (*DiffResult) HasChanges

func (r *DiffResult) HasChanges() bool

HasChanges returns true if there are any changes

type DiffType

type DiffType string

DiffType represents the type of difference between two files

const (
	// Added means the file was added
	Added DiffType = "added"
	// Modified means the file was modified
	Modified DiffType = "modified"
	// Deleted means the file was deleted
	Deleted DiffType = "deleted"
	// Unchanged means the file was not changed
	Unchanged DiffType = "unchanged"
)

type FileDiff

type FileDiff struct {
	// Path is the path to the file
	Path string

	// Type is the type of difference
	Type DiffType

	// OldHash is the hash of the old file
	OldHash string

	// NewHash is the hash of the new file
	NewHash string

	// OldSize is the size of the old file in bytes
	OldSize int64

	// NewSize is the size of the new file in bytes
	NewSize int64

	// OldModTime is the modification time of the old file
	OldModTime time.Time

	// NewModTime is the modification time of the new file
	NewModTime time.Time
}

FileDiff represents a difference between two files

type FileInfo

type FileInfo struct {
	// Path is the path to the file
	Path string

	// Hash is the hash of the file
	Hash string

	// Size is the size of the file in bytes
	Size int64

	// ModTime is the modification time of the file
	ModTime time.Time

	// Content is the content of the file
	Content []byte
}

FileInfo represents information about a file

type FrameworkInfo

type FrameworkInfo struct {
	// Version is the current version of the framework
	Version string
	// MinPluginVersion is the minimum plugin version supported
	MinPluginVersion string
	// MaxPluginVersion is the maximum plugin version supported
	MaxPluginVersion string
}

FrameworkInfo contains information about the framework

func GetFrameworkInfo

func GetFrameworkInfo() *FrameworkInfo

GetFrameworkInfo returns information about the framework

type SemVersion

type SemVersion struct {
	// Major version number
	Major int

	// Minor version number
	Minor int

	// Patch version number
	Patch int

	// Prerelease identifiers (e.g., "alpha.1", "beta.2")
	Prerelease string

	// Build metadata (e.g., "build.123")
	Build string
}

SemVersion represents a semantic version

func MustParse

func MustParse(version string) *SemVersion

MustParse parses a version string into a Version object It panics if the version string is invalid

func Parse

func Parse(version string) (*SemVersion, error)

Parse parses a version string into a Version object

func (*SemVersion) Compare

func (v *SemVersion) Compare(other *SemVersion) int

Compare compares two versions Returns -1 if v < other, 0 if v == other, 1 if v > other

func (*SemVersion) Equal

func (v *SemVersion) Equal(other *SemVersion) bool

Equal returns true if v == other

func (*SemVersion) GreaterThan

func (v *SemVersion) GreaterThan(other *SemVersion) bool

GreaterThan returns true if v > other

func (*SemVersion) IncrementMajor

func (v *SemVersion) IncrementMajor() *SemVersion

IncrementMajor increments the major version and resets minor and patch to 0

func (*SemVersion) IncrementMinor

func (v *SemVersion) IncrementMinor() *SemVersion

IncrementMinor increments the minor version and resets patch to 0

func (*SemVersion) IncrementPatch

func (v *SemVersion) IncrementPatch() *SemVersion

IncrementPatch increments the patch version

func (*SemVersion) IsBackwardsCompatible

func (v *SemVersion) IsBackwardsCompatible(other *SemVersion) bool

IsBackwardsCompatible checks if the version is backwards compatible with the given version using semantic versioning rules (major version must match and be >= the other version)

func (*SemVersion) IsCompatible

func (v *SemVersion) IsCompatible(other *SemVersion) bool

IsCompatible checks if the version is compatible with the given version using semantic versioning rules (major version must match)

func (*SemVersion) LessThan

func (v *SemVersion) LessThan(other *SemVersion) bool

LessThan returns true if v < other

func (*SemVersion) String

func (v *SemVersion) String() string

String returns the string representation of a version

func (*SemVersion) WithBuild

func (v *SemVersion) WithBuild(build string) *SemVersion

WithBuild returns a new version with the given build string

func (*SemVersion) WithPrerelease

func (v *SemVersion) WithPrerelease(prerelease string) *SemVersion

WithPrerelease returns a new version with the given prerelease string

type Version

type Version struct {
	Major      int
	Minor      int
	Patch      int
	PreRelease string
	BuildMeta  string
}

Version represents a semantic version

func ParseVersion

func ParseVersion(versionStr string) (Version, error)

ParseVersion parses a version string into a Version struct

func (Version) String

func (v Version) String() string

String returns the string representation of a Version

type VersionChangeType

type VersionChangeType int

VersionChangeType represents the type of version change

const (
	NoChange VersionChangeType = iota
	PatchChange
	MinorChange
	MajorChange
)

func DetermineChangeType

func DetermineChangeType(oldV, newV Version) VersionChangeType

DetermineChangeType determines the type of change between versions

Jump to

Keyboard shortcuts

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