Skip to content

refactor(proxy/router): extract repoMethodArgs/repoMethodResourceArgs helpers to eliminate Actions route duplication#7211

Merged
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-actions-route-extractargs
Jun 8, 2026
Merged

refactor(proxy/router): extract repoMethodArgs/repoMethodResourceArgs helpers to eliminate Actions route duplication#7211
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-actions-route-extractargs

Conversation

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

The Actions routes block in internal/proxy/router.go contained ~14 near-identical extractArgs closures differing only in method and resource_id string values — ~80 lines of copy-paste that increases bug risk and maintenance cost.

Changes

  • New helpers alongside existing repoArgs:

    • repoMethodArgs(owner, repo, method) — for routes with no resource_id
    • repoMethodResourceArgs(owner, repo, method, resourceID) — for routes that capture a path segment as resource_id
  • Updated Actions routes (lines 200–306): replaced all inlined map[string]interface{} literals with calls to the appropriate helper. The two get_job_logs entries using run_id are unchanged as they don't fit the pattern.

// Before
extractArgs: func(m []string) map[string]interface{} {
    return map[string]interface{}{"owner": m[1], "repo": m[2], "method": "list_workflow_runs", "resource_id": m[3]}
},

// After
extractArgs: func(m []string) map[string]interface{} {
    return repoMethodResourceArgs(m[1], m[2], "list_workflow_runs", m[3])
},

Copilot AI changed the title [WIP] Refactor duplicate extractArgs closures in Actions route refactor(proxy/router): extract repoMethodArgs/repoMethodResourceArgs helpers to eliminate Actions route duplication Jun 8, 2026
Copilot AI requested a review from lpcox June 8, 2026 14:18
Copilot finished work on behalf of lpcox June 8, 2026 14:18
@lpcox lpcox marked this pull request as ready for review June 8, 2026 14:36
Copilot AI review requested due to automatic review settings June 8, 2026 14:36

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 refactors internal/proxy/router.go to reduce duplication in the GitHub Actions routes by extracting small helper functions that build the owner/repo/method (+ optional resource_id) argument maps used when routing REST paths to guard tool invocations.

Changes:

  • Added repoMethodArgs(owner, repo, method) helper for Actions routes that don’t require a resource_id.
  • Added repoMethodResourceArgs(owner, repo, method, resourceID) helper for Actions routes that capture a path segment into resource_id.
  • Updated the Actions routes to use these helpers instead of repeated inline map[string]interface{} literals.
Show a summary per file
File Description
internal/proxy/router.go Adds helper constructors for route argument maps and applies them to Actions routes to remove repeated inline literals.

Copilot's findings

Tip

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

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

@lpcox lpcox merged commit 38a0ad4 into main Jun 8, 2026
29 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-actions-route-extractargs branch June 8, 2026 15:52
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.

[duplicate-code] Duplicate Code Pattern: Actions Route extractArgs Lambda Duplication

3 participants