refactor: PR-CLI command executor refactoring #120
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🎯 Overview
This PR introduces a comprehensive refactoring of the PR-CLI command execution architecture by extracting and unifying command execution logic into a dedicated
executorpackage. This change improves code maintainability, testability, and provides a consistent execution flow across CLI and webhook modes.📋 Changes
New Architecture
pkg/executorpackage: Centralized command execution logic with clear separation of concernsExecutionConfiginstead of scattered conditionalsKey Components
1. CommandExecutor (
executor.go)2. Validator (
validator.go)3. ResultHandler (
result_handler.go)CommentedErrorto avoid duplicate comments4. ExecutionConfig (
config.go)NewCLIExecutionConfig: Posts errors as PR comments, validates comment senderNewWebhookExecutionConfig: Logs errors only, trusts webhook validation5. ExecutionResult (
result.go)6. MetricsRecorder (
metrics.go)pkg/webhook/metrics_recorder.goRefactored Components
webhook/worker.go (108 → 50 lines, 54% reduction)
CommandExecutorexecuteWithUnifiedExecutor)cmd/options.go (minor updates)
Test Coverage
executor_test.go(278 lines)validator_test.go(175 lines)result_test.go(174 lines)result_handler_test.go(136 lines)metrics_test.go(49 lines)🎁 Benefits
1. Code Reusability
2. Improved Testability
3. Better Maintainability
4. Consistent Behavior
5. Enhanced Debugging
📊 Statistics
🔍 Technical Details
Execution Flow
Configuration Modes
Error Handling
CommentedErrorto avoid duplicate error comments✅ Testing
All existing tests pass. New comprehensive test coverage includes:
🔄 Backward Compatibility
This refactoring maintains full backward compatibility:
📚 Related Documentation