X Tutup
Skip to content

Commit b00e8a5

Browse files
author
vilmibm
committed
more accurately check for binary extension
1 parent eeca998 commit b00e8a5

File tree

2 files changed

+67
-11
lines changed

2 files changed

+67
-11
lines changed

pkg/cmd/extension/command.go

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,8 @@ func checkValidExtension(rootCmd *cobra.Command, m extensions.ExtensionManager,
247247
}
248248

249249
func isBinExtension(client *http.Client, repo ghrepo.Interface) (isBin bool, err error) {
250-
hs, err := hasScript(client, repo)
251-
if err != nil || hs {
252-
return
253-
}
254-
255-
_, err = fetchLatestRelease(client, repo)
250+
var r *release
251+
r, err = fetchLatestRelease(client, repo)
256252
if err != nil {
257253
httpErr, ok := err.(api.HTTPError)
258254
if ok && httpErr.StatusCode == 404 {
@@ -262,7 +258,16 @@ func isBinExtension(client *http.Client, repo ghrepo.Interface) (isBin bool, err
262258
return
263259
}
264260

265-
isBin = true
261+
for _, a := range r.Assets {
262+
dists := possibleDists()
263+
for _, d := range dists {
264+
if strings.HasSuffix(a.Name, d) {
265+
isBin = true
266+
break
267+
}
268+
}
269+
}
270+
266271
return
267272
}
268273

@@ -272,3 +277,52 @@ func normalizeExtensionSelector(n string) string {
272277
}
273278
return strings.TrimPrefix(n, "gh-")
274279
}
280+
281+
func possibleDists() []string {
282+
return []string{
283+
"aix-ppc64",
284+
"android-386",
285+
"android-amd64",
286+
"android-arm",
287+
"android-arm64",
288+
"darwin-amd64",
289+
"darwin-arm64",
290+
"dragonfly-amd64",
291+
"freebsd-386",
292+
"freebsd-amd64",
293+
"freebsd-arm",
294+
"freebsd-arm64",
295+
"illumos-amd64",
296+
"ios-amd64",
297+
"ios-arm64",
298+
"js-wasm",
299+
"linux-386",
300+
"linux-amd64",
301+
"linux-arm",
302+
"linux-arm64",
303+
"linux-mips",
304+
"linux-mips64",
305+
"linux-mips64le",
306+
"linux-mipsle",
307+
"linux-ppc64",
308+
"linux-ppc64le",
309+
"linux-riscv64",
310+
"linux-s390x",
311+
"netbsd-386",
312+
"netbsd-amd64",
313+
"netbsd-arm",
314+
"netbsd-arm64",
315+
"openbsd-386",
316+
"openbsd-amd64",
317+
"openbsd-arm",
318+
"openbsd-arm64",
319+
"openbsd-mips64",
320+
"plan9-386",
321+
"plan9-amd64",
322+
"plan9-arm",
323+
"solaris-amd64",
324+
"windows-386",
325+
"windows-amd64",
326+
"windows-arm",
327+
}
328+
}

pkg/cmd/extension/command_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ func TestNewCmdExtension(t *testing.T) {
4040
name: "install a git extension",
4141
args: []string{"install", "owner/gh-some-ext"},
4242
httpStubs: func(reg *httpmock.Registry) {
43+
reg.Register(
44+
httpmock.REST("GET", "repos/owner/gh-some-ext/releases/latest"),
45+
httpmock.StatusStringResponse(404, "nope"))
4346
reg.Register(
4447
httpmock.REST("GET", "repos/owner/gh-some-ext/contents/gh-some-ext"),
4548
httpmock.StringResponse("a script"))
@@ -64,12 +67,11 @@ func TestNewCmdExtension(t *testing.T) {
6467
name: "install a binary extension",
6568
args: []string{"install", "owner/gh-bin-ext"},
6669
httpStubs: func(reg *httpmock.Registry) {
67-
reg.Register(
68-
httpmock.REST("GET", "repos/owner/gh-bin-ext/contents/gh-bin-ext"),
69-
httpmock.StatusStringResponse(404, "no"))
7070
reg.Register(
7171
httpmock.REST("GET", "repos/owner/gh-bin-ext/releases/latest"),
72-
httpmock.StringResponse("{}"))
72+
httpmock.JSONResponse(release{
73+
Assets: []releaseAsset{
74+
{Name: "gh-foo-windows-amd64"}}}))
7375
},
7476
managerStubs: func(em *extensions.ExtensionManagerMock) func(*testing.T) {
7577
em.ListFunc = func(bool) []extensions.Extension {

0 commit comments

Comments
 (0)
X Tutup