-
Notifications
You must be signed in to change notification settings - Fork 499
Consolidate repository and semantic-version utilities #54148
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,30 @@ import ( | |
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestBuildConcurrentDownloadParams_RepoOverride(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| repoOverride string | ||
| wantHost string | ||
| wantOwner string | ||
| wantRepo string | ||
| }{ | ||
| {name: "owner and repo", repoOverride: "owner/repo", wantOwner: "owner", wantRepo: "repo"}, | ||
| {name: "host owner and repo", repoOverride: "ghe.example/owner/repo", wantHost: "ghe.example", wantOwner: "owner", wantRepo: "repo"}, | ||
| {name: "empty component", repoOverride: "owner/"}, | ||
| {name: "empty host-qualified component", repoOverride: "ghe.example/owner/"}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| params := buildConcurrentDownloadParams("", false, tt.repoOverride, nil, false, nil) | ||
| assert.Equal(t, tt.wantHost, params.dlHost) | ||
| assert.Equal(t, tt.wantOwner, params.dlOwner) | ||
| assert.Equal(t, tt.wantRepo, params.dlRepo) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestRunHasEvals(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] The 💡 Suggested test case{name: "empty override", repoOverride: "", wantHost: "", wantOwner: "", wantRepo: ""},@copilot please address this. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import ( | |
| "github.com/github/gh-aw/pkg/errorutil" | ||
| "github.com/github/gh-aw/pkg/gitutil" | ||
| "github.com/github/gh-aw/pkg/logger" | ||
| "github.com/github/gh-aw/pkg/repoutil" | ||
| "github.com/github/gh-aw/pkg/workflow" | ||
| ) | ||
|
|
||
|
|
@@ -352,10 +353,8 @@ func validateSetupRepositoryCheckOptions(opts SetupRepositoryCheckOptions) error | |
| } | ||
|
|
||
| func isValidOwnerRepoSlug(repo string) bool { | ||
| parts := strings.Split(repo, "/") | ||
| return len(parts) == 2 && | ||
| strings.TrimSpace(parts[0]) != "" && | ||
| strings.TrimSpace(parts[1]) != "" | ||
| owner, name, err := repoutil.SplitRepoSlug(repo) | ||
| return err == nil && strings.TrimSpace(owner) != "" && strings.TrimSpace(name) != "" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/codebase-design] 💡 SuggestionEither push whitespace trimming into func isValidOwnerRepoSlug(repo string) bool {
// SplitRepoSlug does not trim whitespace; trim here to reject slugs like " /repo".
owner, name, err := repoutil.SplitRepoSlug(repo)
return err == nil && strings.TrimSpace(owner) != "" && strings.TrimSpace(name) != ""
}A test case @copilot please address this. |
||
| } | ||
|
|
||
| func runSetupRepositoryCheckWithRuntime(opts SetupRepositoryCheckOptions, runtime setupRepositoryRuntime) error { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change silently accepts malformed
--repooverrides and proceeds with empty download coordinates, so the command can fall back to the current repository or fail much later with a misleading error instead of rejecting bad input at the boundary.💡 Why this needs to fail fast
Before this refactor,
owner/still produceddlOwner="owner", which was dubious but at least preserved the user's input shape. The new code is worse:NormalizeRepoForAPI("owner/")returnsowner/,SplitRepoSlugrejects it, and the error is discarded. That leavesdlHost,dlOwner, anddlRepoempty, so downstream code can behave as if no override was provided.That is a correctness regression because an explicitly invalid override should not be treated like "use the default repo". It hides user mistakes and makes debugging much harder.
A minimal fix is to validate once and return an error when
repoOverrideis malformed, e.g.:If changing the helper signature is too invasive, add a dedicated validator before calling this helper and cover the invalid-input path with a failing test rather than asserting empty fields.