Skip to content

Commit

Permalink
since we can change the machine name, we should probably allow them t…
Browse files Browse the repository at this point in the history
…o list it
  • Loading branch information
veverkap authored Feb 16, 2022
1 parent 4d45bc7 commit e3ff873
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions internal/codespaces/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"
Expand Down Expand Up @@ -207,6 +217,7 @@ var CodespaceFields = []string{
"gitStatus",
"createdAt",
"lastUsedAt",
"machineName",
}

func (c *Codespace) ExportData(fields []string) map[string]interface{} {
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/codespace/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit e3ff873

Please sign in to comment.