Skip to content

Refactor: Split 1,368-line compiler_safe_outputs_consolidated.go into 6 domain-focused modules#7262

Merged
pelikhan merged 2 commits intomainfrom
copilot/refactor-large-go-file-again
Dec 22, 2025
Merged

Refactor: Split 1,368-line compiler_safe_outputs_consolidated.go into 6 domain-focused modules#7262
pelikhan merged 2 commits intomainfrom
copilot/refactor-large-go-file-again

Conversation

Copy link
Contributor

Copilot AI commented Dec 22, 2025

Problem

The compiler_safe_outputs_consolidated.go file grew to 1,368 lines (71% over the 800-line threshold) with 30 functions handling safe output operations for issues, PRs, discussions, and specialized operations. This made the code difficult to navigate and increased merge conflict risk.

Changes

Split the monolithic file into 6 modules organized by functional domain:

Core Orchestration

  • compiler_safe_outputs_core.go (674 lines)
    • Main job orchestrator buildConsolidatedSafeOutputsJob
    • Step builder buildConsolidatedSafeOutputStep
    • Shared helpers for environment variables and conditions

Entity-Specific Operations

  • compiler_safe_outputs_issues.go (94 lines)

    • Create, update, close, link sub-issues
  • compiler_safe_outputs_discussions.go (79 lines)

    • Create, update, close discussions
  • compiler_safe_outputs_prs.go (304 lines)

    • PR lifecycle operations (create, update, close, review comments)
    • Git pre-steps for checkout and branch operations

Cross-Entity Operations

  • compiler_safe_outputs_shared.go (115 lines)

    • Operations spanning multiple entity types: comments, labels, hide, assets
  • compiler_safe_outputs_specialized.go (145 lines)

    • Code scanning, milestones, agent tasks, releases, projects

Result

  • Largest file reduced from 1,368 to 674 lines (50% reduction)
  • Average module size: ~235 lines
  • All files under 800-line threshold
  • Follows existing engine separation pattern (copilot_engine.go, claude_engine.go, etc.)
Original prompt

This section details on the original issue you should resolve

<issue_title>[file-diet] Refactor Large Go File: pkg/workflow/compiler_safe_outputs_consolidated.go</issue_title>
<issue_description>## Overview

The file pkg/workflow/compiler_safe_outputs_consolidated.go has grown to 1,368 lines, making it difficult to maintain and test effectively. This file orchestrates the consolidated safe outputs job compilation and contains 30 functions, primarily consisting of step configuration builders for different safe output operations (issues, PRs, discussions, etc.).

Current State

  • File: pkg/workflow/compiler_safe_outputs_consolidated.go
  • Size: 1,368 lines (71% over the 800-line healthy threshold)
  • Functions: 30 total functions
  • Test Coverage: No dedicated test file (compiler_safe_outputs_consolidated_test.go does not exist)
  • Related Tests: 18 test files cover various safe outputs aspects (total: ~5,500 LOC)
  • Complexity: High - manages 20+ different safe output types with similar patterns

Architecture Analysis

The file follows a clear but repetitive pattern:

  1. Lines 1-100: Package setup, SafeOutputStepConfig struct definition
  2. Lines 38-537: buildConsolidatedSafeOutputsJob - main orchestrator (499 lines)
  3. Lines 537-669: Core helper functions (132 lines)
  4. Lines 679-1,368: 25 individual step config builders (689 lines)

Current Groupings Identified

GitHub Issues Operations (5 functions):

  • buildCreateIssueStepConfig
  • buildUpdateIssueStepConfig
  • buildCloseIssueStepConfig
  • buildLinkSubIssueStepConfig
  • Related helper functions

Pull Request Operations (6 functions):

  • buildCreatePullRequestStepConfig
  • buildUpdatePullRequestStepConfig
  • buildClosePullRequestStepConfig
  • buildCreatePRReviewCommentStepConfig
  • buildPushToPullRequestBranchStepConfig
  • buildAddReviewerStepConfig

Discussion Operations (3 functions):

  • buildCreateDiscussionStepConfig
  • buildUpdateDiscussionStepConfig
  • buildCloseDiscussionStepConfig

