diff --git a/pkg/cmd/extension/command.go b/pkg/cmd/extension/command.go index f83637681..8153ef5e4 100644 --- a/pkg/cmd/extension/command.go +++ b/pkg/cmd/extension/command.go @@ -247,12 +247,8 @@ func checkValidExtension(rootCmd *cobra.Command, m extensions.ExtensionManager, } func isBinExtension(client *http.Client, repo ghrepo.Interface) (isBin bool, err error) { - hs, err := hasScript(client, repo) - if err != nil || hs { - return - } - - _, err = fetchLatestRelease(client, repo) + var r *release + r, err = fetchLatestRelease(client, repo) if err != nil { httpErr, ok := err.(api.HTTPError) if ok && httpErr.StatusCode == 404 { @@ -262,7 +258,16 @@ func isBinExtension(client *http.Client, repo ghrepo.Interface) (isBin bool, err return } - isBin = true + for _, a := range r.Assets { + dists := possibleDists() + for _, d := range dists { + if strings.HasSuffix(a.Name, d) { + isBin = true + break + } + } + } + return } @@ -272,3 +277,52 @@ func normalizeExtensionSelector(n string) string { } return strings.TrimPrefix(n, "gh-") } + +func possibleDists() []string { + return []string{ + "aix-ppc64", + "android-386", + "android-amd64", + "android-arm", + "android-arm64", + "darwin-amd64", + "darwin-arm64", + "dragonfly-amd64", + "freebsd-386", + "freebsd-amd64", + "freebsd-arm", + "freebsd-arm64", + "illumos-amd64", + "ios-amd64", + "ios-arm64", + "js-wasm", + "linux-386", + "linux-amd64", + "linux-arm", + "linux-arm64", + "linux-mips", + "linux-mips64", + "linux-mips64le", + "linux-mipsle", + "linux-ppc64", + "linux-ppc64le", + "linux-riscv64", + "linux-s390x", + "netbsd-386", + "netbsd-amd64", + "netbsd-arm", + "netbsd-arm64", + "openbsd-386", + "openbsd-amd64", + "openbsd-arm", + "openbsd-arm64", + "openbsd-mips64", + "plan9-386", + "plan9-amd64", + "plan9-arm", + "solaris-amd64", + "windows-386", + "windows-amd64", + "windows-arm", + } +} diff --git a/pkg/cmd/extension/command_test.go b/pkg/cmd/extension/command_test.go index 635fcba17..8c54b24da 100644 --- a/pkg/cmd/extension/command_test.go +++ b/pkg/cmd/extension/command_test.go @@ -40,6 +40,9 @@ func TestNewCmdExtension(t *testing.T) { name: "install a git extension", args: []string{"install", "owner/gh-some-ext"}, httpStubs: func(reg *httpmock.Registry) { + reg.Register( + httpmock.REST("GET", "repos/owner/gh-some-ext/releases/latest"), + httpmock.StatusStringResponse(404, "nope")) reg.Register( httpmock.REST("GET", "repos/owner/gh-some-ext/contents/gh-some-ext"), httpmock.StringResponse("a script")) @@ -64,12 +67,11 @@ func TestNewCmdExtension(t *testing.T) { name: "install a binary extension", args: []string{"install", "owner/gh-bin-ext"}, httpStubs: func(reg *httpmock.Registry) { - reg.Register( - httpmock.REST("GET", "repos/owner/gh-bin-ext/contents/gh-bin-ext"), - httpmock.StatusStringResponse(404, "no")) reg.Register( httpmock.REST("GET", "repos/owner/gh-bin-ext/releases/latest"), - httpmock.StringResponse("{}")) + httpmock.JSONResponse(release{ + Assets: []releaseAsset{ + {Name: "gh-foo-windows-amd64"}}})) }, managerStubs: func(em *extensions.ExtensionManagerMock) func(*testing.T) { em.ListFunc = func(bool) []extensions.Extension {