Refactor: Eliminate duplicate safe output env logic in workflow helpers#2023
Merged
Refactor: Eliminate duplicate safe output env logic in workflow helpers#2023
Conversation
…mment and create_discussion Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor duplicate safe output env logic in workflow helpers
Refactor: Eliminate duplicate safe output env logic in workflow helpers
Oct 20, 2025
pelikhan
approved these changes
Oct 20, 2025
Contributor
|
Agentic Changeset Generator triggered by this pull request. |
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.
Problem
Safe output environment configuration logic was duplicated across multiple workflow helper files, making maintenance difficult and error-prone. When adding new environment variables, developers had to update the logic in multiple places, increasing the risk of inconsistent behavior.
The duplicate code pattern appeared in:
create_pr_review_comment.go(lines 40-48)create_discussion.go(lines 73-82)Each file independently implemented the same logic for handling
GITHUB_AW_SAFE_OUTPUTS_STAGEDandGITHUB_AW_TARGET_REPO_SLUGenvironment variables:Solution
Consolidated the duplicate logic by utilizing the existing
buildSafeOutputJobEnvVarshelper function that was already available insafe_output_helpers.go. This helper was previously used byadd_comment.gobut not by the other safe output job builders.The refactored code now uses a single, consistent approach:
Benefits
Single Source of Truth: All safe output job builders now use the same helper function:
add_comment.go(already using helper)create_pr_review_comment.go(now using helper)create_discussion.go(now using helper)Improved Maintainability: Future environment variable additions only require changes in one location (
buildSafeOutputJobEnvVars), not across multiple files.Consistent Behavior: Eliminates the risk of divergent implementations causing subtle bugs across different safe output types.
Code Reduction: Eliminated 18 lines of duplicate code while maintaining identical functionality.
Testing
Added comprehensive test suite (
safe_output_refactor_test.go) with 5 test cases:All existing tests continue to pass, confirming no breaking changes.
Related Issue
Addresses Pattern 2 from issue #[duplicate-code]: "Staged/target repo env logic reimplemented instead of using helper"
Original prompt
Fixes #2022
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.