Shared Operations (4 functions):

  • buildAddCommentStepConfig (works with issues, PRs, discussions)
  • buildAddLabelsStepConfig
  • buildHideCommentStepConfig
  • buildUploadAssetsStepConfig

Specialized Operations (7 functions):

  • buildCreateCodeScanningAlertStepConfig
  • buildAssignMilestoneStepConfig
  • buildAssignToAgentStepConfig
  • buildAssignToUserStepConfig
  • buildUpdateReleaseStepConfig
  • buildCreateAgentTaskStepConfig
  • buildUpdateProjectStepConfig

Refactoring Strategy

Proposed File Splits

Split the monolithic file into 6 focused modules based on functional domains:

1. compiler_safe_outputs_core.go (~200 lines)

Responsibility: Core orchestration and shared utilities

Contents:

  • SafeOutputStepConfig struct definition
  • buildConsolidatedSafeOutputsJob main orchestrator
  • buildConsolidatedSafeOutputStep helper
  • buildJobLevelSafeOutputEnvVars helper
  • buildDetectionSuccessCondition helper

Rationale: Central coordination logic used by all step builders


2. compiler_safe_outputs_issues.go (~200 lines)

Responsibility: Issue-related safe output operations

Contents:

  • buildCreateIssueStepConfig
  • buildUpdateIssueStepConfig
  • buildCloseIssueStepConfig
  • buildLinkSubIssueStepConfig
  • Any issue-specific pre-step builders

Estimated LOC: ~200 lines


3. compiler_safe_outputs_prs.go (~300 lines)

Responsibility: Pull request operations

Contents:

  • buildCreatePullRequestStepConfig
  • buildUpdatePullRequestStepConfig
  • buildClosePullRequestStepConfig
  • buildCreatePRReviewCommentStepConfig
  • buildPushToPullRequestBranchStepConfig
  • buildAddReviewerStepConfig
  • buildCreatePullRequestPreStepsConsolidated
  • buildPushToPullRequestBranchPreStepsConsolidated

Estimated LOC: ~300 lines (includes pre-steps logic)


4. compiler_safe_outputs_discussions.go (~150 lines)

Responsibility: Discussion operations

Contents:

  • buildCreateDiscussionStepConfig
  • buildUpdateDiscussionStepConfig
  • buildCloseDiscussionStepConfig

Estimated LOC: ~150 lines


5. compiler_safe_outputs_shared.go (~200 lines)

Responsibility: Operations that work across multiple entity types

Contents:

  • buildAddCommentStepConfig (issues, PRs, discussions)
  • buildAddLabelsStepConfig
  • buildHideCommentStepConfig
  • buildUploadAssetsStepConfig

Estimated LOC: ~200 lines


6. compiler_safe_outputs_specialized.go (~318 lines)

Responsibility: Specialized/less common operations

Contents:

  • buildCreateCodeScanningAlertStepConfig
  • buildAssignMilestoneStepConfig
  • buildAssignToAgentStepConfig
  • buildAssignToUserStepConfig
  • buildUpdateReleaseStepConfig
  • buildCreateAgentTaskStepConfig
  • buildUpdateProjectStepConfig

Estimated LOC: ~318 lines


Benefits of This Split

✅ **Im...


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…modules

Split the 1,368-line compiler_safe_outputs_consolidated.go file into 6 focused modules:

- compiler_safe_outputs_core.go (674 lines): Main orchestrator, step builder, and helper functions
- compiler_safe_outputs_issues.go (94 lines): Issue operations (create, update, close, link sub-issue)
- compiler_safe_outputs_discussions.go (79 lines): Discussion operations (create, update, close)
- compiler_safe_outputs_prs.go (304 lines): Pull request operations with pre-steps
- compiler_safe_outputs_shared.go (115 lines): Shared operations (comments, labels, hide, upload)
- compiler_safe_outputs_specialized.go (145 lines): Specialized operations (code scanning, milestones, agents, releases, projects)

Benefits:
- Improved code organization and navigation
- Easier parallel development
- Better separation of concerns
- All files now under 700 lines (well below 800-line threshold)
- All tests pass
- All linting passes
- No breaking changes

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor large Go file for better maintainability Refactor: Split 1,368-line compiler_safe_outputs_consolidated.go into 6 domain-focused modules Dec 22, 2025
Copilot AI requested a review from mnkiefer December 22, 2025 15:13
@pelikhan pelikhan marked this pull request as ready for review December 22, 2025 15:26
@pelikhan pelikhan added the smoke label Dec 22, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

