Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

Action pin resolution code had 11 instances of multi-part string concatenation creating unnecessary intermediate allocations. Centralized formatting into two helpers.

Changes

  • Added formatting helpers in pkg/workflow/action_pins.go:

    • formatActionReference(repo, sha, version)"repo@sha # version"
    • formatActionCacheKey(repo, version)"repo@version"
  • Replaced concatenation across:

    • 7 instances in action_pins.go (all action reference returns)
    • 4 instances in action_cache.go (Get/Set cache key generation)

Example

Before:

return actionRepo + "@" + latestPin.SHA + " # " + latestPin.Version
cacheKey := actionRepo + "@" + version

After:

return formatActionReference(actionRepo, latestPin.SHA, latestPin.Version)
cacheKey := formatActionCacheKey(actionRepo, version)

Tests added for both helpers covering standard cases, nested paths, and edge cases.

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Extract action pin formatting helpers to reduce string concatenation</issue_title>
<issue_description>## Objective

Replace 10+ instances of multi-part string concatenation in action pin formatting with helper functions for better performance and consistency.

Context

From discussion githubnext/gh-aw#12006: Sergo analysis found repeated string concatenation patterns in action resolution code. While the codebase uses strings.Builder well (187 instances), this specific hotspot creates unnecessary intermediate allocations.

Files to Modify

  • pkg/workflow/action_pins.go - 8 instances (lines 137, 159, 197, 206, 211, 246, 260, 278)
  • pkg/workflow/action_cache.go - 2 instances (lines 169, 194)

Current Pattern

// Repeated 10+ times:
return actionRepo + "@" + latestPin.SHA + " # " + latestPin.Version

// In cache code:
cacheKey := repo + "@" + version

Proposed Solution

Add helper functions to centralize formatting logic:

// formatActionReference formats an action reference with repo, SHA, and version.
// Example: "actions/checkout@abc123 # v4.1.0"
func formatActionReference(repo, sha, version string) string {
    return fmt.Sprintf("%s@%s # %s", repo, sha, version)
}

// formatActionCacheKey generates a cache key for action resolution.
// Example: "actions/checkout@v4"
func formatActionCacheKey(repo, version string) string {
    return fmt.Sprintf("%s@%s", repo, version)
}

Alternative (if benchmarking shows need)

For maximum performance, use strings.Builder with pre-allocation:

func formatActionReference(repo, sha, version string) string {
    var b strings.Builder
    b.Grow(len(repo) + len(sha) + len(version) + 5)
    b.WriteString(repo)
    b.WriteString("@")
    b.WriteString(sha)
    b.WriteString(" # ")
    b.WriteString(version)
    return b.String()
}

Acceptance Criteria

  • All 10+ instances replaced with helper function calls
  • Helper functions defined in appropriate file (suggest action_pins.go)
  • All existing tests pass with identical output
  • Action pin format remains valid
  • Cache key consistency maintained
  • Optional: Benchmark shows performance improvement or no regression

AI generated by Plan Command for discussion #12006

Comments on the Issue (you are @copilot in this section)


💡 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.

- Add formatActionReference() helper for "repo@sha # version" format
- Add formatActionCacheKey() helper for "repo@version" format
- Replace 6 instances in action_pins.go (lines 137, 159, 197, 206, 211, 260, 278)
- Replace 2 instances in action_cache.go (lines 169, 194)
- Add comprehensive tests for both helper functions
- All existing tests pass with identical output

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Extract action pin formatting helpers for consistency Extract action pin formatting helpers to reduce string concatenation Jan 28, 2026
Copilot AI requested a review from pelikhan January 28, 2026 08:09
@pelikhan pelikhan marked this pull request as ready for review January 28, 2026 13:51
@pelikhan pelikhan merged commit 9819f93 into main Jan 28, 2026
@pelikhan pelikhan deleted the copilot/extract-action-pin-helpers branch January 28, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[plan] Extract action pin formatting helpers to reduce string concatenation

2 participants