Documentation
¶
Index ¶
- Constants
- func CloneRepository(repoURL *RepoURL) (string, error)
- func FormatGitError(err error, gitOutput string, repoURL *RepoURL) error
- func InstallFromURL(urlStr, configPath, extensionDirectory string) error
- func IsURL(str string) bool
- func LoadExtensionsForHook(cfg *config.Config, hookType HookType) ([]*extensions.ExtensionManifest, error)
- func PrintGitError(err error)
- func RunPostBumpHooks(ctx context.Context, cfg *config.Config, ...) error
- func RunPreBumpHooks(ctx context.Context, cfg *config.Config, ...) error
- func ValidateExtensionHook(hookType string) error
- func ValidateGitAvailable() error
- type ConfigUpdater
- type DefaultConfigUpdater
- type DefaultExtensionRegistrar
- type DefaultManifestLoader
- type DefaultYAMLMarshaler
- type DiskFullError
- type Executor
- type ExtensionHookRunner
- type ExtensionRegistrar
- type FilePermissionError
- type GitCloneError
- type GitErrorInfo
- type HomeDirectory
- type HookInput
- type HookOutput
- type HookType
- type ManifestLoader
- type MockConfigUpdater
- type MockFileCopier
- type MockHomeDirectory
- type MockManifestLoader
- type MockYAMLMarshaler
- type ModuleInfo
- type OSFileCopier
- type OSHomeDirectory
- type RepoURL
- type ScriptExecutor
- type YAMLMarshaler
Constants ¶
const DefaultTimeout = core.TimeoutDefault
DefaultTimeout is the default execution timeout for extension scripts. Uses core.TimeoutDefault for consistency across the codebase.
const MaxOutputSize = 1024 * 1024 // 1MB
MaxOutputSize limits the amount of data read from script stdout/stderr
Variables ¶
This section is empty.
Functions ¶
func CloneRepository ¶
CloneRepository clones a repository to a temporary directory. If repoURL.Ref is specified, clones that specific version/branch/commit.
func FormatGitError ¶ added in v0.10.0
FormatGitError creates a user-friendly error message from git output. It parses the git error output to identify common issues and provides context-aware suggestions to help users resolve the problem.
If a known error pattern is detected, returns a formatted error with helpful suggestions. Otherwise, returns the original error with git output.
func InstallFromURL ¶
InstallFromURL clones a repository and installs the extension
func LoadExtensionsForHook ¶
func LoadExtensionsForHook(cfg *config.Config, hookType HookType) ([]*extensions.ExtensionManifest, error)
LoadExtensionsForHook returns all enabled extensions that support the specified hook
func PrintGitError ¶ added in v0.10.0
func PrintGitError(err error)
PrintGitError prints a formatted git error to the console using the printer package. This provides a styled, user-friendly error message in the terminal.
func RunPostBumpHooks ¶
func RunPostBumpHooks(ctx context.Context, cfg *config.Config, version, previousVersion, bumpType string, prerelease, metadata *string, moduleInfo *ModuleInfo) error
RunPostBumpHooks is a convenience function to run post-bump hooks
func RunPreBumpHooks ¶
func RunPreBumpHooks(ctx context.Context, cfg *config.Config, version, previousVersion, bumpType string, moduleInfo *ModuleInfo) error
RunPreBumpHooks is a convenience function to run pre-bump hooks
func ValidateExtensionHook ¶
ValidateExtensionHook validates that a hook type is valid
func ValidateGitAvailable ¶
func ValidateGitAvailable() error
ValidateGitAvailable checks if git is available in the system
Types ¶
type ConfigUpdater ¶ added in v0.10.0
type ConfigUpdater interface {
AddExtension(path string, extension config.ExtensionConfig) error
RemoveExtension(path string, extensionName string) error
SetExtensionEnabled(path string, extensionName string, enabled bool) error
}
ConfigUpdater handles extension configuration updates
type DefaultConfigUpdater ¶ added in v0.10.0
type DefaultConfigUpdater struct {
// contains filtered or unexported fields
}
DefaultConfigUpdater implements ConfigUpdater for updating extension configurations
func NewDefaultConfigUpdater ¶ added in v0.10.0
func NewDefaultConfigUpdater(marshaler YAMLMarshaler) *DefaultConfigUpdater
NewDefaultConfigUpdater creates a new DefaultConfigUpdater with the given marshaler
func (*DefaultConfigUpdater) AddExtension ¶ added in v0.10.0
func (u *DefaultConfigUpdater) AddExtension(path string, extension config.ExtensionConfig) error
AddExtension appends an extension entry to the YAML config at the given path. It avoids duplicates and preserves existing comments and formatting by only replacing the extensions section rather than rewriting the entire file.
func (*DefaultConfigUpdater) RemoveExtension ¶ added in v0.10.0
func (u *DefaultConfigUpdater) RemoveExtension(path string, extensionName string) error
RemoveExtension removes the named extension from the YAML config at the given path. It preserves existing comments and formatting by only replacing the extensions section rather than rewriting the entire file.
func (*DefaultConfigUpdater) SetExtensionEnabled ¶ added in v0.10.0
func (u *DefaultConfigUpdater) SetExtensionEnabled(path string, extensionName string, enabled bool) error
SetExtensionEnabled sets the enabled field for the named extension in the YAML config at the given path. It preserves existing comments and formatting by only replacing the extensions section rather than rewriting the entire file.
type DefaultExtensionRegistrar ¶ added in v0.10.0
type DefaultExtensionRegistrar struct {
// contains filtered or unexported fields
}
DefaultExtensionRegistrar implements ExtensionRegistrar for registering local extensions
func NewDefaultExtensionRegistrar ¶ added in v0.10.0
func NewDefaultExtensionRegistrar( manifestLoader ManifestLoader, configUpdater ConfigUpdater, fileCopier core.FileCopier, homeDir HomeDirectory, ) *DefaultExtensionRegistrar
NewDefaultExtensionRegistrar creates a new DefaultExtensionRegistrar with the given dependencies
func NewDefaultExtensionRegistrarInstance ¶ added in v0.10.0
func NewDefaultExtensionRegistrarInstance() *DefaultExtensionRegistrar
NewDefaultExtensionRegistrarInstance creates a new registrar with default implementations
func (*DefaultExtensionRegistrar) Register ¶ added in v0.10.0
func (r *DefaultExtensionRegistrar) Register(localPath, configPath, extensionDirectory string) error
Register installs an extension from a local directory into the extension directory and registers it in the project's configuration file.
The function performs the following steps:
- Validates that localPath is a directory containing a valid extension
- Loads and validates the extension manifest (extension.yaml)
- Resolves the destination directory based on extensionDirectory parameter
- Copies extension files to the destination
- Updates the configuration file to register the extension
Parameters:
- localPath: Path to the extension source directory (must contain extension.yaml)
- configPath: Path to the sley configuration file (e.g., ".sley.yaml")
- extensionDirectory: Base directory for extension installation (see below)
Extension Directory Resolution:
If extensionDirectory is "" (empty): Global installation Uses ~/.sley-extensions as the base directory Example: ~/.sley-extensions/extension-name
If extensionDirectory is specified: Project-local installation Uses <extensionDirectory>/.sley-extensions as the base directory Examples: extensionDirectory="." -> ./.sley-extensions/extension-name extensionDirectory="/path/to/project" -> /path/to/project/.sley-extensions/extension-name
This allows users to:
- Install extensions globally (shared across projects) using "" or by omitting the flag
- Install extensions locally (project-specific) by specifying a directory path
Returns an error if:
- localPath is not a directory
- extension.yaml is missing or invalid
- configuration file doesn't exist
- file operations fail (permissions, disk space, etc.)
type DefaultManifestLoader ¶ added in v0.10.0
type DefaultManifestLoader struct{}
DefaultManifestLoader implements ManifestLoader using extensions.LoadExtensionManifestFn
func (*DefaultManifestLoader) Load ¶ added in v0.10.0
func (l *DefaultManifestLoader) Load(path string) (*extensions.ExtensionManifest, error)
Load loads an extension manifest from the given path
type DefaultYAMLMarshaler ¶ added in v0.10.0
type DefaultYAMLMarshaler struct{}
DefaultYAMLMarshaler implements YAMLMarshaler with proper indentation
type DiskFullError ¶ added in v0.10.0
DiskFullError indicates no space left on device
func (*DiskFullError) Error ¶ added in v0.10.0
func (e *DiskFullError) Error() string
func (*DiskFullError) Unwrap ¶ added in v0.10.0
func (e *DiskFullError) Unwrap() error
type Executor ¶
type Executor interface {
Execute(ctx context.Context, scriptPath string, input *HookInput) (*HookOutput, error)
}
Executor defines the interface for executing extension scripts
type ExtensionHookRunner ¶
ExtensionHookRunner manages the execution of extension hooks
func NewExtensionHookRunner ¶
func NewExtensionHookRunner(cfg *config.Config) *ExtensionHookRunner
NewExtensionHookRunner creates a new ExtensionHookRunner
type ExtensionRegistrar ¶ added in v0.10.0
type ExtensionRegistrar interface {
Register(localPath, configPath, extensionDirectory string) error
}
ExtensionRegistrar handles registering local extensions
type FilePermissionError ¶ added in v0.10.0
type FilePermissionError struct {
Src string
Dst string
Op string // operation: "open", "create", "copy"
Err error
}
FilePermissionError indicates insufficient permissions for file operations
func (*FilePermissionError) Error ¶ added in v0.10.0
func (e *FilePermissionError) Error() string
func (*FilePermissionError) Unwrap ¶ added in v0.10.0
func (e *FilePermissionError) Unwrap() error
type GitCloneError ¶ added in v0.10.0
type GitCloneError struct {
RepoURL *RepoURL
ErrorInfo *GitErrorInfo
GitOutput string
OriginalErr error
}
GitCloneError represents a structured git clone error with helpful context
func (*GitCloneError) Error ¶ added in v0.10.0
func (e *GitCloneError) Error() string
Error implements the error interface
func (*GitCloneError) Unwrap ¶ added in v0.10.0
func (e *GitCloneError) Unwrap() error
Unwrap returns the original error for error unwrapping
type GitErrorInfo ¶ added in v0.10.0
GitErrorInfo contains user-friendly error information
type HomeDirectory ¶ added in v0.10.0
HomeDirectory provides access to the user's home directory
type HookInput ¶
type HookInput struct {
Hook string `json:"hook"`
Version string `json:"version"`
PreviousVersion string `json:"previous_version,omitempty"`
BumpType string `json:"bump_type,omitempty"`
Prerelease *string `json:"prerelease,omitempty"`
Metadata *string `json:"metadata,omitempty"`
ProjectRoot string `json:"project_root"`
ModuleDir string `json:"module_dir,omitempty"` // Directory containing the .version file (for monorepo support)
ModuleName string `json:"module_name,omitempty"` // Module identifier (for monorepo support)
Config map[string]any `json:"config,omitempty"` // Extension-specific configuration
}
HookInput represents the JSON input passed to an extension script
type HookOutput ¶
type HookOutput struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
HookOutput represents the JSON output expected from an extension script
func ExecuteExtensionHook ¶
func ExecuteExtensionHook(ctx context.Context, extensionPath, entry string, input *HookInput) (*HookOutput, error)
ExecuteExtensionHook is a convenience function to execute an extension hook It resolves the full script path relative to the extension directory and validates that the script remains within the extension directory to prevent path traversal attacks
type HookType ¶
type HookType string
HookType represents the different hook points available in the extension system
const ( // PreBumpHook is called before any version bump operation PreBumpHook HookType = "pre-bump" // PostBumpHook is called after a version bump completes successfully PostBumpHook HookType = "post-bump" // PreReleaseHook is called before pre-release changes are applied PreReleaseHook HookType = "pre-release" // ValidateHook is called to validate version changes ValidateHook HookType = "validate" )
type ManifestLoader ¶ added in v0.10.0
type ManifestLoader interface {
Load(path string) (*extensions.ExtensionManifest, error)
}
ManifestLoader handles loading extension manifests
type MockConfigUpdater ¶ added in v0.10.0
type MockConfigUpdater struct {
AddExtensionFunc func(path string, extension config.ExtensionConfig) error
RemoveExtensionFunc func(path string, extensionName string) error
SetExtensionEnabledFunc func(path string, extensionName string, enabled bool) error
}
MockConfigUpdater is a mock implementation of ConfigUpdater for testing
func (*MockConfigUpdater) AddExtension ¶ added in v0.10.0
func (m *MockConfigUpdater) AddExtension(path string, extension config.ExtensionConfig) error
func (*MockConfigUpdater) RemoveExtension ¶ added in v0.10.0
func (m *MockConfigUpdater) RemoveExtension(path string, extensionName string) error
func (*MockConfigUpdater) SetExtensionEnabled ¶ added in v0.10.0
func (m *MockConfigUpdater) SetExtensionEnabled(path string, extensionName string, enabled bool) error
type MockFileCopier ¶ added in v0.10.0
type MockFileCopier struct {
CopyDirFunc func(src, dst string) error
CopyFileFunc func(src, dst string, perm os.FileMode) error
}
MockFileCopier is a mock implementation of core.FileCopier for testing
func (*MockFileCopier) CopyDir ¶ added in v0.10.0
func (m *MockFileCopier) CopyDir(src, dst string) error
type MockHomeDirectory ¶ added in v0.10.0
MockHomeDirectory is a mock implementation of HomeDirectory for testing
func (*MockHomeDirectory) Get ¶ added in v0.10.0
func (m *MockHomeDirectory) Get() (string, error)
type MockManifestLoader ¶ added in v0.10.0
type MockManifestLoader struct {
LoadFunc func(path string) (*extensions.ExtensionManifest, error)
}
MockManifestLoader is a mock implementation of ManifestLoader for testing
func (*MockManifestLoader) Load ¶ added in v0.10.0
func (m *MockManifestLoader) Load(path string) (*extensions.ExtensionManifest, error)
type MockYAMLMarshaler ¶ added in v0.10.0
MockYAMLMarshaler is a mock implementation of YAMLMarshaler for testing
type ModuleInfo ¶
type ModuleInfo struct {
Dir string // Directory containing the .version file
Name string // Module identifier
}
ModuleInfo contains optional module context for monorepo support.
type OSFileCopier ¶
type OSFileCopier struct {
// contains filtered or unexported fields
}
OSFileCopier implements core.FileCopier using OS file operations.
func NewOSFileCopier ¶
func NewOSFileCopier() *OSFileCopier
NewOSFileCopier creates an OSFileCopier with default OS implementations.
func (*OSFileCopier) CopyDir ¶
func (c *OSFileCopier) CopyDir(src, dst string) error
CopyDir recursively copies all files and subdirectories from src to dst.
type OSHomeDirectory ¶ added in v0.10.0
type OSHomeDirectory struct{}
OSHomeDirectory implements HomeDirectory using os.UserHomeDir
func (*OSHomeDirectory) Get ¶ added in v0.10.0
func (h *OSHomeDirectory) Get() (string, error)
Get returns the user's home directory
type RepoURL ¶
type RepoURL struct {
Host string // github.com, gitlab.com, etc.
Owner string // user or organization
Repo string // repository name
Subdir string // optional subdirectory path within the repository
Ref string // optional version tag, branch name, or commit hash
Raw string // original URL
}
RepoURL represents a parsed repository URL
func ParseRepoURL ¶
ParseRepoURL parses various repository URL formats into a RepoURL struct. Supports version/branch/commit specification via @ separator:
- github.com/user/repo@v1.0.0 (version tag)
- github.com/user/repo@develop (branch)
- github.com/user/repo@abc123 (commit hash)
- github.com/user/repo/subdir@v1.0.0 (subdirectory with ref)
func (*RepoURL) IsGitHubURL ¶
IsGitHubURL checks if the URL is a GitHub repository
func (*RepoURL) IsGitLabURL ¶
IsGitLabURL checks if the URL is a GitLab repository
type ScriptExecutor ¶
ScriptExecutor implements the Executor interface for running shell scripts
func NewScriptExecutor ¶
func NewScriptExecutor() *ScriptExecutor
NewScriptExecutor creates a new ScriptExecutor with the default timeout
func NewScriptExecutorWithTimeout ¶
func NewScriptExecutorWithTimeout(timeout time.Duration) *ScriptExecutor
NewScriptExecutorWithTimeout creates a new ScriptExecutor with a custom timeout
func (*ScriptExecutor) Execute ¶
func (e *ScriptExecutor) Execute(ctx context.Context, scriptPath string, input *HookInput) (*HookOutput, error)
Execute runs an extension script with the provided input and returns the output
type YAMLMarshaler ¶ added in v0.10.0
YAMLMarshaler handles YAML marshaling with custom options