plugin

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package plugin provides the public interface for ReleasePilot plugins.

Package plugin provides the public interface for ReleasePilot plugins.

Package plugin provides the public interface for ReleasePilot plugins. Plugin authors should implement this interface to create compatible plugins.

Package plugin provides the public interface for ReleasePilot plugins.

Package plugin provides the public interface for ReleasePilot plugins. This file contains types that would normally be generated by protoc.

Index

Constants

View Source
const (
	// PluginName is the name used for the plugin map.
	PluginName = "release-pilot-plugin"

	// MagicCookieKey is the key for the plugin handshake.
	MagicCookieKey = "RELEASE_PILOT_PLUGIN"

	// MagicCookieValue is the value for the plugin handshake.
	MagicCookieValue = "release-pilot-v1"
)

Variables

Handshake is the handshake config for plugins.

View Source
var PluginMap = map[string]plugin.Plugin{
	PluginName: &GRPCPlugin{},
}

PluginMap is the map of plugin implementations.

Functions

func BuildMentionText

func BuildMentionText(mentions []string, format MentionFormat) string

BuildMentionText formats a list of user mentions for messaging platforms. It handles various mention formats (with/without @ prefix, special syntax).

func IsPlugin

func IsPlugin() bool

IsPlugin returns true if the current process is running as a plugin.

func RegisterPluginServer

func RegisterPluginServer(s *grpc.Server, srv PluginServer)

RegisterPluginServer registers a PluginServer with a gRPC server.

func Serve

func Serve(impl Plugin)

Serve starts the plugin server with the given plugin implementation. This should be called from the plugin's main function.

func ServeTest

func ServeTest(impl Plugin) (*plugin.ReattachConfig, func())

ServeTest starts the plugin server in test mode. This returns a reattach config for the test harness.

func ValidateAssetPath

func ValidateAssetPath(assetPath string) (string, error)

ValidateAssetPath validates a file path for use as a release asset. It prevents path traversal attacks and ensures the file exists.

Types

type Artifact

type Artifact struct {
	// Name is the artifact name.
	Name string `json:"name"`
	// Path is the artifact path (local file or URL).
	Path string `json:"path"`
	// Type is the artifact type (file, url, etc.).
	Type string `json:"type"`
	// Size is the artifact size in bytes.
	Size int64 `json:"size,omitempty"`
	// Checksum is the artifact checksum.
	Checksum string `json:"checksum,omitempty"`
}

Artifact represents a file or resource created by a plugin.

type ArtifactProto

type ArtifactProto struct {
	Name     string
	Path     string
	Type     string
	Size     int64
	Checksum string
}

ArtifactProto is the protobuf artifact.

type CategorizedChanges

type CategorizedChanges struct {
	// Features lists feature commits.
	Features []ConventionalCommit `json:"features,omitempty"`
	// Fixes lists bug fix commits.
	Fixes []ConventionalCommit `json:"fixes,omitempty"`
	// Breaking lists breaking change commits.
	Breaking []ConventionalCommit `json:"breaking,omitempty"`
	// Performance lists performance improvement commits.
	Performance []ConventionalCommit `json:"performance,omitempty"`
	// Refactor lists refactoring commits.
	Refactor []ConventionalCommit `json:"refactor,omitempty"`
	// Docs lists documentation commits.
	Docs []ConventionalCommit `json:"docs,omitempty"`
	// Other lists other commits.
	Other []ConventionalCommit `json:"other,omitempty"`
}

CategorizedChanges contains commits grouped by category.

type CategorizedChangesProto

type CategorizedChangesProto struct {
	Features    []*ConventionalCommitProto
	Fixes       []*ConventionalCommitProto
	Breaking    []*ConventionalCommitProto
	Performance []*ConventionalCommitProto
	Refactor    []*ConventionalCommitProto
	Docs        []*ConventionalCommitProto
	Other       []*ConventionalCommitProto
}

CategorizedChangesProto is the protobuf categorized changes.

type ConfigParser

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

ConfigParser provides utilities for parsing plugin configurations. It handles type-safe extraction of values from map[string]any config with support for environment variable fallbacks.

func NewConfigParser

func NewConfigParser(config map[string]any) *ConfigParser

NewConfigParser creates a new ConfigParser for the given config map.

func (*ConfigParser) GetBool

func (p *ConfigParser) GetBool(field string) bool

GetBool extracts a boolean field. Returns false if the field is not found or not a boolean.

func (*ConfigParser) GetBoolDefault

func (p *ConfigParser) GetBoolDefault(field string, defaultVal bool) bool

