Skip to content

[task] Consolidate safe output job builders to reduce duplication #4670

Closed

Description

@github-actions

Objective

Eliminate 85% code duplication across 22 safe output files by extracting common job building patterns to reusable base types.

Context

Part of issue #4640 - Priority 2 (Medium Effort, High Value)

22 safe output files (create_*.go, close_*.go, add_*.go, update_*.go) follow nearly identical patterns for config parsing and job building, with ~2,500 lines of 85% similar code. This is the highest-value refactoring opportunity (could save 1,700 lines).

Approach

  1. Create pkg/workflow/safe_output_builder.go with base types:

    • SafeOutputConfigParser struct for generic config parsing
    • SafeOutputJobBuilder struct for generic job building
    • Common parsing utilities for shared fields (labels, target-repo, etc.)
    • Common env var building patterns
  2. Extract common patterns:

    • Config-to-env-var conversion logic (70-80% similar across all files)
    • Job condition building (85% identical)
    • Standard env var setup (100% identical)
    • Outputs map creation (100% identical)
  3. Refactor existing safe output files to use new base types:

    • Start with 3-4 files as proof of concept
    • Gradually migrate remaining files
    • Maintain config-specific customization through builder functions
  4. Focus areas with most duplication:

    • close_issue.go / close_discussion.go / close_pull_request.go (90% identical)
    • create_issue.go / create_discussion.go (85% similar)
    • add_comment.go / add_labels.go / add_reviewer.go (80% similar)

Files to Modify

  • Create: pkg/workflow/safe_output_builder.go (new base types)
  • Update: 22 files in pkg/workflow/ (create_, close_, add_, update_.go)

Acceptance Criteria

  • Base types created with common patterns extracted
  • At least 10 safe output files refactored to use base types
  • ~1,700 lines of duplicate code eliminated
  • Config-specific behavior preserved
  • All existing tests pass (make test)
  • Successful compilation (make build)
  • No behavioral changes in safe output processing
    Related to [refactor] 🔧 Semantic Function Clustering Analysis - November 2025 #4640

AI generated by Plan Command for #4640

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions