-
Notifications
You must be signed in to change notification settings - Fork 81
Closed as not planned
Closed as not planned
Copy link
Labels
automationcode-qualitycookieIssue Monster Loves Cookies!Issue Monster Loves Cookies!refactoringtask-miningtesting
Description
Description
The generateYAML() function in compiler_yaml.go is likely >100 lines and handles multiple concerns (job building, validation, header generation, body generation). Splitting it into smaller functions would improve testability and readability.
Identified in: Daily Compiler Code Quality Report #12164
Current Issues
- Long function - Exceeds recommended 60-line limit
- Multiple responsibilities - Violates Single Responsibility Principle
- Hard to test - Cannot test sub-operations in isolation
- Complex logic - Difficult to understand full flow
Suggested Changes
1. Extract Job Building and Validation
// buildJobsAndValidate processes job configurations and validates structure
func buildJobsAndValidate(data *CompilerData, markdownPath string) error {
// Extract job building logic
// Extract validation logic
return nil
}2. Extract Header Generation
// generateWorkflowHeader writes YAML header (name, on, permissions)
func generateWorkflowHeader(yaml *strings.Builder, data *CompilerData) error {
// Extract header generation logic
return nil
}3. Extract Body Generation
// generateWorkflowBody writes YAML body (jobs, steps)
func generateWorkflowBody(yaml *strings.Builder, data *CompilerData) error {
// Extract body generation logic
return nil
}4. Simplified Main Function
// generateYAML orchestrates YAML generation from compiler data
func generateYAML(data *CompilerData, markdownPath string) (string, error) {
var yaml strings.Builder
yaml.Grow(initialCapacity)
if err := buildJobsAndValidate(data, markdownPath); err != nil {
return "", err
}
if err := generateWorkflowHeader(&yaml, data); err != nil {
return "", err
}
if err := generateWorkflowBody(&yaml, data); err != nil {
return "", err
}
return yaml.String(), nil
}Benefits
- Testability - Each component can be tested independently
- Readability - Clear separation of concerns
- Maintainability - Easier to modify specific sections
- Reusability - Sub-functions can be reused elsewhere
Files Affected
pkg/workflow/compiler_yaml.go- Main refactoringpkg/workflow/compiler_yaml_test.go- Add tests for new functions
Success Criteria
-
generateYAML()orchestration function < 40 lines - Each extracted function < 60 lines
- Each function has single responsibility
- New unit tests for each extracted function
- All existing tests pass
- No change in generated YAML output
Testing Strategy
func TestBuildJobsAndValidate(t *testing.T) {
// Test job building in isolation
}
func TestGenerateWorkflowHeader(t *testing.T) {
// Test header generation with mock data
}
func TestGenerateWorkflowBody(t *testing.T) {
// Test body generation with mock data
}
func TestGenerateYAML_Integration(t *testing.T) {
// Test full workflow (existing test)
}Estimated Effort
2-3 hours - Medium complexity refactoring
Source
Extracted from Daily Compiler Code Quality Report discussion #12164
Priority: Low - Code quality improvement, not blocking
AI generated by Discussion Task Miner - Code Quality Improvement Agent
- expires on Feb 18, 2026, 9:12 AM UTC
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
automationcode-qualitycookieIssue Monster Loves Cookies!Issue Monster Loves Cookies!refactoringtask-miningtesting