GetBoolDefault extracts a boolean field with a default value.

func (*ConfigParser) GetFloat

func (p *ConfigParser) GetFloat(field string) float64

GetFloat extracts a float64 field. Returns 0 if the field is not found or not a number.

func (*ConfigParser) GetInt

func (p *ConfigParser) GetInt(field string) int

GetInt extracts an integer field. Handles both int and float64 (JSON numbers are unmarshaled as float64). Returns 0 if the field is not found or not a number.

func (*ConfigParser) GetIntDefault

func (p *ConfigParser) GetIntDefault(field string, defaultVal int) int

GetIntDefault extracts an integer field with a default value.

func (*ConfigParser) GetString

func (p *ConfigParser) GetString(field string, envVars ...string) string

GetString extracts a string field with optional fallback to environment variables. Returns empty string if the field is not found or not a string.

func (*ConfigParser) GetStringDefault added in v1.1.0

func (p *ConfigParser) GetStringDefault(field string, defaultVal string, envVars ...string) string

GetStringDefault extracts a string field with a default value. Falls back to environment variables before using the default.

func (*ConfigParser) GetStringMap

func (p *ConfigParser) GetStringMap(field string) map[string]string

GetStringMap extracts a map[string]string field. Returns nil if the field is not found or not a map. Non-string values are silently skipped.

func (*ConfigParser) GetStringSlice

func (p *ConfigParser) GetStringSlice(field string) []string

GetStringSlice extracts a string array field. Returns nil if the field is not found or not an array. Non-string elements are silently skipped.

func (*ConfigParser) Has

func (p *ConfigParser) Has(field string) bool

Has returns true if the field exists in the config (even if nil).

func (*ConfigParser) Raw

func (p *ConfigParser) Raw() map[string]any

Raw returns the underlying config map.

type ConventionalCommit

type ConventionalCommit struct {
	// Hash is the commit hash.
	Hash string `json:"hash"`
	// Type is the commit type (feat, fix, etc.).
	Type string `json:"type"`
	// Scope is the optional scope.
	Scope string `json:"scope,omitempty"`
	// Description is the commit description.
	Description string `json:"description"`
	// Body is the commit body.
	Body string `json:"body,omitempty"`
	// Breaking indicates if this is a breaking change.
	Breaking bool `json:"breaking"`
	// BreakingDescription is the breaking change description.
	BreakingDescription string `json:"breaking_description,omitempty"`
	// Issues lists referenced issues.
	Issues []string `json:"issues,omitempty"`
	// Author is the commit author.
	Author string `json:"author,omitempty"`
	// Date is the commit date.
	Date string `json:"date,omitempty"`
}

ConventionalCommit represents a parsed conventional commit.

type ConventionalCommitProto

type ConventionalCommitProto struct {
	Hash                string
	Type                string
	Scope               string
	Description         string
	Body                string
	Breaking            bool
	BreakingDescription string
	Issues              []string
	Author              string
	Date                string
}

ConventionalCommitProto is the protobuf conventional commit.

type Empty

type Empty struct{}

Empty is an empty message.

type ExecuteRequest

type ExecuteRequest struct {
	// Hook is the hook being executed.
	Hook Hook `json:"hook"`
	// Config is the plugin-specific configuration.
	Config map[string]any `json:"config"`
	// Context contains the release context.
	Context ReleaseContext `json:"context"`
	// DryRun indicates if this is a dry run.
	DryRun bool `json:"dry_run"`
}

ExecuteRequest contains the context for plugin execution.

type ExecuteRequestProto

type ExecuteRequestProto struct {
	Hook    HookProto
	Config  string
	Context *ReleaseContextProto
	DryRun  bool
}

ExecuteRequestProto is the protobuf request for Execute.

type ExecuteResponse

type ExecuteResponse struct {
	// Success indicates if the execution was successful.
	Success bool `json:"success"`
	// Message is an optional message about the execution.
	Message string `json:"message,omitempty"`
	// Error is the error message if execution failed.
	Error string `json:"error,omitempty"`
	// Outputs contains any outputs from the plugin.
	Outputs map[string]any `json:"outputs,omitempty"`
	// Artifacts lists any artifacts created by the plugin.
	Artifacts []Artifact `json:"artifacts,omitempty"`
}

ExecuteResponse contains the result of plugin execution.

type ExecuteResponseProto

type ExecuteResponseProto struct {
	Success   bool
	Message   string
	Error     string
	Outputs   string
	Artifacts []*ArtifactProto
}

ExecuteResponseProto is the protobuf response for Execute.

