Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ae3034c

Browse files
Fix adding from http/s
This broke when adding bulk add as the marketplace did a stat first to see if the source was a directory which fails for URLs.
1 parent 7879f54 commit ae3034c

File tree

3 files changed

+66
-34
lines changed

3 files changed

+66
-34
lines changed

‎CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## [1.2.1](https://github.com/coder/code-marketplace/releases/tag/v1.2.1) - 2022年10月31日
11+
12+
### Fixed
13+
14+
- Adding extensions from a URL. This broke in 1.2.0 with the addition of bulk
15+
adding.
16+
1017
## [1.2.0](https://github.com/coder/code-marketplace/releases/tag/v1.2.0) - 2022年10月20日
1118

1219
### Added

‎cli/add.go‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,19 @@ func add() *cobra.Command {
5656
return err
5757
}
5858

59-
stat, err := os.Stat(args[0])
60-
if err != nil {
61-
return err
59+
// The source might be a local directory with extensions.
60+
isDir := false
61+
if !strings.HasPrefix(args[0], "http://") && !strings.HasPrefix(args[0], "https://") {
62+
stat, err := os.Stat(args[0])
63+
if err != nil {
64+
return err
65+
}
66+
isDir = stat.IsDir()
6267
}
6368

6469
var summary []string
6570
var failed []string
66-
if stat.IsDir() {
71+
if isDir {
6772
files, err := os.ReadDir(args[0])
6873
if err != nil {
6974
return err

‎cli/add_test.go‎

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cli_test
33
import (
44
"bytes"
55
"fmt"
6+
"net/http"
7+
"net/http/httptest"
68
"os"
79
"path/filepath"
810
"testing"
@@ -97,42 +99,60 @@ func TestAdd(t *testing.T) {
9799
}
98100

99101
// With multiple extensions use bulk add by pointing to the directory
100-
// otherwise point to the vsix file.
101-
source := extdir
102+
// otherwise point to the vsix file. When not using bulk add also test
103+
// from HTTP.
104+
sources := []string{extdir}
102105
if count == 1 {
103-
source = filepath.Join(extdir, "0.vsix")
106+
sources = []string{filepath.Join(extdir, "0.vsix")}
107+
108+
handler := func(rw http.ResponseWriter, r *http.Request) {
109+
var vsix []byte
110+
if test.vsixes == nil {
111+
vsix = testutil.CreateVSIXFromExtension(t, test.extensions[0])
112+
} else {
113+
vsix = test.vsixes[0]
114+
}
115+
_, err := rw.Write(vsix)
116+
require.NoError(t, err)
117+
}
118+
server := httptest.NewServer(http.HandlerFunc(handler))
119+
defer server.Close()
120+
121+
sources = append(sources, server.URL)
104122
}
105123

106-
cmd := cli.Root()
107-
args := []string{"add", source, "--extensions-dir", extdir}
108-
cmd.SetArgs(args)
109-
buf := new(bytes.Buffer)
110-
cmd.SetOutput(buf)
124+
for _, source := range sources {
125+
cmd := cli.Root()
126+
args := []string{"add", source, "--extensions-dir", extdir}
127+
cmd.SetArgs(args)
128+
buf := new(bytes.Buffer)
129+
cmd.SetOutput(buf)
111130

112-
err := cmd.Execute()
113-
output := buf.String()
131+
err := cmd.Execute()
132+
output := buf.String()
114133

115-
if test.error != "" {
116-
require.Error(t, err)
117-
require.Regexp(t, test.error, err.Error())
118-
} else {
119-
require.NoError(t, err)
120-
}
121-
// Should list all the extensions that worked.
122-
for _, ext := range test.extensions {
123-
// Should exist on disk.
124-
dest := filepath.Join(extdir, ext.Publisher, ext.Name, ext.LatestVersion)
125-
_, err := os.Stat(dest)
126-
require.NoError(t, err)
127-
// Should tell you where it went.
128-
id := storage.ExtensionID(ext.Publisher, ext.Name, ext.LatestVersion)
129-
require.Contains(t, output, fmt.Sprintf("Unpacked %s to %s", id, dest))
130-
// Should mention the dependencies and pack.
131-
require.Contains(t, output, fmt.Sprintf("%s has %d dep", id, len(ext.Dependencies)))
132-
if len(ext.Pack) > 0 {
133-
require.Contains(t, output, fmt.Sprintf("%s is in a pack with %d other", id, len(ext.Pack)))
134+
if test.error != "" {
135+
require.Error(t, err)
136+
require.Regexp(t, test.error, err.Error())
134137
} else {
135-
require.Contains(t, output, fmt.Sprintf("%s is not in a pack", id))
138+
require.NoError(t, err)
139+
}
140+
// Should list all the extensions that worked.
141+
for _, ext := range test.extensions {
142+
// Should exist on disk.
143+
dest := filepath.Join(extdir, ext.Publisher, ext.Name, ext.LatestVersion)
144+
_, err := os.Stat(dest)
145+
require.NoError(t, err)
146+
// Should tell you where it went.
147+
id := storage.ExtensionID(ext.Publisher, ext.Name, ext.LatestVersion)
148+
require.Contains(t, output, fmt.Sprintf("Unpacked %s to %s", id, dest))
149+
// Should mention the dependencies and pack.
150+
require.Contains(t, output, fmt.Sprintf("%s has %d dep", id, len(ext.Dependencies)))
151+
if len(ext.Pack) > 0 {
152+
require.Contains(t, output, fmt.Sprintf("%s is in a pack with %d other", id, len(ext.Pack)))
153+
} else {
154+
require.Contains(t, output, fmt.Sprintf("%s is not in a pack", id))
155+
}
136156
}
137157
}
138158
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /