diff --git a/CHANGELOG.md b/CHANGELOG.md index 74cb41e0cc..b89490e9df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ All notable changes to `src-cli` are documented in this file. - SBOM support: Added `--image` and `--exclude-image` flags to `src sbom fetch` for filtering which docker images SBOMs are fetched for. Both flags support glob patterns (e.g., `frontend`, `*api*`) and comma-separated lists. The `sourcegraph/` image name prefix is optional. +### Changed + +- The deprecated `src extensions` commands have been removed. + ## 6.4.0 ## 6.3.0 diff --git a/cmd/src/cmd.go b/cmd/src/cmd.go index 35cc240fac..95c16e6e0e 100644 --- a/cmd/src/cmd.go +++ b/cmd/src/cmd.go @@ -6,9 +6,6 @@ import ( "log" "os" "slices" - "strings" - - "github.com/sourcegraph/sourcegraph/lib/errors" "github.com/sourcegraph/src-cli/internal/cmderrors" ) @@ -128,16 +125,3 @@ func (c commander) run(flagSet *flag.FlagSet, cmdName, usageText string, args [] log.Printf("%s: unknown subcommand %q", cmdName, name) log.Fatalf("Run '%s help' for usage.", cmdName) } - -func didYouMeanOtherCommand(actual string, suggested []string) *command { - fullSuggestions := make([]string, len(suggested)) - for i, s := range suggested { - fullSuggestions[i] = "src " + s - } - msg := fmt.Sprintf("src: unknown subcommand %q\n\nDid you mean:\n\n\t%s", actual, strings.Join(fullSuggestions, "\n\t")) - return &command{ - flagSet: flag.NewFlagSet(actual, flag.ExitOnError), - handler: func(args []string) error { return errors.New(msg) }, - usageFunc: func() { log.Println(msg) }, - } -} diff --git a/cmd/src/doc.go b/cmd/src/doc.go index dc4e7a222c..0bcb7b9d1a 100644 --- a/cmd/src/doc.go +++ b/cmd/src/doc.go @@ -56,7 +56,6 @@ Examples: "": &commands, "batch": &batchCommands, "config": &configCommands, - "extensions": &extensionsCommands, "extsvc": &extsvcCommands, "code-intel": &codeintelCommands, "orgs": &orgsCommands, diff --git a/cmd/src/extensions.go b/cmd/src/extensions.go deleted file mode 100644 index 9c33ab3bc2..0000000000 --- a/cmd/src/extensions.go +++ /dev/null @@ -1,87 +0,0 @@ -package main - -import ( - "flag" - "fmt" -) - -var extensionsCommands commander - -func init() { - usage := `'src extensions' is a tool that manages extensions in the extension registry on a Sourcegraph instance. - -DEPRECATED: We're in the process of removing Sourcegraph extensions with our September release. - Learn more: https://docs.sourcegraph.com/extensions/deprecation - -Usage: - - src extensions command [command options] - -The commands are: - - copy copy an extension from Sourcegraph.com to your private extension registry - publish publish the extension in the current directory - list lists extensions - get gets an extension - delete deletes an extension - -Use "src extensions [command] -h" for more information about a command. - -Alias: "src ext" -` - - flagSet := flag.NewFlagSet("extensions", flag.ExitOnError) - handler := func(args []string) error { - extensionsCommands.run(flagSet, "src extensions", usage, args) - return nil - } - - // Register the command. - commands = append(commands, &command{ - flagSet: flagSet, - aliases: []string{"ext", "extension"}, - handler: handler, - usageFunc: func() { - fmt.Println(usage) - }, - }) -} - -const registryExtensionFragment = ` -fragment RegistryExtensionFields on RegistryExtension { - id - uuid - extensionID - name - createdAt - updatedAt - url - remoteURL - registryName - isLocal - manifest { - raw - description - bundleURL - } -} -` - -type Extension struct { - ID string - UUID string - ExtensionID string - Name string - CreatedAt string - UpdatedAt string - URL string - RemoteURL string - RegistryName string - IsLocal bool - Manifest struct { - Raw string - Title string - Description string - BundleURL string - } -} diff --git a/cmd/src/extensions_copy.go b/cmd/src/extensions_copy.go deleted file mode 100644 index 4b91cf9f62..0000000000 --- a/cmd/src/extensions_copy.go +++ /dev/null @@ -1,174 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - "io" - "net/http" - "strings" - - "github.com/sourcegraph/src-cli/internal/api" -) - -func withCfg(new *config, f func()) { - old := cfg - cfg = new - f() - cfg = old -} - -func init() { - usage := ` -Copy an extension from Sourcegraph.com to your private registry. -` - - flagSet := flag.NewFlagSet("copy", flag.ExitOnError) - usageFunc := func() { - fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src extensions %s':\n", flagSet.Name()) - flagSet.PrintDefaults() - fmt.Println(usage) - } - var ( - extensionIDFlag = flagSet.String("extension-id", "", `The in https://sourcegraph.com/extensions/ (e.g. sourcegraph/java)`) - currentUserFlag = flagSet.String("current-user", "", `The current user`) - apiFlags = api.NewFlags(flagSet) - ) - - handler := func(args []string) error { - err := flagSet.Parse(args) - if err != nil { - return err - } - - extensionID := *extensionIDFlag - if extensionID == "" { - return fmt.Errorf("must provide -extension-id") - } - - currentUser := *currentUserFlag - if currentUser == "" { - return fmt.Errorf("must provide -current-user") - } - - extensionIDParts := strings.Split(extensionID, "/") - if len(extensionIDParts) != 2 { - return fmt.Errorf("-extension-id must have the form /") - } - extensionName := extensionIDParts[1] - - ctx := context.Background() - client := cfg.apiClient(apiFlags, flagSet.Output()) - ok := false - - var extensionResult struct { - ExtensionRegistry struct { - Extension struct { - Manifest struct { - Raw string - BundleURL string - } - } - } - } - - withCfg(&config{Endpoint: "https://sourcegraph.com"}, func() { - dotComClient := cfg.apiClient(apiFlags, flagSet.Output()) - query := `query GetExtension( - $extensionID: String! -){ - extensionRegistry{ - extension(extensionID: $extensionID) { - manifest{ - raw - bundleURL - } - } - } -}` - - ok, err = dotComClient.NewRequest(query, map[string]interface{}{ - "extensionID": extensionID, - }).Do(ctx, &extensionResult) - }) - if err != nil || !ok { - return err - } - - rawManifest := []byte(extensionResult.ExtensionRegistry.Extension.Manifest.Raw) - manifest, err := updatePropertyInManifest(rawManifest, "extensionID", extensionID) - if err != nil { - return err - } - // Remove sourcegraph.com bundle URL. - manifest, err = updatePropertyInManifest(manifest, "url", "") - if err != nil { - return err - } - - response, err := http.Get(extensionResult.ExtensionRegistry.Extension.Manifest.BundleURL) - if err != nil { - return err - } - defer response.Body.Close() - bundle, err := io.ReadAll(response.Body) - if err != nil { - return err - } - fmt.Printf("bundle: %s\n", string(bundle[0:100])) - fmt.Printf("manifest: %s\n", string(manifest[0:])) - - query := `mutation PublishExtension( - $extensionID: String!, - $manifest: String!, - $bundle: String, -) { - extensionRegistry { - publishExtension( - extensionID: $extensionID, - manifest: $manifest, - bundle: $bundle - ) { - extension { - extensionID - url - } - } - } -}` - - var publishResult struct { - ExtensionRegistry struct { - PublishExtension struct { - Extension struct { - ExtensionID string - URL string - } - } - } - } - if ok, err := client.NewRequest(query, map[string]interface{}{ - "extensionID": currentUser + "/" + extensionName, - "manifest": string(manifest), - "bundle": bundle, - }).Do(ctx, &publishResult); err != nil || !ok { - return err - } - - fmt.Println("Extension published!") - fmt.Println() - fmt.Printf("\tExtension ID: %s\n\n", publishResult.ExtensionRegistry.PublishExtension.Extension.ExtensionID) - fmt.Printf("View, enable, and configure it at: %s\n", cfg.Endpoint+publishResult.ExtensionRegistry.PublishExtension.Extension.URL) - return nil - } - - // Register the command. - extensionsCommands = append(extensionsCommands, &command{ - flagSet: flagSet, - handler: handler, - usageFunc: usageFunc, - }) - - // Catch the mistake of omitting the "extensions" subcommand. - commands = append(commands, didYouMeanOtherCommand("publish", []string{"extensions publish", "ext publish (alias)"})) -} diff --git a/cmd/src/extensions_delete.go b/cmd/src/extensions_delete.go deleted file mode 100644 index 863c2c655b..0000000000 --- a/cmd/src/extensions_delete.go +++ /dev/null @@ -1,77 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - - "github.com/sourcegraph/src-cli/internal/api" -) - -func init() { - usage := ` -Examples: - - Delete the extension by ID (GraphQL API ID, not extension ID): - - $ src extensions delete -id=UmVnaXN0cnlFeHRlbnNpb246... - - Delete the extension with extension ID "alice/myextension": - - $ src extensions delete -id=$(src extensions get -f '{{.ID}}' -extension-id=alice/myextension) - -` - - flagSet := flag.NewFlagSet("delete", flag.ExitOnError) - usageFunc := func() { - fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src extensions %s':\n", flagSet.Name()) - flagSet.PrintDefaults() - fmt.Println(usage) - } - var ( - extensionIDFlag = flagSet.String("id", "", `The ID (GraphQL API ID, not extension ID) of the extension to delete.`) - apiFlags = api.NewFlags(flagSet) - ) - - handler := func(args []string) error { - err := flagSet.Parse(args) - if err != nil { - return err - } - - client := cfg.apiClient(apiFlags, flagSet.Output()) - - query := `mutation DeleteExtension( - $extension: ID! -) { - extensionRegistry { - deleteExtension( - extension: $extension - ) { - alwaysNil - } - } -}` - - var result struct { - ExtensionRegistry struct { - DeleteExtension struct{} - } - } - if ok, err := client.NewRequest(query, map[string]interface{}{ - "extension": *extensionIDFlag, - }).Do(context.Background(), &result); err != nil || !ok { - return err - } - - fmt.Printf("Extension with ID %q deleted.\n", *extensionIDFlag) - return nil - } - - // Register the command. - extensionsCommands = append(extensionsCommands, &command{ - flagSet: flagSet, - handler: handler, - usageFunc: usageFunc, - }) -} diff --git a/cmd/src/extensions_get.go b/cmd/src/extensions_get.go deleted file mode 100644 index 9763e504ba..0000000000 --- a/cmd/src/extensions_get.go +++ /dev/null @@ -1,83 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - - "github.com/sourcegraph/src-cli/internal/api" -) - -func init() { - usage := ` -Examples: - - Get extension with extension ID "alice/myextension": - - $ src extensions get alice/myextension - $ src extensions get -extension-id=alice/myextension - -` - - flagSet := flag.NewFlagSet("get", flag.ExitOnError) - usageFunc := func() { - fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src extensions %s':\n", flagSet.Name()) - flagSet.PrintDefaults() - fmt.Println(usage) - } - var ( - extensionIDFlag = flagSet.String("extension-id", "", `Look up extension by extension ID. (e.g. "alice/myextension")`) - formatFlag = flagSet.String("f", "{{.|json}}", `Format for the output, using the syntax of Go package text/template. (e.g. "{{.ExtensionID}}: {{.Manifest.Title}} ({{.RemoteURL}})" or "{{.|json}}")`) - apiFlags = api.NewFlags(flagSet) - ) - - handler := func(args []string) error { - if err := flagSet.Parse(args); err != nil { - return err - } - - tmpl, err := parseTemplate(*formatFlag) - if err != nil { - return err - } - - client := cfg.apiClient(apiFlags, flagSet.Output()) - - query := `query RegistryExtension( - $extensionID: String!, -) { - extensionRegistry { - extension( - extensionID: $extensionID - ) { - ...RegistryExtensionFields - } - } -}` + registryExtensionFragment - - extensionID := *extensionIDFlag - if extensionID == "" && flagSet.NArg() == 1 { - extensionID = flagSet.Arg(0) - } - - var result struct { - ExtensionRegistry struct { - Extension *Extension - } - } - if ok, err := client.NewRequest(query, map[string]interface{}{ - "extensionID": extensionID, - }).Do(context.Background(), &result); err != nil || !ok { - return err - } - - return execTemplate(tmpl, result.ExtensionRegistry.Extension) - } - - // Register the command. - extensionsCommands = append(extensionsCommands, &command{ - flagSet: flagSet, - handler: handler, - usageFunc: usageFunc, - }) -} diff --git a/cmd/src/extensions_list.go b/cmd/src/extensions_list.go deleted file mode 100644 index 6aa5bead6c..0000000000 --- a/cmd/src/extensions_list.go +++ /dev/null @@ -1,104 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - - "github.com/sourcegraph/src-cli/internal/api" -) - -func init() { - usage := ` -Examples: - - List extensions: - - $ src extensions list - - List extensions whose names match the query: - - $ src extensions list -query='myquery' - - List *all* extensions (may be slow!): - - $ src extensions list -first='-1' - -` - - flagSet := flag.NewFlagSet("list", flag.ExitOnError) - usageFunc := func() { - fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src extensions %s':\n", flagSet.Name()) - flagSet.PrintDefaults() - fmt.Println(usage) - } - var ( - firstFlag = flagSet.Int("first", 1000, "Returns the first n extensions from the list. (use -1 for unlimited)") - queryFlag = flagSet.String("query", "", `Returns extensions whose extension IDs match the query. (e.g. "myextension")`) - formatFlag = flagSet.String("f", "{{.ExtensionID}}", `Format for the output, using the syntax of Go package text/template. (e.g. "{{.ExtensionID}}: {{.Manifest.Description}} ({{.RemoteURL}})" or "{{.|json}}")`) - apiFlags = api.NewFlags(flagSet) - ) - - handler := func(args []string) error { - if err := flagSet.Parse(args); err != nil { - return err - } - - tmpl, err := parseTemplate(*formatFlag) - if err != nil { - return err - } - - client := cfg.apiClient(apiFlags, flagSet.Output()) - - query := `query RegistryExtensions( - $first: Int, - $query: String, -) { - extensionRegistry { - extensions( - first: $first, - query: $query, - ) { - nodes { - ...RegistryExtensionFields - } - error - } - } -}` + registryExtensionFragment - - var result struct { - ExtensionRegistry struct { - Extensions struct { - Nodes []Extension - Error string - } - } - } - if ok, err := client.NewRequest(query, map[string]interface{}{ - "first": api.NullInt(*firstFlag), - "query": api.NullString(*queryFlag), - }).Do(context.Background(), &result); err != nil || !ok { - return err - } - - if result.ExtensionRegistry.Extensions.Error != "" { - return fmt.Errorf("%s", result.ExtensionRegistry.Extensions.Error) - } - - for _, extension := range result.ExtensionRegistry.Extensions.Nodes { - if err := execTemplate(tmpl, extension); err != nil { - return err - } - } - return nil - } - - // Register the command. - extensionsCommands = append(extensionsCommands, &command{ - flagSet: flagSet, - handler: handler, - usageFunc: usageFunc, - }) -} diff --git a/cmd/src/extensions_publish.go b/cmd/src/extensions_publish.go deleted file mode 100644 index 2156c7b170..0000000000 --- a/cmd/src/extensions_publish.go +++ /dev/null @@ -1,318 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "flag" - "fmt" - "os" - "os/exec" - "path/filepath" - "strings" - - "github.com/sourcegraph/sourcegraph/lib/errors" - - "github.com/sourcegraph/src-cli/internal/api" -) - -func init() { - usage := ` -Publish an extension to Sourcegraph, creating it (if necessary). - -Examples: - - Publish the "alice/myextension" extension described by package.json in the current directory: - - $ cat package.json - { - "name": "myextension", - "publisher": "alice", - "title": "My Extension", - "main": "dist/myext.js", - "scripts": {"sourcegraph:prepublish": "parcel build --out-file dist/myext.js src/myext.ts"} - } - $ src extensions publish - -Notes: - - Source maps are supported (for easier debugging of extensions). If the main JavaScript bundle is "dist/myext.js", - it looks for a source map in "dist/myext.map". - -` - - flagSet := flag.NewFlagSet("publish", flag.ExitOnError) - usageFunc := func() { - fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src extensions %s':\n", flagSet.Name()) - flagSet.PrintDefaults() - fmt.Println(usage) - } - var ( - extensionIDFlag = flagSet.String("extension-id", "", `Override the extension ID in the manifest. (default: read from -manifest file)`) - urlFlag = flagSet.String("url", "", `Override the URL for the bundle. (example: set to http://localhost:1234/myext.js for local dev with parcel)`) - gitHeadFlag = flagSet.String("git-head", "", "Override the current git commit for the bundle. (default: uses `git rev-parse head`)") - manifestFlag = flagSet.String("manifest", "package.json", `The extension manifest file.`) - forceFlag = flagSet.Bool("force", false, `Force publish the extension, even if there are validation problems or other warnings.`) - apiFlags = api.NewFlags(flagSet) - ) - - handler := func(args []string) error { - if err := flagSet.Parse(args); err != nil { - return err - } - - manifestPath, err := filepath.Abs(*manifestFlag) - if err != nil { - return err - } - manifestDir := filepath.Dir(manifestPath) - - manifest, err := os.ReadFile(manifestPath) - if err != nil { - return fmt.Errorf("%s\n\nRun this command in a directory with a %s file for an extension.\n\nSee 'src extensions %s -h' for help", err, *manifestFlag, flagSet.Name()) - } - extensionID := *extensionIDFlag - if extensionID == "" { - extensionID, err = readExtensionIDFromManifest(manifest) - if err != nil { - return err - } - } - manifest, err = updatePropertyInManifest(manifest, "extensionID", extensionID) - if err != nil { - return err - } - manifest, err = addReadmeToManifest(manifest, manifestDir) - if err != nil { - return err - } - - var bundle, sourceMap *string - if *urlFlag != "" { - manifest, err = updatePropertyInManifest(manifest, "url", *urlFlag) - if err != nil { - return err - } - } else { - // Prepare and upload bundle. - if err := runManifestPrepublishScript(manifest, manifestDir); err != nil { - return err - } - - var err error - bundle, sourceMap, err = readExtensionArtifacts(manifest, manifestDir) - if err != nil { - return err - } - } - - if *gitHeadFlag != "" { - manifest, err = updatePropertyInManifest(manifest, "gitHead", *gitHeadFlag) - if err != nil { - return err - } - } else { - command := exec.Command("git", "rev-parse", "head") - command.Dir = manifestDir - - out, err := command.CombinedOutput() - if err != nil { - fmt.Printf("failed to determine git head: %q\n", err) - } else { - manifest, err = updatePropertyInManifest(manifest, "gitHead", strings.TrimSpace(string(out))) - if err != nil { - return err - } - } - } - - client := cfg.apiClient(apiFlags, flagSet.Output()) - - query := `mutation PublishExtension( - $extensionID: String!, - $manifest: String!, - $bundle: String, - $sourceMap: String, - $force: Boolean!, -) { - extensionRegistry { - publishExtension( - extensionID: $extensionID, - manifest: $manifest, - bundle: $bundle, - sourceMap: $sourceMap, - force: $force, - ) { - extension { - extensionID - url - } - } - } -}` - - var result struct { - ExtensionRegistry struct { - PublishExtension struct { - Extension struct { - ExtensionID string - URL string - } - } - } - } - if ok, err := client.NewRequest(query, map[string]interface{}{ - "extensionID": extensionID, - "manifest": string(manifest), - "bundle": bundle, - "sourceMap": sourceMap, - "force": *forceFlag, - }).Do(context.Background(), &result); err != nil || !ok { - return err - } - - fmt.Println("Extension published!") - fmt.Println() - fmt.Printf("\tExtension ID: %s\n\n", result.ExtensionRegistry.PublishExtension.Extension.ExtensionID) - fmt.Printf("View, enable, and configure it at: %s\n", cfg.Endpoint+result.ExtensionRegistry.PublishExtension.Extension.URL) - return nil - } - - // Register the command. - extensionsCommands = append(extensionsCommands, &command{ - flagSet: flagSet, - handler: handler, - usageFunc: usageFunc, - }) - - // Catch the mistake of omitting the "extensions" subcommand. - commands = append(commands, didYouMeanOtherCommand("publish", []string{"extensions publish", "ext publish (alias)"})) -} - -func runManifestPrepublishScript(manifest []byte, dir string) error { - var o struct { - Scripts struct { - SourcegraphPrepublish string `json:"sourcegraph:prepublish"` - } `json:"scripts"` - } - if err := json.Unmarshal(manifest, &o); err != nil { - return err - } - - if o.Scripts.SourcegraphPrepublish == "" { - return nil - } - cmd := exec.Command("bash", "-c", o.Scripts.SourcegraphPrepublish) - cmd.Env = append(os.Environ(), fmt.Sprintf("PATH=%s:%s", filepath.Join(dir, "node_modules", ".bin"), os.Getenv("PATH"))) - cmd.Dir = dir - cmd.Stdout = os.Stderr - cmd.Stderr = os.Stderr - fmt.Fprintf(os.Stderr, "# sourcegraph:prepublish: %s\n", o.Scripts.SourcegraphPrepublish) - if err := cmd.Run(); err != nil { - return fmt.Errorf("sourcegraph:prepublish script failed: %w (see output above)", err) - } - fmt.Fprintln(os.Stderr) - return nil -} - -func readExtensionIDFromManifest(manifest []byte) (string, error) { - var o map[string]interface{} - if err := json.Unmarshal(manifest, &o); err != nil { - return "", err - } - - extensionID, _ := o["extensionID"].(string) - if extensionID != "" { - return extensionID, nil - } - - name, _ := o["name"].(string) - publisher, _ := o["publisher"].(string) - if name == "" && publisher == "" { - return "", errors.New(`extension manifest must contain "name" and "publisher" string properties (the extension ID is of the form "publisher/name" and uses these values)`) - } - if name == "" { - return "", fmt.Errorf(`extension manifest must contain a "name" string property for the extension name (the extension ID will be %q)`, publisher+"/name") - } - if publisher == "" { - return "", fmt.Errorf(`extension manifest must contain a "publisher" string property referring to a username or organization name on Sourcegraph (the extension ID will be %q)`, "publisher/"+name) - } - return publisher + "/" + name, nil -} - -func updatePropertyInManifest(manifest []byte, property, value string) (updatedManifest []byte, err error) { - var o map[string]interface{} - if err := json.Unmarshal(manifest, &o); err != nil { - return nil, err - } - if o == nil { - o = map[string]interface{}{} - } - if value == "" { - delete(o, property) - } else { - o[property] = value - } - return json.MarshalIndent(o, "", " ") -} - -func addReadmeToManifest(manifest []byte, dir string) ([]byte, error) { - var readme string - filenames := []string{"README.md", "README.txt", "README", "readme.md", "readme.txt", "readme", "Readme.md", "Readme.txt", "Readme"} - for _, f := range filenames { - data, err := os.ReadFile(filepath.Join(dir, f)) - if err != nil { - continue - } - readme = string(data) - break - } - - if readme == "" { - return manifest, nil - } - - var o map[string]interface{} - if err := json.Unmarshal(manifest, &o); err != nil { - return nil, err - } - if o == nil { - o = map[string]interface{}{} - } - o["readme"] = readme - return json.MarshalIndent(o, "", " ") -} - -func readExtensionArtifacts(manifest []byte, dir string) (bundle, sourceMap *string, err error) { - var o struct { - Main string `json:"main"` - } - if err := json.Unmarshal(manifest, &o); err != nil { - return nil, nil, err - } - if o.Main == "" { - return nil, nil, nil - } - - mainPath := filepath.Join(dir, o.Main) - - data, err := os.ReadFile(mainPath) - if err != nil { - return nil, nil, fmt.Errorf(`extension manifest "main" bundle file: %s`, err) - } - { - tmp := string(data) - bundle = &tmp - } - - // Guess that source map is the main file with a ".map" extension. - sourceMapPath := strings.TrimSuffix(mainPath, filepath.Ext(mainPath)) + ".map" - data, err = os.ReadFile(sourceMapPath) - if err == nil { - tmp := string(data) - sourceMap = &tmp - } else if !os.IsNotExist(err) { - return nil, nil, err - } - - return bundle, sourceMap, nil -} diff --git a/cmd/src/extensions_publish_test.go b/cmd/src/extensions_publish_test.go deleted file mode 100644 index abf2832968..0000000000 --- a/cmd/src/extensions_publish_test.go +++ /dev/null @@ -1,80 +0,0 @@ -package main - -import ( - "encoding/json" - "reflect" - "testing" -) - -func TestReadExtensionIDFromManifest(t *testing.T) { - tests := map[string]string{ - `{"name": "a", "publisher": "b"}`: "b/a", - `{"name": "a", "publisher": "b", "extensionID": "c"}`: "c", - `{"extensionID": "c"}`: "c", - } - for manifest, want := range tests { - t.Run(manifest, func(t *testing.T) { - got, err := readExtensionIDFromManifest([]byte(manifest)) - if err != nil { - t.Fatal(err) - } - if got != want { - t.Errorf("got %q, want %q", got, want) - } - }) - } - - t.Run("no name", func(t *testing.T) { - if _, err := readExtensionIDFromManifest([]byte(`{}`)); err == nil { - t.Fatal() - } - }) - - t.Run("no publisher", func(t *testing.T) { - if _, err := readExtensionIDFromManifest([]byte(`{"name":"a"}`)); err == nil { - t.Fatal() - } - }) -} - -func TestUpdatePropertyInManifest(t *testing.T) { - tests := map[string]string{ - `{}`: `{"p": "x"}`, - `{"a":1}`: `{"a":1, "p": "x"}`, - `{"p":"a"}`: `{"p": "x"}`, - } - for manifest, want := range tests { - t.Run(manifest, func(t *testing.T) { - got, err := updatePropertyInManifest([]byte(manifest), "p", "x") - if err != nil { - t.Fatal(err) - } - if !jsonDeepEqual(string(got), want) { - t.Errorf("got %q, want %q", got, want) - } - }) - } - - t.Run("remove property", func(t *testing.T) { - manifest := `{"extensionID":"sourcegraph/typescript", "url":"https://sourcegraph.com"}` - want := `{"extensionID": "sourcegraph/typescript"}` - got, err := updatePropertyInManifest([]byte(manifest), "url", "") - if err != nil { - t.Fatal(err) - } - if !jsonDeepEqual(string(got), want) { - t.Errorf("got %q, want %q", got, want) - } - }) -} - -func jsonDeepEqual(a, b string) bool { - var va, vb interface{} - if err := json.Unmarshal([]byte(a), &va); err != nil { - panic(err) - } - if err := json.Unmarshal([]byte(b), &vb); err != nil { - panic(err) - } - return reflect.DeepEqual(va, vb) -} diff --git a/cmd/src/users_prune.go b/cmd/src/users_prune.go index e35555feb6..8c78ef2b11 100644 --- a/cmd/src/users_prune.go +++ b/cmd/src/users_prune.go @@ -166,7 +166,7 @@ Examples: } // confirm and remove users - if confirmed, _ := confirmUserRemoval(usersToDelete, int(totalUsers.Site.Users.TotalCount), *daysToDelete, *displayUsersToDelete); !confirmed { + if confirmed, _ := confirmUserRemoval(usersToDelete, *daysToDelete, *displayUsersToDelete); !confirmed { fmt.Println("Aborting removal") return nil } else { @@ -223,7 +223,7 @@ type UserToDelete struct { } // Verify user wants to remove users with table of users and a command prompt for [y/N] -func confirmUserRemoval(usersToDelete []UserToDelete, totalUsers int, daysThreshold int, displayUsers bool) (bool, error) { +func confirmUserRemoval(usersToDelete []UserToDelete, daysThreshold int, displayUsers bool) (bool, error) { if displayUsers { fmt.Printf("Users to remove from %s\n", cfg.Endpoint) t := table.NewWriter()