Documentation
¶
Index ¶
- Constants
- func GetCommandDisplayName(subCmd SubCommand) string
- type CommandExecutor
- func (e *CommandExecutor) Execute(parsedCmd *ParsedCommand) (*ExecutionResult, error)
- func (e *CommandExecutor) ExecuteBuiltInCommand(command string, args []string) (*ExecutionResult, error)
- func (e *CommandExecutor) ExecuteMultiCommand(commandLines, rawCommandLines []string) (*ExecutionResult, error)
- func (e *CommandExecutor) ExecuteSingleCommand(command string, args []string) (*ExecutionResult, error)
- type CommandType
- type ExecutionConfig
- type ExecutionContext
- type ExecutionResult
- type MetricsRecorder
- type NoOpMetricsRecorder
- type PRHandlerInterface
- type ParsedCommand
- type ResultHandler
- type SubCommand
- type SubCommandResult
- type Validator
Constants ¶
const ( ErrUnsupportedCommandType = "unsupported command type: %s" ErrUnknownCommandType = "unknown command type: %s" )
Error message constants for consistency
Variables ¶
This section is empty.
Functions ¶
func GetCommandDisplayName ¶
func GetCommandDisplayName(subCmd SubCommand) string
GetCommandDisplayName returns a display name for a command with its arguments
Types ¶
type CommandExecutor ¶
type CommandExecutor struct {
// contains filtered or unexported fields
}
CommandExecutor orchestrates command execution with validation and result handling
func NewCommandExecutor ¶
func NewCommandExecutor(ctx *ExecutionContext) *CommandExecutor
NewCommandExecutor creates a new command executor instance
func (*CommandExecutor) Execute ¶
func (e *CommandExecutor) Execute(parsedCmd *ParsedCommand) (*ExecutionResult, error)
Execute executes a parsed command and returns the result
func (*CommandExecutor) ExecuteBuiltInCommand ¶
func (e *CommandExecutor) ExecuteBuiltInCommand(command string, args []string) (*ExecutionResult, error)
ExecuteBuiltInCommand executes a built-in command
func (*CommandExecutor) ExecuteMultiCommand ¶
func (e *CommandExecutor) ExecuteMultiCommand(commandLines, rawCommandLines []string) (*ExecutionResult, error)
ExecuteMultiCommand executes multiple commands
func (*CommandExecutor) ExecuteSingleCommand ¶
func (e *CommandExecutor) ExecuteSingleCommand(command string, args []string) (*ExecutionResult, error)
ExecuteSingleCommand executes a single command
type CommandType ¶
type CommandType int
CommandType represents the type of parsed command
const ( // SingleCommand represents a regular single command SingleCommand CommandType = iota // MultiCommand represents multiple commands in a single comment MultiCommand // BuiltInCommand represents a built-in system command BuiltInCommand )
func (CommandType) String ¶
func (ct CommandType) String() string
String returns the string representation of CommandType
type ExecutionConfig ¶
type ExecutionConfig struct {
// ValidateCommentSender determines if the command sender should be validated
ValidateCommentSender bool
// ValidatePRStatus determines if PR status should be checked before execution
ValidatePRStatus bool
// DebugMode enables debug logging and skips some validations
DebugMode bool
// PostErrorsAsPRComments determines if errors should be posted as PR comments
PostErrorsAsPRComments bool
// ReturnErrors determines if errors should be returned to the caller
ReturnErrors bool
// StopOnFirstError determines if multi-command execution should stop on first error
StopOnFirstError bool
}
ExecutionConfig holds the configuration for command execution behavior
func NewCLIExecutionConfig ¶
func NewCLIExecutionConfig(debugMode bool) *ExecutionConfig
NewCLIExecutionConfig creates a new execution configuration for CLI mode
func NewWebhookExecutionConfig ¶
func NewWebhookExecutionConfig() *ExecutionConfig
NewWebhookExecutionConfig creates a new execution configuration for webhook mode
type ExecutionContext ¶
type ExecutionContext struct {
// PRHandler is the handler for PR operations
PRHandler PRHandlerInterface
// Logger is the logger instance for logging
Logger logrus.FieldLogger
// Config is the execution configuration
Config *ExecutionConfig
// MetricsRecorder records execution metrics
MetricsRecorder MetricsRecorder
// Platform is the git platform (github, gitlab, gitea)
Platform string
// CommentSender is the user who triggered the command
CommentSender string
// TriggerComment is the original comment that triggered the command
TriggerComment string
}
ExecutionContext holds the context for command execution
type ExecutionResult ¶
type ExecutionResult struct {
// Success indicates if the execution was successful
Success bool
// Error contains the error if execution failed
Error error
// CommandType indicates the type of command that was executed
CommandType CommandType
// Results contains the results of sub-commands for multi-command execution
Results []SubCommandResult
}
ExecutionResult represents the result of a command execution
func NewErrorResult ¶
func NewErrorResult(cmdType CommandType, err error) *ExecutionResult
NewErrorResult creates a new failed execution result
func NewMultiCommandResult ¶
func NewMultiCommandResult(results []SubCommandResult) *ExecutionResult
NewMultiCommandResult creates a new multi-command execution result
func NewSuccessResult ¶
func NewSuccessResult(cmdType CommandType) *ExecutionResult
NewSuccessResult creates a new successful execution result
type MetricsRecorder ¶
type MetricsRecorder interface {
// RecordCommandExecution records a command execution event
// platform: the git platform (github, gitlab, gitea)
// command: the command name
// status: the execution status (success, failure)
RecordCommandExecution(platform, command, status string)
// RecordProcessingDuration records the duration of command processing
// platform: the git platform (github, gitlab, gitea)
// command: the command name
// duration: the processing duration
RecordProcessingDuration(platform, command string, duration time.Duration)
}
MetricsRecorder defines the interface for recording execution metrics
type NoOpMetricsRecorder ¶
type NoOpMetricsRecorder struct{}
NoOpMetricsRecorder is a no-op implementation of MetricsRecorder
func (*NoOpMetricsRecorder) RecordCommandExecution ¶
func (n *NoOpMetricsRecorder) RecordCommandExecution(platform, command, status string)
RecordCommandExecution does nothing
func (*NoOpMetricsRecorder) RecordProcessingDuration ¶
func (n *NoOpMetricsRecorder) RecordProcessingDuration(platform, command string, duration time.Duration)
RecordProcessingDuration does nothing
type PRHandlerInterface ¶
type PRHandlerInterface interface {
ExecuteCommand(command string, args []string) error
PostComment(body string) error
CheckPRStatus(expectedStatus string) error
GetCommentsWithCache() ([]git.Comment, error)
}
PRHandlerInterface defines the interface for PR handler operations needed by the executor
type ParsedCommand ¶
type ParsedCommand struct {
Type CommandType
Command string
Args []string
CommandLines []string // Used only for MultiCommand type (processed)
RawCommandLines []string // Used only for MultiCommand type (original, unprocessed)
}
ParsedCommand encapsulates a parsed command with its type and data
func ParseCommand ¶
func ParseCommand(commentStr string) (*ParsedCommand, error)
ParseCommand parses a trigger comment and returns a structured command object
type ResultHandler ¶
type ResultHandler struct {
// contains filtered or unexported fields
}
ResultHandler handles command execution results
func NewResultHandler ¶
func NewResultHandler(ctx *ExecutionContext) *ResultHandler
NewResultHandler creates a new result handler instance
func (*ResultHandler) FormatSubCommandResult ¶
func (r *ResultHandler) FormatSubCommandResult(result SubCommandResult) string
FormatSubCommandResult formats a single sub-command result
func (*ResultHandler) HandleMultiCommandResults ¶
func (r *ResultHandler) HandleMultiCommandResults(results []SubCommandResult) error
HandleMultiCommandResults handles results from multi-command execution
func (*ResultHandler) HandleSingleCommandError ¶
func (r *ResultHandler) HandleSingleCommandError(command string, err error) error
HandleSingleCommandError handles errors from single command execution
type SubCommand ¶
SubCommand represents a single command in a multi-command execution
func ParseMultiCommandLines ¶
func ParseMultiCommandLines(commandLines []string) ([]SubCommand, error)
ParseMultiCommandLines parses multiple command lines into SubCommand structs
type SubCommandResult ¶
type SubCommandResult struct {
// Command is the command name
Command string
// Args are the command arguments
Args []string
// Success indicates if the sub-command was successful
Success bool
// Error contains the error if the sub-command failed
Error error
}
SubCommandResult represents the result of a single sub-command in multi-command execution
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator handles validation logic for command execution
func NewValidator ¶
func NewValidator(ctx *ExecutionContext) *Validator
NewValidator creates a new validator instance
func (*Validator) ValidateMultiCommand ¶
func (v *Validator) ValidateMultiCommand(subCommands []SubCommand, rawCommandLines []string) error
ValidateMultiCommand validates multiple commands before execution
func (*Validator) ValidateSingleCommand ¶
ValidateSingleCommand validates a single command before execution