Skip to content

[task] Consolidate secret extraction logic into shared utilities #3746

@github-actions

Description

@github-actions

Objective

Eliminate ~60% code duplication in secret extraction logic by consolidating similar functions from mcp-config.go and secrets.go into shared utilities.

Context

Currently secret extraction logic is duplicated across multiple files with ~60% similarity. Functions like extractSecretsFromValue, extractSecretsFromHeaders (mcp-config.go) and extractSecretsFromConfig (secrets.go) all perform similar pattern matching for ${{ secrets.NAME }} with slight variations.

Related to #3713 - Duplicate #2: Secret Extraction Functions.

Approach

  1. Create new file pkg/workflow/secret_extraction.go with shared utilities:

    • Common secret pattern regex
    • Generic secret extraction from strings
    • Generic secret extraction from maps
    • Helper functions for parsing secret expressions with defaults
  2. Refactor existing functions to use shared utilities:

    • Update extractSecretsFromValue in mcp-config.go
    • Update extractSecretsFromHeaders in mcp-config.go
    • Update extractSecretsFromConfig in cli/secrets.go
  3. Add comprehensive tests for the new utilities

  4. Verify all existing tests continue to pass

Files to Create

  • pkg/workflow/secret_extraction.go - Shared secret extraction utilities
  • pkg/workflow/secret_extraction_test.go - Tests for new utilities

Files to Modify

  • pkg/workflow/mcp-config.go - Refactor to use shared utilities
  • pkg/cli/secrets.go - Refactor to use shared utilities
  • Existing test files that test secret extraction

Acceptance Criteria

  • New secret_extraction.go file created with shared utilities
  • Common secret pattern regex defined once (DRY principle)
  • All existing secret extraction functions refactored to use utilities
  • Code duplication reduced significantly
  • All existing tests pass without modification
  • New tests added for shared utilities
  • Secret extraction behavior identical to original
  • Handles edge cases: defaults (secrets.X || 'default'), malformed expressions
  • Single source of truth for secret pattern matching
    Related to [refactor] 🔧 Semantic Function Clustering Analysis: Refactoring Opportunities #3713

AI generated by Plan Command for #3713

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions