From e3ff873d649ce3675a2dc5e7672f41165099b1e6 Mon Sep 17 00:00:00 2001 From: Patrick Veverka Date: Wed, 16 Feb 2022 00:00:13 +0000 Subject: [PATCH] since we can change the machine name, we should probably allow them to list it --- internal/codespaces/api/api.go | 20 ++++++++++++++++---- pkg/cmd/codespace/edit.go | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/internal/codespaces/api/api.go b/internal/codespaces/api/api.go index fc94b22fd..1653e06ed 100644 --- a/internal/codespaces/api/api.go +++ b/internal/codespaces/api/api.go @@ -170,6 +170,7 @@ type Codespace struct { State string `json:"state"` GitStatus CodespaceGitStatus `json:"git_status"` Connection CodespaceConnection `json:"connection"` + Machine CodespaceMachine `json:"machine"` } type CodespaceGitStatus struct { @@ -180,6 +181,15 @@ type CodespaceGitStatus struct { HasUncommitedChanges bool `json:"has_uncommited_changes"` } +type CodespaceMachine struct { + Name string `json:"name"` + DisplayName string `json:"display_name"` + OperatingSystem string `json:"operating_system"` + StorageInBytes int `json:"storage_in_bytes"` + MemoryInBytes int `json:"memory_in_bytes"` + CPUCount int `json:"cpus"` +} + const ( // CodespaceStateAvailable is the state for a running codespace environment. CodespaceStateAvailable = "Available" @@ -207,6 +217,7 @@ var CodespaceFields = []string{ "gitStatus", "createdAt", "lastUsedAt", + "machineName", } func (c *Codespace) ExportData(fields []string) map[string]interface{} { @@ -219,6 +230,8 @@ func (c *Codespace) ExportData(fields []string) map[string]interface{} { data[f] = c.Owner.Login case "repository": data[f] = c.Repository.FullName + case "machineName": + data[f] = c.Machine.Name case "gitStatus": data[f] = map[string]interface{}{ "ref": c.GitStatus.Ref, @@ -265,6 +278,7 @@ func (a *API) ListCodespaces(ctx context.Context, limit int) (codespaces []*Code var response struct { Codespaces []*Codespace `json:"codespaces"` } + dec := json.NewDecoder(resp.Body) if err := dec.Decode(&response); err != nil { return nil, fmt.Errorf("error unmarshaling response: %w", err) @@ -704,7 +718,7 @@ func (a *API) EditCodespace(ctx context.Context, codespaceName string, params *E IdleTimeoutMinutes: params.IdleTimeoutMinutes, Machine: params.Machine, }) - fmt.Printf("requestBody: %s\n", requestBody) + if err != nil { return nil, fmt.Errorf("error marshaling request: %w", err) } @@ -721,9 +735,7 @@ func (a *API) EditCodespace(ctx context.Context, codespaceName string, params *E } defer resp.Body.Close() - if resp.StatusCode == http.StatusAccepted { - return nil, errProvisioningInProgress // RPC finished before result of creation known - } else if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { return nil, api.HandleHTTPError(resp) } diff --git a/pkg/cmd/codespace/edit.go b/pkg/cmd/codespace/edit.go index 16b4d3ad2..6b1af1c8c 100644 --- a/pkg/cmd/codespace/edit.go +++ b/pkg/cmd/codespace/edit.go @@ -60,6 +60,6 @@ func (a *App) Edit(ctx context.Context, opts editOptions) error { return fmt.Errorf("error editing codespace: %w", err) } - fmt.Fprintln(a.io.Out, codespace.Name) + fmt.Fprintln(a.io.Out, codespace.DisplayName) return nil }