From f87451ff56362dee05eb87ad9b03565a692cf34d Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Thu, 10 Jul 2025 12:33:08 +0200 Subject: [PATCH] Simplify path qualifier building logic --- pkg/cmd/search/code/code.go | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/pkg/cmd/search/code/code.go b/pkg/cmd/search/code/code.go index 944d11795..a2e152960 100644 --- a/pkg/cmd/search/code/code.go +++ b/pkg/cmd/search/code/code.go @@ -7,12 +7,12 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/gh" - "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/internal/text" "github.com/cli/cli/v2/pkg/cmd/search/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/cli/cli/v2/pkg/search" + ghauth "github.com/cli/go-gh/v2/pkg/auth" "github.com/spf13/cobra" ) @@ -117,22 +117,15 @@ func codeRun(opts *CodeOptions) error { } host, _ := cfg.Authentication().DefaultHost() // FIXME: Remove this check once GHES supports Blackbird. - if host == ghinstance.Default() { - filename, extension, _ := strings.Cut(opts.Query.Qualifiers.Filename, ".") - if filename == "" { - filename = "*" - } - // Prioritize file extension that may have been provided with the `--filename` flag. - if extension == "" { - if opts.Query.Qualifiers.Extension != "" { - extension, _ = strings.CutPrefix(opts.Query.Qualifiers.Extension, ".") - } else { - extension = "*" - } + if !ghauth.IsEnterprise(host) { + filename := opts.Query.Qualifiers.Filename + extension := opts.Query.Qualifiers.Extension + if extension != "" && !strings.HasPrefix(extension, ".") { + extension = "." + extension } opts.Query.Qualifiers.Filename = "" opts.Query.Qualifiers.Extension = "" - opts.Query.Qualifiers.Path = fmt.Sprintf("%s.%s", filename, extension) + opts.Query.Qualifiers.Path = fmt.Sprintf("%s%s", filename, extension) } } url := opts.Searcher.URL(opts.Query)