extensionmgr

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = core.TimeoutDefault

DefaultTimeout is the default execution timeout for extension scripts. Uses core.TimeoutDefault for consistency across the codebase.

View Source
const MaxOutputSize = 1024 * 1024 // 1MB

MaxOutputSize limits the amount of data read from script stdout/stderr

Variables

This section is empty.

Functions

func CloneRepository

func CloneRepository(repoURL *RepoURL) (string, error)

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

func FormatGitError(err error, gitOutput string, repoURL *RepoURL) error

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

func InstallFromURL(urlStr, configPath, extensionDirectory string) error

InstallFromURL clones a repository and installs the extension

func IsURL

func IsURL(str string) bool

IsURL checks if a string looks like a URL (has a host and path)

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

func ValidateExtensionHook(hookType string) error

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:

  1. Validates that localPath is a directory containing a valid extension
  2. Loads and validates the extension manifest (extension.yaml)
  3. Resolves the destination directory based on extensionDirectory parameter
  4. Copies extension files to the destination
  5. 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:

  1. Install extensions globally (shared across projects) using "" or by omitting the flag
  2. 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

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

func (*DefaultYAMLMarshaler) Marshal added in v0.10.0

func (m *DefaultYAMLMarshaler) Marshal(v any) ([]byte, error)

Marshal marshals config with proper indentation (2 spaces for both maps and sequences)

type DiskFullError added in v0.10.0

type DiskFullError struct {
	Path string
	Err  error
}

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

type ExtensionHookRunner struct {
	Config   *config.Config
	Executor Executor
}

ExtensionHookRunner manages the execution of extension hooks

func NewExtensionHookRunner

func NewExtensionHookRunner(cfg *config.Config) *ExtensionHookRunner

NewExtensionHookRunner creates a new ExtensionHookRunner

func (*ExtensionHookRunner) RunHooks

func (r *ExtensionHookRunner) RunHooks(ctx context.Context, hookType HookType, input *HookInput) error

RunHooks executes all enabled extensions for the specified hook point

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

type GitErrorInfo struct {
	Category    string
	Message     string
	Suggestions []string
}

GitErrorInfo contains user-friendly error information

type HomeDirectory added in v0.10.0

type HomeDirectory interface {
	Get() (string, error)
}

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

func (*MockFileCopier) CopyFile added in v0.10.0

func (m *MockFileCopier) CopyFile(src, dst string, perm os.FileMode) error

type MockHomeDirectory added in v0.10.0

type MockHomeDirectory struct {
	GetFunc func() (string, error)
}

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

type MockYAMLMarshaler added in v0.10.0

type MockYAMLMarshaler struct {
	MarshalFunc func(v any) ([]byte, error)
}

MockYAMLMarshaler is a mock implementation of YAMLMarshaler for testing

func (*MockYAMLMarshaler) Marshal added in v0.10.0

func (m *MockYAMLMarshaler) Marshal(v any) ([]byte, error)

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.

func (*OSFileCopier) CopyFile

func (c *OSFileCopier) CopyFile(src, dst string, perm core.FileMode) error

CopyFile copies a single file from src to dst with given permissions. Returns context-aware errors for common failure scenarios.

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

func ParseRepoURL(urlStr string) (*RepoURL, error)

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) CloneURL

func (r *RepoURL) CloneURL() string

CloneURL returns the HTTPS clone URL for the repository

func (*RepoURL) IsGitHubURL

func (r *RepoURL) IsGitHubURL() bool

IsGitHubURL checks if the URL is a GitHub repository

func (*RepoURL) IsGitLabURL

func (r *RepoURL) IsGitLabURL() bool

IsGitLabURL checks if the URL is a GitLab repository

func (*RepoURL) String

func (r *RepoURL) String() string

String returns a human-readable representation

type ScriptExecutor

type ScriptExecutor struct {
	Timeout time.Duration
}

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

type YAMLMarshaler interface {
	Marshal(v any) ([]byte, error)
}

YAMLMarshaler handles YAML marshaling with custom options

Jump to

Keyboard shortcuts

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