{"modulePath":"github.com/AlaudaDevops/toolbox/pr-cli","version":"v0.0.0-20261019083812-38d5e0ad0d24","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package executor\n\n## Constants\n\n```go\nconst (\n\tErrUnsupportedCommandType = \"unsupported command type: %s\"\n\tErrUnknownCommandType     = \"unknown command type: %s\"\n)\n```\nError message constants for consistency\n\n## Functions\n\n```go\nfunc GetCommandDisplayName(subCmd SubCommand) string\n```\nGetCommandDisplayName returns a display name for a command with its arguments\n\n## Types\n\n```go\ntype CommandExecutor struct {\n\t// contains filtered or unexported fields\n}\n```\nCommandExecutor orchestrates command execution with validation and result handling\n\n```go\nfunc NewCommandExecutor(ctx *ExecutionContext) *CommandExecutor\n```\nNewCommandExecutor creates a new command executor instance\n\n```go\nfunc (e *CommandExecutor) Execute(parsedCmd *ParsedCommand) (*ExecutionResult, error)\n```\nExecute executes a parsed command and returns the result\n\n```go\nfunc (e *CommandExecutor) ExecuteBuiltInCommand(command string, args []string) (*ExecutionResult, error)\n```\nExecuteBuiltInCommand executes a built-in command\n\n```go\nfunc (e *CommandExecutor) ExecuteMultiCommand(commandLines, rawCommandLines []string) (*ExecutionResult, error)\n```\nExecuteMultiCommand executes multiple commands\n\n```go\nfunc (e *CommandExecutor) ExecuteSingleCommand(command string, args []string) (*ExecutionResult, error)\n```\nExecuteSingleCommand executes a single command\n\n```go\ntype CommandType int\n```\nCommandType represents the type of parsed command\n\n```go\nconst (\n\t// SingleCommand represents a regular single command\n\tSingleCommand CommandType = iota\n\t// MultiCommand represents multiple commands in a single comment\n\tMultiCommand\n\t// BuiltInCommand represents a built-in system command\n\tBuiltInCommand\n)\n```\n\n```go\nfunc (ct CommandType) String() string\n```\nString returns the string representation of CommandType\n\n```go\ntype ExecutionConfig struct {\n\t// ValidateCommentSender determines if the command sender should be validated\n\tValidateCommentSender bool\n\n\t// ValidatePRStatus determines if PR status should be checked before execution\n\tValidatePRStatus bool\n\n\t// DebugMode enables debug logging and skips some validations\n\tDebugMode bool\n\n\t// PostErrorsAsPRComments determines if errors should be posted as PR comments\n\tPostErrorsAsPRComments bool\n\n\t// ReturnErrors determines if errors should be returned to the caller\n\tReturnErrors bool\n\n\t// StopOnFirstError determines if multi-command execution should stop on first error\n\tStopOnFirstError bool\n}\n```\nExecutionConfig holds the configuration for command execution behavior\n\n```go\nfunc NewCLIExecutionConfig(debugMode bool) *ExecutionConfig\n```\nNewCLIExecutionConfig creates a new execution configuration for CLI mode\n\n```go\nfunc NewWebhookExecutionConfig() *ExecutionConfig\n```\nNewWebhookExecutionConfig creates a new execution configuration for webhook mode\n\n```go\ntype ExecutionContext struct {\n\t// PRHandler is the handler for PR operations\n\tPRHandler PRHandlerInterface\n\n\t// Logger is the logger instance for logging\n\tLogger logrus.FieldLogger\n\n\t// Config is the execution configuration\n\tConfig *ExecutionConfig\n\n\t// MetricsRecorder records execution metrics\n\tMetricsRecorder MetricsRecorder\n\n\t// Platform is the git platform (github, gitlab, gitea)\n\tPlatform string\n\n\t// CommentSender is the user who triggered the command\n\tCommentSender string\n\n\t// TriggerComment is the original comment that triggered the command\n\tTriggerComment string\n}\n```\nExecutionContext holds the context for command execution\n\n```go\ntype ExecutionResult struct {\n\t// Success indicates if the execution was successful\n\tSuccess bool\n\n\t// Error contains the error if execution failed\n\tError error\n\n\t// CommandType indicates the type of command that was executed\n\tCommandType CommandType\n\n\t// Results contains the results of sub-commands for multi-command execution\n\tResults []SubCommandResult\n}\n```\nExecutionResult represents the result of a command execution\n\n```go\nfunc NewErrorResult(cmdType CommandType, err error) *ExecutionResult\n```\nNewErrorResult creates a new failed execution result\n\n```go\nfunc NewMultiCommandResult(results []SubCommandResult) *ExecutionResult\n```\nNewMultiCommandResult creates a new multi-command execution result\n\n```go\nfunc NewSuccessResult(cmdType CommandType) *ExecutionResult\n```\nNewSuccessResult creates a new successful execution result\n\n```go\ntype MetricsRecorder interface {\n\t// RecordCommandExecution records a command execution event\n\t// platform: the git platform (github, gitlab, gitea)\n\t// command: the command name\n\t// status: the execution status (success, failure)\n\tRecordCommandExecution(platform, command, status string)\n\n\t// RecordProcessingDuration records the duration of command processing\n\t// platform: the git platform (github, gitlab, gitea)\n\t// command: the command name\n\t// duration: the processing duration\n\tRecordProcessingDuration(platform, command string, duration time.Duration)\n}\n```\nMetricsRecorder defines the interface for recording execution metrics\n\n```go\ntype NoOpMetricsRecorder struct{}\n```\nNoOpMetricsRecorder is a no-op implementation of MetricsRecorder\n\n```go\nfunc (n *NoOpMetricsRecorder) RecordCommandExecution(platform, command, status string)\n```\nRecordCommandExecution does nothing\n\n```go\nfunc (n *NoOpMetricsRecorder) RecordProcessingDuration(platform, command string, duration time.Duration)\n```\nRecordProcessingDuration does nothing\n\n```go\ntype PRHandlerInterface interface {\n\tExecuteCommand(command string, args []string) error\n\tPostComment(body string) error\n\tCheckPRStatus(expectedStatus string) error\n\tGetCommentsWithCache() ([]git.Comment, error)\n}\n```\nPRHandlerInterface defines the interface for PR handler operations needed by the executor\n\n```go\ntype ParsedCommand struct {\n\tType            CommandType\n\tCommand         string\n\tArgs            []string\n\tCommandLines    []string // Used only for MultiCommand type (processed)\n\tRawCommandLines []string // Used only for MultiCommand type (original, unprocessed)\n}\n```\nParsedCommand encapsulates a parsed command with its type and data\n\n```go\nfunc ParseCommand(commentStr string) (*ParsedCommand, error)\n```\nParseCommand parses a trigger comment and returns a structured command object\n\n```go\ntype ResultHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nResultHandler handles command execution results\n\n```go\nfunc NewResultHandler(ctx *ExecutionContext) *ResultHandler\n```\nNewResultHandler creates a new result handler instance\n\n```go\nfunc (r *ResultHandler) FormatSubCommandResult(result SubCommandResult) string\n```\nFormatSubCommandResult formats a single sub-command result\n\n```go\nfunc (r *ResultHandler) HandleMultiCommandResults(results []SubCommandResult) error\n```\nHandleMultiCommandResults handles results from multi-command execution\n\n```go\nfunc (r *ResultHandler) HandleSingleCommandError(command string, err error) error\n```\nHandleSingleCommandError handles errors from single command execution\n\n```go\ntype SubCommand struct {\n\tCommand string\n\tArgs    []string\n}\n```\nSubCommand represents a single command in a multi-command execution\n\n```go\nfunc ParseMultiCommandLines(commandLines []string) ([]SubCommand, error)\n```\nParseMultiCommandLines parses multiple command lines into SubCommand structs\n\n```go\ntype SubCommandResult struct {\n\t// Command is the command name\n\tCommand string\n\n\t// Args are the command arguments\n\tArgs []string\n\n\t// Success indicates if the sub-command was successful\n\tSuccess bool\n\n\t// Error contains the error if the sub-command failed\n\tError error\n}\n```\nSubCommandResult represents the result of a single sub-command in multi-command execution\n\n```go\ntype Validator struct {\n\t// contains filtered or unexported fields\n}\n```\nValidator handles validation logic for command execution\n\n```go\nfunc NewValidator(ctx *ExecutionContext) *Validator\n```\nNewValidator creates a new validator instance\n\n```go\nfunc (v *Validator) ValidateMultiCommand(subCommands []SubCommand, rawCommandLines []string) error\n```\nValidateMultiCommand validates multiple commands before execution\n\n```go\nfunc (v *Validator) ValidateSingleCommand(command string) error\n```\nValidateSingleCommand validates a single command before execution\n\n","path":"github.com/AlaudaDevops/toolbox/pr-cli/pkg/executor","name":"executor","synopsis":"","isRedistributable":true}