type GRPCClient

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

GRPCClient is the client-side implementation of the plugin gRPC interface.

func (*GRPCClient) Execute

func (c *GRPCClient) Execute(ctx context.Context, req ExecuteRequest) (*ExecuteResponse, error)

Execute runs the plugin for the given hook.

func (*GRPCClient) GetInfo

func (c *GRPCClient) GetInfo() Info

GetInfo returns plugin metadata. Uses a timeout context to prevent indefinite hangs when communicating with plugins.

func (*GRPCClient) Validate

func (c *GRPCClient) Validate(ctx context.Context, config map[string]any) (*ValidateResponse, error)

Validate validates the plugin configuration.

type GRPCPlugin

type GRPCPlugin struct {
	plugin.Plugin
	Impl Plugin
}

GRPCPlugin is the plugin implementation for gRPC.

func (*GRPCPlugin) GRPCClient

func (p *GRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

GRPCClient returns the gRPC client for this plugin.

func (*GRPCPlugin) GRPCServer

func (p *GRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error

GRPCServer returns the gRPC server for this plugin.

type GRPCServer

type GRPCServer struct {
	UnimplementedPluginServer
	Impl Plugin
}

GRPCServer is the server-side implementation of the plugin gRPC interface.

func (*GRPCServer) Execute

Execute runs the plugin for a given hook.

func (*GRPCServer) GetInfo

func (s *GRPCServer) GetInfo(ctx context.Context, req *Empty) (*PluginInfo, error)

GetInfo returns plugin metadata.

func (*GRPCServer) Validate

Validate validates the plugin configuration.

type Hook

type Hook string

Hook represents a point in the release workflow where plugins can execute.

const (
	// HookPreInit runs before initialization.
	HookPreInit Hook = "pre-init"
	// HookPostInit runs after initialization.
	HookPostInit Hook = "post-init"
	// HookPrePlan runs before planning.
	HookPrePlan Hook = "pre-plan"
	// HookPostPlan runs after planning.
	HookPostPlan Hook = "post-plan"
	// HookPreVersion runs before version bump.
	HookPreVersion Hook = "pre-version"
	// HookPostVersion runs after version bump.
	HookPostVersion Hook = "post-version"
	// HookPreNotes runs before notes generation.
	HookPreNotes Hook = "pre-notes"
	// HookPostNotes runs after notes generation.
	HookPostNotes Hook = "post-notes"
	// HookPreApprove runs before approval.
	HookPreApprove Hook = "pre-approve"
	// HookPostApprove runs after approval.
	HookPostApprove Hook = "post-approve"
	// HookPrePublish runs before publishing.
	HookPrePublish Hook = "pre-publish"
	// HookPostPublish runs after publishing.
	HookPostPublish Hook = "post-publish"
	// HookOnSuccess runs when release succeeds.
	HookOnSuccess Hook = "on-success"
	// HookOnError runs when release fails.
	HookOnError Hook = "on-error"
)

func AllHooks

func AllHooks() []Hook

AllHooks returns all available hooks in execution order.

type HookProto

type HookProto int32

HookProto is the protobuf enum for hooks.

const (
	HookProto_HOOK_UNSPECIFIED  HookProto = 0
	HookProto_HOOK_PRE_INIT     HookProto = 1
	HookProto_HOOK_POST_INIT    HookProto = 2
	HookProto_HOOK_PRE_PLAN     HookProto = 3
	HookProto_HOOK_POST_PLAN    HookProto = 4
	HookProto_HOOK_PRE_VERSION  HookProto = 5
	HookProto_HOOK_POST_VERSION HookProto = 6
	HookProto_HOOK_PRE_NOTES    HookProto = 7
	HookProto_HOOK_POST_NOTES   HookProto = 8
	HookProto_HOOK_PRE_APPROVE  HookProto = 9
	HookProto_HOOK_POST_APPROVE HookProto = 10
	HookProto_HOOK_PRE_PUBLISH  HookProto = 11
	HookProto_HOOK_POST_PUBLISH HookProto = 12
	HookProto_HOOK_ON_SUCCESS   HookProto = 13
	HookProto_HOOK_ON_ERROR     HookProto = 14
)

type Info

type Info struct {
	// Name is the plugin name.
	Name string `json:"name"`
	// Version is the plugin version.
	Version string `json:"version"`
	// Description is a short description of the plugin.
	Description string `json:"description"`
	// Author is the plugin author.
	Author string `json:"author"`
	// Hooks lists the hooks this plugin supports.
	Hooks []Hook `json:"hooks"`
	// ConfigSchema is a JSON schema for the plugin configuration.
	ConfigSchema string `json:"config_schema,omitempty"`
}

Info contains metadata about a plugin.

type MentionFormat

type MentionFormat int

MentionFormat specifies the format for user mentions.

const (
	// MentionFormatPlain uses simple @username format.
	MentionFormatPlain MentionFormat = iota
	// MentionFormatSlack uses Slack's <@USER_ID> format.
	MentionFormatSlack
	// MentionFormatDiscord uses Discord's <@USER_ID> format.
	MentionFormatDiscord
)

type Plugin

type Plugin interface {
	// GetInfo returns metadata about the plugin.
	GetInfo() Info

	// Execute runs the plugin for the given hook.
	Execute(ctx context.Context, req ExecuteRequest) (*ExecuteResponse, error)

	// Validate validates the plugin configuration.
	// The context allows for cancellation of long-running validation operations.
	Validate(ctx context.Context, config map[string]any) (*ValidateResponse, error)
}

Plugin is the interface that all plugins must implement.

type PluginClient

type PluginClient interface {
	GetInfo(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*PluginInfo, error)
	Execute(ctx context.Context, in *ExecuteRequestProto, opts ...grpc.CallOption) (*ExecuteResponseProto, error)
	Validate(ctx context.Context, in *ValidateRequestProto, opts ...grpc.CallOption) (*ValidateResponseProto, error)
}

PluginClient is the client interface for the Plugin service.

func NewPluginClient

func NewPluginClient(cc grpc.ClientConnInterface) PluginClient

NewPluginClient creates a new PluginClient.

type PluginInfo

type PluginInfo struct {
	Name         string
	Version      string
	Description  string
	Author       string
	Hooks        []string
	ConfigSchema string
}

PluginInfo contains plugin metadata.

type PluginServer

PluginServer is the server interface for the Plugin service.

type ReleaseContext

type ReleaseContext struct {
	// Version is the release version (e.g., "1.2.3").
	Version string `json:"version"`
	// PreviousVersion is the previous release version.
	PreviousVersion string `json:"previous_version,omitempty"`
	// TagName is the full tag name (e.g., "v1.2.3").
	TagName string `json:"tag_name"`
	// ReleaseType is the type of release (major, minor, patch).
	ReleaseType string `json:"release_type"`
	// RepositoryURL is the repository URL.
	RepositoryURL string `json:"repository_url,omitempty"`
	// RepositoryOwner is the repository owner.
	RepositoryOwner string `json:"repository_owner,omitempty"`
	// RepositoryName is the repository name.
	RepositoryName string `json:"repository_name,omitempty"`
	// Branch is the branch being released from.
	Branch string `json:"branch"`
	// CommitSHA is the HEAD commit SHA.
	CommitSHA string `json:"commit_sha"`
	// Changelog is the generated changelog content.
	Changelog string `json:"changelog,omitempty"`
	// ReleaseNotes is the generated release notes.
	ReleaseNotes string `json:"release_notes,omitempty"`
	// Changes contains the categorized changes.
	Changes *CategorizedChanges `json:"changes,omitempty"`
	// Environment contains filtered environment variables.
	Environment map[string]string `json:"environment,omitempty"`
}

ReleaseContext contains information about the current release.

type ReleaseContextProto

type ReleaseContextProto struct {
	Version         string
	PreviousVersion string
	TagName         string
	ReleaseType     string
	RepositoryUrl   string
	RepositoryOwner string
	RepositoryName  string
	Branch          string
	CommitSha       string
	Changelog       string
	ReleaseNotes    string
	Changes         *CategorizedChangesProto
	Environment     map[string]string
}

ReleaseContextProto is the protobuf release context.

type URLValidator

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

URLValidator provides URL validation with SSRF protection.

func NewURLValidator

func NewURLValidator(scheme string) *URLValidator

NewURLValidator creates a new URL validator requiring the given scheme.

func (*URLValidator) Validate

func (uv *URLValidator) Validate(urlString string) error

Validate validates a URL string against the configured rules.

func (*URLValidator) WithHosts

func (uv *URLValidator) WithHosts(hosts ...string) *URLValidator

WithHosts restricts URLs to specific hosts (SSRF protection).

func (*URLValidator) WithPathPrefix

func (uv *URLValidator) WithPathPrefix(prefix string) *URLValidator

WithPathPrefix requires URLs to have a specific path prefix.

type UnimplementedPluginServer

type UnimplementedPluginServer struct{}

UnimplementedPluginServer is an empty implementation of PluginServer.

func (UnimplementedPluginServer) Execute

func (UnimplementedPluginServer) GetInfo

func (UnimplementedPluginServer) Validate

type ValidateRequestProto

type ValidateRequestProto struct {
	Config string
}

ValidateRequestProto is the protobuf request for Validate.

type ValidateResponse

type ValidateResponse struct {
	// Valid indicates if the configuration is valid.
	Valid bool `json:"valid"`
	// Errors lists validation errors.
	Errors []ValidationError `json:"errors,omitempty"`
}

ValidateResponse contains the result of configuration validation.

type ValidateResponseProto

type ValidateResponseProto struct {
	Valid  bool
	Errors []*ValidationErrorProto
}

ValidateResponseProto is the protobuf response for Validate.

type ValidationBuilder

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

ValidationBuilder provides a fluent API for building validation responses.

func NewValidationBuilder

func NewValidationBuilder() *ValidationBuilder

NewValidationBuilder creates a new validation builder.

func (*ValidationBuilder) AddEnumError

func (vb *ValidationBuilder) AddEnumError(field string, validValues []string) *ValidationBuilder

AddEnumError adds an "enum" validation error for invalid values.

func (*ValidationBuilder) AddError

func (vb *ValidationBuilder) AddError(field, message, code string) *ValidationBuilder

AddError adds a validation error with field, message, and code.

func (*ValidationBuilder) AddFormatError

func (vb *ValidationBuilder) AddFormatError(field, message string) *ValidationBuilder

AddFormatError adds a "format" validation error.

func (*ValidationBuilder) AddRequired

func (vb *ValidationBuilder) AddRequired(field string) *ValidationBuilder

AddRequired adds a "required" validation error for a field.

func (*ValidationBuilder) AddTypeError

func (vb *ValidationBuilder) AddTypeError(field, expectedType string) *ValidationBuilder

AddTypeError adds a "type" validation error for a field.

func (*ValidationBuilder) AddWarning added in v1.1.0

func (vb *ValidationBuilder) AddWarning(field, message string) *ValidationBuilder

AddWarning adds a validation warning. Warnings don't fail validation but indicate potential issues that should be addressed.

func (*ValidationBuilder) Build

func (vb *ValidationBuilder) Build() *ValidateResponse

Build returns the validation response.

func (*ValidationBuilder) Errors

func (vb *ValidationBuilder) Errors() []ValidationError

Errors returns the recorded validation errors.

func (*ValidationBuilder) HasErrors

func (vb *ValidationBuilder) HasErrors() bool

HasErrors returns true if any validation errors have been recorded.

func (*ValidationBuilder) RequireString

func (vb *ValidationBuilder) RequireString(config map[string]any, field string) *ValidationBuilder

RequireString validates that a string field is present and non-empty.

func (*ValidationBuilder) RequireStringWithEnv

func (vb *ValidationBuilder) RequireStringWithEnv(config map[string]any, field string, envVars ...string) *ValidationBuilder

RequireStringWithEnv validates a string field with environment variable fallback.

func (*ValidationBuilder) ValidateEnum

func (vb *ValidationBuilder) ValidateEnum(config map[string]any, field string, validValues []string) *ValidationBuilder

ValidateEnum validates that a string field contains one of the allowed values.

func (*ValidationBuilder) ValidateRegex

func (vb *ValidationBuilder) ValidateRegex(config map[string]any, field string) *ValidationBuilder

ValidateRegex validates that a field contains a valid regex pattern.

func (*ValidationBuilder) ValidateStringSlice

func (vb *ValidationBuilder) ValidateStringSlice(config map[string]any, field string) *ValidationBuilder

ValidateStringSlice validates that all elements in an array are strings.

func (*ValidationBuilder) ValidateURL

func (vb *ValidationBuilder) ValidateURL(config map[string]any, field string) *ValidationBuilder

ValidateURL validates that a field contains a valid URL.

func (*ValidationBuilder) Warnings added in v1.1.0

func (vb *ValidationBuilder) Warnings() []string

Warnings returns the recorded validation warnings.

type ValidationError

type ValidationError struct {
	// Field is the field that failed validation.
	Field string `json:"field"`
	// Message is the error message.
	Message string `json:"message"`
	// Code is an optional error code.
	Code string `json:"code,omitempty"`
}

ValidationError represents a configuration validation error.

type ValidationErrorProto

type ValidationErrorProto struct {
	Field   string
	Message string
	Code    string
}

ValidationErrorProto is the protobuf validation error.

Jump to

Keyboard shortcuts

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