Documentation
¶
Overview ¶
Package version provides utilities for semantic versioning
Package version provides utilities for semantic versioning
Index ¶
- Constants
- func Compare(v1, v2 Version) int
- func ComputeHash(content []byte) string
- func Equal(v1, v2 Version) bool
- func FormatVersionDiff(oldV, newV Version) string
- func GetFileExtension(path string) string
- func GreaterThan(v1, v2 Version) bool
- func IsBinaryFile(path string) bool
- func IsCodeFile(path string) bool
- func IsConfigFile(path string) bool
- func IsPluginVersionCompatible(pluginVersion, minFrameworkVersion, maxFrameworkVersion string) (bool, error)
- func IsTextFile(path string) bool
- func LessThan(v1, v2 Version) bool
- func ReadFileContent(r io.Reader, maxSize int64) ([]byte, error)
- type AnalysisResult
- type Analyzer
- type AnalyzerOptions
- type ContentDiff
- type Dependency
- type DependencyGraph
- func (g *DependencyGraph) AddDependency(fromID, toID, versionConstraint string, isOptional bool) error
- func (g *DependencyGraph) AddNode(id, name, nodeType string, version *Version, metadata map[string]interface{}) *DependencyNode
- func (g *DependencyGraph) GetAllNodes() []*DependencyNode
- func (g *DependencyGraph) GetDependencies(id string) ([]*DependencyNode, error)
- func (g *DependencyGraph) GetDependents(id string) ([]*DependencyNode, error)
- func (g *DependencyGraph) GetImpactedNodes(id string) ([]*DependencyNode, error)
- func (g *DependencyGraph) GetIncompatibleDependencies() []*Dependency
- func (g *DependencyGraph) GetNode(id string) *DependencyNode
- func (g *DependencyGraph) GetNodesByType(nodeType string) []*DependencyNode
- func (g *DependencyGraph) GetTopologicalOrder() ([]*DependencyNode, error)
- func (g *DependencyGraph) GetTransitiveDependencies(id string) ([]*DependencyNode, error)
- func (g *DependencyGraph) GetTransitiveDependents(id string) ([]*DependencyNode, error)
- func (g *DependencyGraph) RemoveDependency(fromID, toID string) error
- func (g *DependencyGraph) RemoveNode(id string) bool
- type DependencyNode
- type DiffChunk
- type DiffOptions
- type DiffResult
- type DiffType
- type FileDiff
- type FileInfo
- type FrameworkInfo
- type SemVersion
- func (v *SemVersion) Compare(other *SemVersion) int
- func (v *SemVersion) Equal(other *SemVersion) bool
- func (v *SemVersion) GreaterThan(other *SemVersion) bool
- func (v *SemVersion) IncrementMajor() *SemVersion
- func (v *SemVersion) IncrementMinor() *SemVersion
- func (v *SemVersion) IncrementPatch() *SemVersion
- func (v *SemVersion) IsBackwardsCompatible(other *SemVersion) bool
- func (v *SemVersion) IsCompatible(other *SemVersion) bool
- func (v *SemVersion) LessThan(other *SemVersion) bool
- func (v *SemVersion) String() string
- func (v *SemVersion) ToVersion() *Version
- func (v *SemVersion) WithBuild(build string) *SemVersion
- func (v *SemVersion) WithPrerelease(prerelease string) *SemVersion
- type Version
- type VersionChangeType
Constants ¶
const FrameworkVersion = "0.1.0"
Current version of the framework
Variables ¶
This section is empty.
Functions ¶
func ComputeHash ¶
ComputeHash computes the SHA-256 hash of a file
func FormatVersionDiff ¶
FormatVersionDiff formats the difference between versions
func GetFileExtension ¶
GetFileExtension gets the extension of a file
func GreaterThan ¶
GreaterThan checks if v1 is greater than v2
func IsBinaryFile ¶
IsBinaryFile checks if a file is a binary file based on its extension
func IsCodeFile ¶
IsCodeFile checks if a file is a code file based on its extension
func IsConfigFile ¶
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 ¶
IsTextFile checks if a file is a text file based on its extension
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 ¶
AnalyzeAll analyzes all templates and modules
func (*Analyzer) AnalyzeModule ¶
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 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) ToVersion ¶ added in v0.8.0
func (v *SemVersion) ToVersion() *Version
ToVersion converts a SemVersion to 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 ¶
Version represents a semantic version
func ParseVersion ¶
ParseVersion parses a version string into a Version struct
func (*Version) IsCompatible ¶ added in v0.8.0
IsCompatible checks if this version is compatible with the other version (same major 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