since we can change the machine name, we should probably allow them to list it

This commit is contained in:
Patrick Veverka 2022-02-16 00:00:13 +00:00 committed by GitHub
parent 4d45bc7654
commit e3ff873d64
2 changed files with 17 additions and 5 deletions

View file

@ -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)
}

View file

@ -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
}