🎉 Yo ho ho! Changeset Generator found the treasure and completed successfully! ⚓💰

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

🎉 Yo ho ho! Smoke Copilot Safe Inputs found the treasure and completed successfully! ⚓💰

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

🤖 DIAGNOSTIC COMPLETE: Smoke Copilot No Firewall STATUS: ALL_UNITS_OPERATIONAL. MISSION_SUCCESS.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

✅ Firewall validation complete... Smoke Codex Firewall confirmed network sandboxing is operational. 🛡️

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions
Copy link
Contributor

Smoke Test Results

Last 2 Merged PRs:

Test Results:

  • ✅ GitHub MCP Testing (list_pull_requests)
  • ✅ File Writing Testing
  • ✅ Bash Tool Testing
  • ✅ GitHub MCP Default Toolset (get_me correctly unavailable)
  • ✅ Cache Memory Testing

Overall Status: PASS

@pelikhan @mnkiefer

📰 BREAKING: Report filed by Smoke Copilot fer issue #7262 🗺️

@github-actions
Copy link
Contributor

PRs: #7260 Prefer precise version numbers in action pin algorithm; #7263 Increase skip-if-match limit to 9 in issue-monster workflow
OpenAI curl blocked: ✅
MCP merged PR fetch: ✅
Test file write/read: ✅
Blocked domain curl: ✅
Network: SANDBOXED | Overall: PASS

🔥 Firewall tested by Smoke Codex Firewall fer issue #7262 🗺️

@github-actions
Copy link
Contributor

Smoke Test Results

File Writing: Created /tmp/gh-aw/agent/smoke-test-copilot-20436291997.txt
Bash Tool: Verified file content successfully
Safe Input gh Tool: Merged PRs retrieved (test passed)

Overall Status: ✅ PASS

Ahoy! This treasure was crafted by 🏴‍☠️ Smoke Copilot Safe Inputs fer issue #7262 🗺️

@github-actions
Copy link
Contributor

Claude Smoke Test Results

Last 2 Merged PRs:

Test Results:

  • ✅ GitHub MCP (fetched PRs with pagination)
  • ✅ File Writing (created test file)
  • ✅ Bash Tool (verified file contents)
  • ✅ Playwright MCP (navigated to GitHub, title contains "GitHub")
  • ✅ Cache Memory (created and verified test file)
  • ❌ Safe Input gh Tool (tool not available)

Overall Status: FAIL (5/6 tests passed)

💥 [THE END] — Illustrated by Smoke Claude fer issue #7262 🗺️

@pelikhan pelikhan merged commit 2f0107f into main Dec 22, 2025
170 checks passed
@pelikhan pelikhan deleted the copilot/refactor-large-go-file-again branch December 22, 2025 15:30
@github-actions
Copy link
Contributor

  • PRs: Prefer precise version numbers in action pin algorithm; Increase skip-if-match limit to 9 in issue-monster workflow
  • GitHub MCP PR fetch: ✅
  • Agent file + cat: ✅
  • Cache memory file: ✅
  • Playwright title check: ✅
  • safeinputs-gh gh issues list: ❌ (tool unavailable)
  • Overall: FAIL

🔮 The oracle has spoken through Smoke Codex fer issue #7262 🗺️

@github-actions
Copy link
Contributor

Copilot Smoke Test Results (No Firewall)

Last 2 Merged PRs:

Test Results:

  • ✅ GitHub MCP: Retrieved PR data
  • ✅ File Writing: Created test file successfully
  • ✅ Bash Tool: Verified file contents
  • ✅ Playwright MCP: Page title contains "GitHub"
  • ⏳ Safe Input gh Tool: Testing in progress

Overall Status: PASS

🤖 DIAGNOSTIC REPORT GENERATED BY Smoke Copilot No Firewall fer issue #7262 🗺️

Copilot AI added a commit that referenced this pull request Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[file-diet] Refactor Large Go File: pkg/workflow/compiler_safe_outputs_consolidated.go

3 participants