Refactor safe_outputs_config_generation.go into 6 focused modules using registry pattern#13510
Closed
Refactor safe_outputs_config_generation.go into 6 focused modules using registry pattern#13510
Conversation
This was referenced Feb 3, 2026
…ng registry pattern - Split 1023-line monolithic file into 6 focused modules: 1. safe_outputs_config_builder.go (256 lines) - Main orchestration 2. safe_outputs_tool_registry.go (406 lines) - Registry pattern handlers 3. safe_outputs_tool_definitions.go (206 lines) - MCP tool definitions 4. safe_outputs_tool_filter.go (89 lines) - Tool filtering 5. safe_outputs_repo_parameters.go (166 lines) - Repo parameter injection 6. safe_outputs_dispatch_workflows.go (58 lines) - Dispatch workflow handling - Replaced 84+ conditional checks with data-driven registry pattern - All existing tests pass - Code is well-organized with clear separation of concerns - Each file has focused responsibility and documentation Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
|
@copilot recompile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Splits 1023-line monolithic file into 6 focused modules, replacing 84+ conditional branches with a data-driven registry pattern.
Problem
safe_outputs_config_generation.gohad grown to 1023 lines with repetitive conditional logic:generateSafeOutputsConfig(): 387 lines checkingif data.SafeOutputs.X != nil84+ timesgenerateFilteredToolsJSON(): 242 lines with duplicate tool enablement checksChanges
Registry Pattern (new:
safe_outputs_tool_registry.go, 400 lines)SafeOutputToolHandlerinterface for tool config generationtoolRegistrygenerateSafeOutputsConfig()Focused Modules
safe_outputs_config_builder.go(256 lines): Main orchestration using registry, custom job/dispatch workflow helperssafe_outputs_tool_filter.go(89 lines): Tool filtering and description enhancementsafe_outputs_tool_definitions.go(206 lines): MCP tool schema generation for custom jobs and dispatch workflowssafe_outputs_repo_parameters.go(166 lines): Cross-repo parameter injection logicsafe_outputs_dispatch_workflows.go(58 lines): Workflow file discovery and mappingPublic API
Unchanged.
generateSafeOutputsConfig()andgenerateFilteredToolsJSON()maintain identical signatures and behavior.Impact
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/graphql/usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw GO111MODULE 64/bin/go base64 -d GOMODCACHE go /home/REDACTED/.cargo/bin/sh heck '**/*.cjs' infocmp GO111MODULE 64/bin/go sh(http block)/usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw GO111MODULE /opt/hostedtoolc-m infocmp ance�� REDACTED go 0/x64/bin/node -json GO111MODULE ndor/bin/git infocmp(http block)https://api.github.com/repos/actions/github-script/git/ref/tags/v8/usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha /x64=/_/GOROOT HEAD u/13/cc1 rfaces_test.go .go bin/git u/13/cc1 t(AR�� p/bin/git 64/src/runtime/cgo x_amd64/vet --abbrev-ref HEAD(http block)/usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha 64/src/runtime/cgo HEAD 64/pkg/tool/linux_amd64/vet home/REDACTED/.nvmbase64(http block)/usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha 64/src/runtime/cgo HEAD 64/bin/as #versions/iojs/#base64(http block)https://api.github.com/repos/github/gh-aw/git/ref/tags/v1.0.0/usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.0.0 --jq .object.sha -json GO111MODULE ndor/bin/git GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)/usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.0.0 --jq .object.sha /ref/tags/v8 go ache/node/24.13.0/x64/bin/git -json GO111MODULE 64/bin/go tail -n /ref/tags/v8 go /usr/bin/base64 -json GO111MODULE 64/bin/go base64(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[file-diet] Refactor safe_outputs_config_generation.go (1023 lines) into focused modules</issue_title>
<issue_description>### Overview
The file
pkg/workflow/safe_outputs_config_generation.gohas grown to 1023 lines, making it the largest source file in the codebase and difficult to maintain and test. This task involves refactoring it into smaller, focused files with improved test coverage.Current State
pkg/workflow/safe_outputs_config_generation.godata.SafeOutputs.*fieldsFull File Analysis
Detailed Breakdown
The file contains three distinct functional domains:
1. Main Configuration Generation (lines 58-445)
generateSafeOutputsConfig()- 387 lines2. Tool Definition Generation (lines 449-535)
generateCustomJobToolDefinition()- 87 lines3. Filtered Tools and Repo Parameter Handling (lines 539-926)
generateFilteredToolsJSON()- 242 linesaddRepoParameterIfNeeded()- 147 lines4. Dispatch Workflow Tool Generation (lines 930-1023)
generateDispatchWorkflowTool()- 94 linesHelper Functions Already Extracted:
safe_outputs_config_generation_helpers.go- ContainsgenerateMaxConfig,generatePullRequestConfig, etc.tool_description_enhancer.go- ContainsenhanceToolDescriptionComplexity Hotspots
generateSafeOutputsConfig()(lines 58-445):generateFilteredToolsJSON()(lines 539-777):addRepoParameterIfNeeded()(lines 781-926):Duplicate/Similar Patterns
Config generation pattern (repeated 30+ times):
Tool enablement pattern (repeated 30+ times):
Repo parameter check pattern (repeated 15+ times):
Refactoring Strategy
Proposed File Splits
Based on functional domains and responsibilities, split the file into the following modules:
1.
safe_outputs_config_builder.go(~200 lines)generateSafeOutputsConfig()- Refactored to use registry patternbuildConfigForTool()- Helper to build config for a single tool2.
safe_outputs_tool_registry.go(~150 lines)SafeOutputToolHandler- Interface for tool config generationtoolRegistry- Map of tool names to handlersregisterTools()- Initialize registry with all tool handlers