Consolidate duplicate secret extraction logic into shared utilities#3752
Merged
Consolidate duplicate secret extraction logic into shared utilities#3752
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Consolidate secret extraction logic into shared utilities
Consolidate duplicate secret extraction logic into shared utilities
Nov 12, 2025
pelikhan
approved these changes
Nov 12, 2025
| @@ -5,20 +5,15 @@ import ( | |||
| "fmt" | |||
… directly Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR successfully consolidates duplicate secret extraction logic from multiple files into a shared utility module, reducing code duplication and improving maintainability. The refactoring moves secret pattern matching and extraction functions into pkg/workflow/secret_extraction.go and updates all call sites to use the new shared utilities.
Key changes:
- Created centralized secret extraction utilities with comprehensive test coverage
- Eliminated ~75 lines of duplicate code from
mcp-config.go - Removed thin wrapper function from
secrets.goin favor of direct use of shared utilities
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/secret_extraction.go |
New shared utilities for secret extraction with exported functions for extracting secret names and expressions from strings and maps |
pkg/workflow/secret_extraction_test.go |
Comprehensive test suite with 31 test cases covering all shared utilities including edge cases |
pkg/workflow/mcp-config.go |
Refactored to use shared ExtractSecretsFromMap() and ReplaceSecretsWithEnvVars() utilities, removing 3 duplicate private functions |
pkg/workflow/mcp_http_headers_test.go |
Updated test calls to use new exported function names (ExtractSecretsFromValue, ExtractSecretsFromMap, ReplaceSecretsWithEnvVars) |
pkg/cli/secrets.go |
Removed duplicate extractSecretName() wrapper function and unused regex pattern; now directly uses workflow.ExtractSecretName() |
pkg/cli/secrets_test.go |
Updated to import and use workflow.ExtractSecretName() instead of the removed local wrapper |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+12
to
+16
| // SecretExpression represents a parsed secret expression | ||
| type SecretExpression struct { | ||
| VarName string // The secret variable name (e.g., "DD_API_KEY") | ||
| FullExpr string // The full expression (e.g., "${{ secrets.DD_API_KEY }}") | ||
| } |
There was a problem hiding this comment.
The SecretExpression struct is defined but never used anywhere in the codebase. This is dead code that should be removed.
Suggested change
| // SecretExpression represents a parsed secret expression | |
| type SecretExpression struct { | |
| VarName string // The secret variable name (e.g., "DD_API_KEY") | |
| FullExpr string // The full expression (e.g., "${{ secrets.DD_API_KEY }}") | |
| } |
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.
✅ Consolidate Secret Extraction Logic - COMPLETE
Summary
Successfully eliminated ~60% code duplication in secret extraction logic by consolidating similar functions from
mcp-config.goandsecrets.gointo shared utilities.Changes Made
1. Created Shared Utilities ✓
pkg/workflow/secret_extraction.go(115 lines)secretExprPattern- Common pre-compiled regex for secret matchingExtractSecretName()- Extract just the secret name from expressionExtractSecretsFromValue()- Extract all secrets from a single stringExtractSecretsFromMap()- Extract all secrets from a map of stringsReplaceSecretsWithEnvVars()- Replace secret expressions with env var references2. Comprehensive Test Coverage ✓
pkg/workflow/secret_extraction_test.go(340 lines)3. Refactored Existing Code ✓
pkg/workflow/mcp-config.go:ExtractSecretsFromMap()ReplaceSecretsWithEnvVars()pkg/cli/secrets.go:extractSecretName()functionworkflow.ExtractSecretName()in all call sites4. Validation ✓
Benefits
Code Metrics
Files Changed
pkg/workflow/secret_extraction.go(new)pkg/workflow/secret_extraction_test.go(new)pkg/workflow/mcp-config.go(refactored)pkg/workflow/mcp_http_headers_test.go(updated)pkg/cli/secrets.go(refactored - removed thin wrapper)pkg/cli/secrets_test.go(updated to use workflow.ExtractSecretName)Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.