-
Notifications
You must be signed in to change notification settings - Fork 447
Refactor getOrCreateListRepoClone into focused helpers in parser remote file listing
#44179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pelikhan
merged 8 commits into
main
from
copilot/lint-monster-parser-function-length-cleanup
Jul 8, 2026
+233
−42
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a3f1e34
Initial plan
Copilot 8fb3f3f
Refactor parser clone helper to satisfy largefunc lint
Copilot 410fe4a
refactor: extend listRepoCloneConfig with owner/repo, simplify cloneA…
Copilot b5d8ef4
plan: address remaining mutex/I/O and defensive cache-check threads
Copilot 23c1c2e
fix: release mutex before os.Stat in getCachedListRepoClone; add defe…
Copilot 3f2dee4
fix: guard stale-entry eviction with path equality check; log RemoveA…
Copilot 6129ab3
plan: fix manualmutexunlock lint errors and revert .lock.yml changes
Copilot b143c2a
fix: extract readCloneFromCache/evictCloneFromCache to satisfy manual…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| //go:build !integration | ||
|
|
||
| package parser | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestResolveListRepoCloneConfig(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| owner string | ||
| repo string | ||
| ref string | ||
| host string | ||
| wantErr bool | ||
| checkFn func(t *testing.T, cfg listRepoCloneConfig) | ||
| }{ | ||
| { | ||
| name: "empty ref returns error", | ||
| owner: "o", | ||
| repo: "r", | ||
| ref: "", | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "whitespace-only ref returns error", | ||
| owner: "o", | ||
| repo: "r", | ||
| ref: " ", | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "host override used in repoURL and cacheKey", | ||
| owner: "o", | ||
| repo: "r", | ||
| ref: "main", | ||
| host: "ghes.example.com", | ||
| checkFn: func(t *testing.T, cfg listRepoCloneConfig) { | ||
| t.Helper() | ||
| if !strings.Contains(cfg.repoURL, "ghes.example.com") { | ||
| t.Errorf("expected ghes.example.com in repoURL, got %q", cfg.repoURL) | ||
| } | ||
| if !strings.Contains(cfg.cacheKey, "ghes.example.com") { | ||
| t.Errorf("expected ghes.example.com in cacheKey, got %q", cfg.cacheKey) | ||
| } | ||
| }, | ||
| }, | ||
| { | ||
| name: "cache key contains all identity fields", | ||
| owner: "myowner", | ||
| repo: "myrepo", | ||
| ref: "v1.2.3", | ||
| host: "ghes.example.com", | ||
| checkFn: func(t *testing.T, cfg listRepoCloneConfig) { | ||
| t.Helper() | ||
| for _, part := range []string{"myowner", "myrepo", "v1.2.3"} { | ||
| if !strings.Contains(cfg.cacheKey, part) { | ||
| t.Errorf("missing %q in cacheKey %q", part, cfg.cacheKey) | ||
| } | ||
| } | ||
| }, | ||
| }, | ||
| { | ||
| name: "owner and repo are set on config", | ||
| owner: "myowner", | ||
| repo: "myrepo", | ||
| ref: "main", | ||
| host: "ghes.example.com", | ||
| checkFn: func(t *testing.T, cfg listRepoCloneConfig) { | ||
| t.Helper() | ||
| if cfg.owner != "myowner" { | ||
| t.Errorf("owner = %q, want %q", cfg.owner, "myowner") | ||
| } | ||
| if cfg.repo != "myrepo" { | ||
| t.Errorf("repo = %q, want %q", cfg.repo, "myrepo") | ||
| } | ||
| }, | ||
| }, | ||
| { | ||
| name: "ref is trimmed of surrounding whitespace", | ||
| owner: "o", | ||
| repo: "r", | ||
| ref: " main ", | ||
| host: "ghes.example.com", | ||
| checkFn: func(t *testing.T, cfg listRepoCloneConfig) { | ||
| t.Helper() | ||
| if cfg.ref != "main" { | ||
| t.Errorf("ref = %q, want %q", cfg.ref, "main") | ||
| } | ||
| }, | ||
| }, | ||
| { | ||
| name: "public github org uses github.com host", | ||
| owner: "github", | ||
| repo: "myrepo", | ||
| ref: "main", | ||
| host: "", | ||
| checkFn: func(t *testing.T, cfg listRepoCloneConfig) { | ||
| t.Helper() | ||
| if !strings.Contains(cfg.repoURL, "github.com") { | ||
| t.Errorf("expected github.com in repoURL for public org, got %q", cfg.repoURL) | ||
| } | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| // Isolate environment so GetGitHubHostForRepo uses a predictable host. | ||
| t.Setenv("GITHUB_SERVER_URL", "") | ||
| t.Setenv("GITHUB_ENTERPRISE_HOST", "") | ||
| t.Setenv("GITHUB_HOST", "") | ||
| t.Setenv("GH_HOST", "") | ||
|
|
||
| cfg, err := resolveListRepoCloneConfig(tt.owner, tt.repo, tt.ref, tt.host) | ||
| if tt.wantErr { | ||
| if err == nil { | ||
| t.Fatalf("resolveListRepoCloneConfig() error = nil, want error") | ||
| } | ||
| return | ||
| } | ||
| if err != nil { | ||
| t.Fatalf("resolveListRepoCloneConfig() unexpected error: %v", err) | ||
| } | ||
| if tt.checkFn != nil { | ||
| tt.checkFn(t, cfg) | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.