refactor: Semantic function clustering — split strutil.go, extract githubhttp package, fix validation.go placement, rename logger/common.go by Copilot · Pull Request #8244 · github/gh-aw-mcpg · GitHub
Skip to content

refactor: Semantic function clustering — split strutil.go, extract githubhttp package, fix validation.go placement, rename logger/common.go#8244

Merged
lpcox merged 2 commits into
mainfrom
copilot/refactor-semantic-function-clustering
Jun 28, 2026
Merged

refactor: Semantic function clustering — split strutil.go, extract githubhttp package, fix validation.go placement, rename logger/common.go#8244
lpcox merged 2 commits into
mainfrom
copilot/refactor-semantic-function-clustering

Conversation

Copilot AI commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Four file-organization issues identified by semantic function clustering analysis where source files contradicted naming conventions or mixed concerns.

1. strutil/strutil.go → dedicated files

Split the catch-all into files that match the existing *_test.go conventions:

New file Functions
deepclone.go DeepCloneJSON
util.go SortedSetKeys, GetStringFromMap
deduplicate.go DeduplicateStrings
strings_to_any.go StringsToAny
copy_trimmed_string_int_map.go CopyTrimmedStringIntMap

strutil.go removed (no remaining content).

2. httputilinternal/githubhttp/ (new package)

GitHub API–specific code was co-located with generic HTTP utilities. Extracted into a dedicated package:

internal/githubhttp/
    client.go       ← ApplyGitHubAPIHeaders, DoGitHubGET,
                       ParseRateLimitResetHeader, ComputeRetryAfter
    collaborator.go ← ParseCollaboratorPermissionArgs,
                       FetchCollaboratorPermission, LogAndWrapCollaboratorPermission

Updated callers: server/unified.go, proxy/proxy.go, proxy/handler.go, proxy/rate_limit_test.go. Tests moved to githubhttp/.

3. config/validation_rules.govalidation.go

validateRuleBasedPatterns is a composite orchestrator (iterates all servers, calls validateGatewayConfig), not an atomic rule. Moved to validation.go where all other orchestrators live.

4. logger/common.gologger/global_state.go

common is a Go anti-pattern filename. The file manages global logger state with mutex locking — global_state.go communicates this. Test file renamed to match.

GitHub Advanced Security started work on behalf of lpcox June 28, 2026 18:50 View session
GitHub Advanced Security finished work on behalf of lpcox June 28, 2026 18:50
…provements

Addresses issue #8207 with four refactoring improvements:

1. strutil: Split catch-all strutil.go into focused files matching test files
   - deepclone.go: DeepCloneJSON (with improved docs)
   - util.go: SortedSetKeys, GetStringFromMap
   - deduplicate.go: DeduplicateStrings
   - strings_to_any.go: StringsToAny
   - copy_trimmed_string_int_map.go: CopyTrimmedStringIntMap
   - Remove empty strutil.go

2. httputil -> githubhttp: Extract GitHub API-specific code into dedicated package
   - githubhttp/client.go: ApplyGitHubAPIHeaders, DoGitHubGET,
     ParseRateLimitResetHeader, ComputeRetryAfter
   - githubhttp/collaborator.go: ParseCollaboratorPermissionArgs,
     LogAndWrapCollaboratorPermission, FetchCollaboratorPermission
   - Update server/unified.go, proxy/proxy.go, proxy/handler.go callers
   - Move tests to githubhttp package

3. config: Move validateRuleBasedPatterns from validation_rules.go
   (atomic rules) to validation.go (composite orchestrators)

4. logger: Rename common.go -> global_state.go to better communicate purpose
Copilot AI changed the title [WIP] Refactor semantic function clustering for organization improvements refactor: Semantic function clustering — split strutil.go, extract githubhttp package, fix validation.go placement, rename logger/common.go Jun 28, 2026
GitHub Advanced Security started work on behalf of lpcox June 28, 2026 19:09 View session
Copilot finished work on behalf of lpcox June 28, 2026 19:09
Copilot AI requested a review from lpcox June 28, 2026 19:09
GitHub Advanced Security finished work on behalf of lpcox June 28, 2026 19:10
@lpcox lpcox marked this pull request as ready for review June 28, 2026 19:21
Copilot AI review requested due to automatic review settings June 28, 2026 19:21

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

Refactors internal packages and file layout to better align source files with their responsibilities (string utilities, GitHub-HTTP helpers, config validation orchestration, and logger global state), improving navigability and reducing mixed concerns.

Changes:

  • Split internal/strutil/strutil.go into focused files (util.go, deduplicate.go, deepclone.go, etc.) and removed the catch-all file.
  • Extract GitHub API–specific HTTP helpers into a new internal/githubhttp package and update server/proxy callers + tests accordingly.
  • Move validateRuleBasedPatterns into internal/config/validation.go and rename logger “common” file to global_state.go with matching test rename.
Show a summary per file
File Description
internal/strutil/util.go Hosts general small utilities (SortedSetKeys, GetStringFromMap) after the split.
internal/strutil/strings_to_any.go Isolates StringsToAny into its own file.
internal/strutil/deepclone.go Isolates DeepCloneJSON into its own file.
internal/strutil/deduplicate.go Isolates DeduplicateStrings into its own file.
internal/strutil/copy_trimmed_string_int_map.go Isolates CopyTrimmedStringIntMap into its own file.
internal/strutil/strutil.go Removes the previous “catch-all” strutil file.
internal/githubhttp/client.go New GitHub API HTTP helper package (headers, GET, rate-limit parsing, retry calculation).
internal/githubhttp/client_test.go Moves GitHub HTTP helper tests into the new package.
internal/githubhttp/collaborator.go Moves collaborator-permission helpers into githubhttp and updates logger namespace.
internal/githubhttp/collaborator_test.go Moves collaborator-permission tests into the new package.
internal/server/unified.go Updates unified server code to call githubhttp helpers instead of httputil.
internal/server/rate_limit.go Updates internal reference comment to point at githubhttp helpers.
internal/proxy/proxy.go Switches GitHub header/collaborator helper calls to githubhttp.
internal/proxy/handler.go Switches rate-limit header parsing / retry calculation to githubhttp.
internal/proxy/rate_limit_test.go Updates tests to use githubhttp.ComputeRetryAfter.
internal/httputil/httputil_test.go Removes GitHub-specific helper tests from the generic httputil package.
internal/config/validation.go Relocates validateRuleBasedPatterns into the validation orchestrator file.
internal/config/validation_rules.go Removes validateRuleBasedPatterns from rule definitions file.
internal/logger/global_state.go Renames and consolidates global logger state + helper utilities into a clearer filename.
internal/logger/global_state_test.go Adds/renames tests covering global-state helpers and init/close behavior.
AGENTS.md Updates documentation to reflect the new internal/githubhttp package and clarifies httputil as generic.

Review details

Tip

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

Comments suppressed due to low confidence (1)

internal/githubhttp/client.go:28

  • The ApplyGitHubAPIHeaders doc comment uses "******" as an Authorization header example, which is misleading and obscures the expected scheme (token vs Bearer). Use a placeholder that preserves the header format (e.g., "Bearer ").
  • Files reviewed: 19/21 changed files
  • Comments generated: 0
  • Review effort level: Low

@lpcox lpcox merged commit 7f12e5b into main Jun 28, 2026
34 checks passed
@lpcox lpcox deleted the copilot/refactor-semantic-function-clustering branch June 28, 2026 19:54
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