Skip to content

Refactor duplicated []string[]interface{} conversions into strutil.StringsToAny#7990

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-conversion-utility
Jun 23, 2026
Merged

Refactor duplicated []string[]interface{} conversions into strutil.StringsToAny#7990
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-conversion-utility

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This change removes three repeated inline conversion loops that transformed []string into []interface{} in guard/config paths. The conversion is now centralized to reduce boilerplate and keep future behavior changes in one place.

  • New shared utility

    • Added StringsToAny([]string) []interface{} in internal/strutil/strutil.go.
    • Purpose: canonical conversion helper for JSON/generic-interface call paths.
  • Guard payload cleanup

    • Replaced duplicate loops in BuildLabelAgentPayload (internal/guard/wasm_payload.go) for:
      • trusted-bots
      • trusted-users
    • Call sites now use strutil.StringsToAny(...).
  • Guard policy normalization cleanup

    • Replaced the inline []string scope conversion in internal/config/guard_policy_validation.go with strutil.StringsToAny(scope) before normalizeAndValidateScopeArray(...).
  • Focused coverage for helper

    • Added internal/strutil/strings_to_any_test.go covering:
      • nil input
      • empty input
      • ordered value conversion
// before
generic := make([]interface{}, len(scope))
for i := range scope {
    generic[i] = scope[i]
}
scopes, err := normalizeAndValidateScopeArray(generic)

// after
scopes, err := normalizeAndValidateScopeArray(strutil.StringsToAny(scope))

GitHub Advanced Security started work on behalf of lpcox June 23, 2026 18:36 View session
GitHub Advanced Security finished work on behalf of lpcox June 23, 2026 18:36
Copilot AI changed the title [WIP] Refactor duplicate []string to []interface{} conversion Refactor duplicated []string[]interface{} conversions into strutil.StringsToAny Jun 23, 2026
Copilot finished work on behalf of lpcox June 23, 2026 18:42
Copilot AI requested a review from lpcox June 23, 2026 18:42
GitHub Advanced Security started work on behalf of lpcox June 23, 2026 18:45 View session
GitHub Advanced Security finished work on behalf of lpcox June 23, 2026 18:45
@lpcox lpcox marked this pull request as ready for review June 23, 2026 21:46
Copilot AI review requested due to automatic review settings June 23, 2026 21:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces duplicated boilerplate by centralizing []string[]interface{} conversions into a shared internal/strutil.StringsToAny helper, then updating guard/config code paths to use it.

Changes:

  • Added strutil.StringsToAny([]string) []interface{} as the canonical conversion helper.
  • Replaced repeated inline conversion loops in guard label-agent payload building and guard policy normalization.
  • Added a focused unit test covering conversion behavior.
Show a summary per file
File Description
internal/strutil/strutil.go Adds the new shared StringsToAny conversion helper.
internal/strutil/strings_to_any_test.go Introduces unit tests for StringsToAny behavior.
internal/guard/wasm_payload.go Replaces inline []string[]interface{} loops for trusted-bots/users with StringsToAny.
internal/config/guard_policy_validation.go Uses StringsToAny when normalizing allow-only.repos provided as []string.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 4/4 changed files
  • Comments generated: 1

Comment thread internal/strutil/strings_to_any_test.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitHub Advanced Security started work on behalf of lpcox June 23, 2026 22:14 View session
GitHub Advanced Security finished work on behalf of lpcox June 23, 2026 22:15
@lpcox lpcox merged commit f3cd621 into main Jun 23, 2026
23 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-conversion-utility branch June 23, 2026 22:16
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.

3 participants