X Tutup
Skip to content

Commit e3ff873

Browse files
authored
since we can change the machine name, we should probably allow them to list it
1 parent 4d45bc7 commit e3ff873

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

internal/codespaces/api/api.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ type Codespace struct {
170170
State string `json:"state"`
171171
GitStatus CodespaceGitStatus `json:"git_status"`
172172
Connection CodespaceConnection `json:"connection"`
173+
Machine CodespaceMachine `json:"machine"`
173174
}
174175

175176
type CodespaceGitStatus struct {
@@ -180,6 +181,15 @@ type CodespaceGitStatus struct {
180181
HasUncommitedChanges bool `json:"has_uncommited_changes"`
181182
}
182183

184+
type CodespaceMachine struct {
185+
Name string `json:"name"`
186+
DisplayName string `json:"display_name"`
187+
OperatingSystem string `json:"operating_system"`
188+
StorageInBytes int `json:"storage_in_bytes"`
189+
MemoryInBytes int `json:"memory_in_bytes"`
190+
CPUCount int `json:"cpus"`
191+
}
192+
183193
const (
184194
// CodespaceStateAvailable is the state for a running codespace environment.
185195
CodespaceStateAvailable = "Available"
@@ -207,6 +217,7 @@ var CodespaceFields = []string{
207217
"gitStatus",
208218
"createdAt",
209219
"lastUsedAt",
220+
"machineName",
210221
}
211222

212223
func (c *Codespace) ExportData(fields []string) map[string]interface{} {
@@ -219,6 +230,8 @@ func (c *Codespace) ExportData(fields []string) map[string]interface{} {
219230
data[f] = c.Owner.Login
220231
case "repository":
221232
data[f] = c.Repository.FullName
233+
case "machineName":
234+
data[f] = c.Machine.Name
222235
case "gitStatus":
223236
data[f] = map[string]interface{}{
224237
"ref": c.GitStatus.Ref,
@@ -265,6 +278,7 @@ func (a *API) ListCodespaces(ctx context.Context, limit int) (codespaces []*Code
265278
var response struct {
266279
Codespaces []*Codespace `json:"codespaces"`
267280
}
281+
268282
dec := json.NewDecoder(resp.Body)
269283
if err := dec.Decode(&response); err != nil {
270284
return nil, fmt.Errorf("error unmarshaling response: %w", err)
@@ -704,7 +718,7 @@ func (a *API) EditCodespace(ctx context.Context, codespaceName string, params *E
704718
IdleTimeoutMinutes: params.IdleTimeoutMinutes,
705719
Machine: params.Machine,
706720
})
707-
fmt.Printf("requestBody: %s\n", requestBody)
721+
708722
if err != nil {
709723
return nil, fmt.Errorf("error marshaling request: %w", err)
710724
}
@@ -721,9 +735,7 @@ func (a *API) EditCodespace(ctx context.Context, codespaceName string, params *E
721735
}
722736
defer resp.Body.Close()
723737

724-
if resp.StatusCode == http.StatusAccepted {
725-
return nil, errProvisioningInProgress // RPC finished before result of creation known
726-
} else if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
738+
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
727739
return nil, api.HandleHTTPError(resp)
728740
}
729741

pkg/cmd/codespace/edit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ func (a *App) Edit(ctx context.Context, opts editOptions) error {
6060
return fmt.Errorf("error editing codespace: %w", err)
6161
}
6262

63-
fmt.Fprintln(a.io.Out, codespace.Name)
63+
fmt.Fprintln(a.io.Out, codespace.DisplayName)
6464
return nil
6565
}

0 commit comments

Comments
 (0)
X Tutup