-
Notifications
You must be signed in to change notification settings - Fork 472
fix: honor GH_HOST for --trigger-context issue URLs in gh aw trial
#43729
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
7d234d8
2c0b22f
d4b13ee
5ace27d
08bc2ce
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 |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ import ( | |
| ) | ||
|
|
||
| func TestExtractIssueNumberFromURL(t *testing.T) { | ||
| // All of these cases run with the default host (no GH_HOST set), so | ||
| // getGitHubHost() returns https://github.com. | ||
| testCases := []struct { | ||
| name string | ||
| url string | ||
|
|
@@ -64,6 +66,67 @@ func TestExtractIssueNumberFromURL(t *testing.T) { | |
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| // Ensure no GH_HOST is set so getGitHubHost() returns the public github.com default. | ||
| t.Setenv("GITHUB_SERVER_URL", "") | ||
| t.Setenv("GITHUB_ENTERPRISE_HOST", "") | ||
| t.Setenv("GITHUB_HOST", "") | ||
| t.Setenv("GH_HOST", "") | ||
| result := parseIssueSpec(tc.url) | ||
| if result != tc.expected { | ||
| t.Errorf("parseIssueSpec(%q) = %q, expected %q", tc.url, result, tc.expected) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestExtractIssueNumberFromURL_GHES(t *testing.T) { | ||
| // When GH_HOST points to a GitHub Enterprise Server, parseIssueSpec must accept | ||
| // issue URLs on that host and must reject github.com URLs (which belong to a | ||
| // different host in this configuration). | ||
| t.Setenv("GITHUB_SERVER_URL", "") | ||
| t.Setenv("GITHUB_ENTERPRISE_HOST", "") | ||
| t.Setenv("GITHUB_HOST", "") | ||
| t.Setenv("GH_HOST", "example.ghe.com") | ||
|
pelikhan marked this conversation as resolved.
|
||
|
|
||
| testCases := []struct { | ||
| name string | ||
| url string | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "GHES issue URL", | ||
| url: "https://example.ghe.com/owner/repo/issues/42", | ||
| expected: "42", | ||
| }, | ||
| { | ||
| name: "GHES issue URL with query parameters", | ||
| url: "https://example.ghe.com/owner/repo/issues/99?tab=comments", | ||
| expected: "99", | ||
| }, | ||
| { | ||
| name: "GHES issue URL with fragment", | ||
| url: "https://example.ghe.com/owner/repo/issues/7#issuecomment-1", | ||
| expected: "7", | ||
| }, | ||
| { | ||
| name: "github.com issue URL rejected when GH_HOST is GHES", | ||
| url: "https://github.com/owner/repo/issues/123", | ||
| expected: "", | ||
| }, | ||
| { | ||
| name: "other host rejected", | ||
| url: "https://gitlab.com/owner/repo/issues/123", | ||
| expected: "", | ||
| }, | ||
| { | ||
| name: "GHES non-issue URL rejected", | ||
| url: "https://example.ghe.com/owner/repo/pulls/5", | ||
| expected: "", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
|
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 inner test loop in 💡 Suggested fixMove the env guards from the outer function into each subtest — the same pattern used in for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Setenv("GITHUB_SERVER_URL", "")
t.Setenv("GITHUB_ENTERPRISE_HOST", "")
t.Setenv("GITHUB_HOST", "")
t.Setenv("GH_HOST", "example.ghe.com")
result := parseIssueSpec(tc.url)
// ...
})
}This makes each subtest hermetic and safe if @copilot please address this. |
||
| t.Run(tc.name, func(t *testing.T) { | ||
| result := parseIssueSpec(tc.url) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.