X Tutup
Skip to content

Commit bdc9ad3

Browse files
committed
Revert other rename changes
1 parent 811d841 commit bdc9ad3

File tree

6 files changed

+35
-33
lines changed

6 files changed

+35
-33
lines changed

internal/codespaces/api/api.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ func (a *API) GetRepository(ctx context.Context, nwo string) (*Repository, error
147147
return &response, nil
148148
}
149149

150+
// Codespace represents a codespace.
150151
type Codespace struct {
151152
Name string `json:"name"`
152153
CreatedAt string `json:"created_at"`
@@ -177,6 +178,7 @@ type CodespaceEnvironmentGitStatus struct {
177178
}
178179

179180
const (
181+
// CodespaceEnvironmentStateAvailable is the state for a running codespace environment.
180182
CodespaceEnvironmentStateAvailable = "Available"
181183
)
182184

@@ -421,7 +423,7 @@ type CreateCodespaceParams struct {
421423
// CreateCodespace creates a codespace with the given parameters and returns a non-nil error if it
422424
// fails to create.
423425
func (a *API) CreateCodespace(ctx context.Context, params *CreateCodespaceParams) (*Codespace, error) {
424-
cs, err := a.startCreate(ctx, params.RepositoryID, params.Machine, params.Branch, params.Location)
426+
codespace, err := a.startCreate(ctx, params.RepositoryID, params.Machine, params.Branch, params.Location)
425427
if err != errProvisioningInProgress {
426428
return nil, err
427429
}
@@ -440,17 +442,17 @@ func (a *API) CreateCodespace(ctx context.Context, params *CreateCodespaceParams
440442
case <-ctx.Done():
441443
return nil, ctx.Err()
442444
case <-ticker.C:
443-
cs, err = a.GetCodespace(ctx, cs.Name, false)
445+
codespace, err = a.GetCodespace(ctx, codespace.Name, false)
444446
if err != nil {
445447
return nil, fmt.Errorf("failed to get codespace: %w", err)
446448
}
447449

448450
// we continue to poll until the codespace shows as provisioned
449-
if cs.State != CodespaceStateProvisioned {
451+
if codespace.State != CodespaceStateProvisioned {
450452
continue
451453
}
452454

453-
return cs, nil
455+
return codespace, nil
454456
}
455457
}
456458
}
@@ -535,14 +537,14 @@ type getCodespaceRepositoryContentsResponse struct {
535537
Content string `json:"content"`
536538
}
537539

538-
func (a *API) GetCodespaceRepositoryContents(ctx context.Context, cs *Codespace, path string) ([]byte, error) {
539-
req, err := http.NewRequest(http.MethodGet, a.githubAPI+"/repos/"+cs.RepositoryNWO+"/contents/"+path, nil)
540+
func (a *API) GetCodespaceRepositoryContents(ctx context.Context, codespace *Codespace, path string) ([]byte, error) {
541+
req, err := http.NewRequest(http.MethodGet, a.githubAPI+"/repos/"+codespace.RepositoryNWO+"/contents/"+path, nil)
540542
if err != nil {
541543
return nil, fmt.Errorf("error creating request: %w", err)
542544
}
543545

544546
q := req.URL.Query()
545-
q.Add("ref", cs.Branch)
547+
q.Add("ref", codespace.Branch)
546548
req.URL.RawQuery = q.Encode()
547549

548550
a.setHeaders(req)

internal/codespaces/codespaces.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ type logger interface {
1515
Println(v ...interface{}) (int, error)
1616
}
1717

18-
func connectionReady(cs *api.Codespace) bool {
19-
return cs.Environment.Connection.SessionID != "" &&
20-
cs.Environment.Connection.SessionToken != "" &&
21-
cs.Environment.Connection.RelayEndpoint != "" &&
22-
cs.Environment.Connection.RelaySAS != "" &&
23-
cs.Environment.State == api.CodespaceEnvironmentStateAvailable
18+
func connectionReady(codespace *api.Codespace) bool {
19+
return codespace.Environment.Connection.SessionID != "" &&
20+
codespace.Environment.Connection.SessionToken != "" &&
21+
codespace.Environment.Connection.RelayEndpoint != "" &&
22+
codespace.Environment.Connection.RelaySAS != "" &&
23+
codespace.Environment.State == api.CodespaceEnvironmentStateAvailable
2424
}
2525

2626
type apiClient interface {
@@ -30,17 +30,17 @@ type apiClient interface {
3030

3131
// ConnectToLiveshare waits for a Codespace to become running,
3232
// and connects to it using a Live Share session.
33-
func ConnectToLiveshare(ctx context.Context, log logger, apiClient apiClient, cs *api.Codespace) (*liveshare.Session, error) {
33+
func ConnectToLiveshare(ctx context.Context, log logger, apiClient apiClient, codespace *api.Codespace) (*liveshare.Session, error) {
3434
var startedCodespace bool
35-
if cs.Environment.State != api.CodespaceEnvironmentStateAvailable {
35+
if codespace.Environment.State != api.CodespaceEnvironmentStateAvailable {
3636
startedCodespace = true
3737
log.Print("Starting your codespace...")
38-
if err := apiClient.StartCodespace(ctx, cs.Name); err != nil {
38+
if err := apiClient.StartCodespace(ctx, codespace.Name); err != nil {
3939
return nil, fmt.Errorf("error starting codespace: %w", err)
4040
}
4141
}
4242

43-
for retries := 0; !connectionReady(cs); retries++ {
43+
for retries := 0; !connectionReady(codespace); retries++ {
4444
if retries > 1 {
4545
if retries%2 == 0 {
4646
log.Print(".")
@@ -54,7 +54,7 @@ func ConnectToLiveshare(ctx context.Context, log logger, apiClient apiClient, cs
5454
}
5555

5656
var err error
57-
cs, err = apiClient.GetCodespace(ctx, cs.Name, true)
57+
codespace, err = apiClient.GetCodespace(ctx, codespace.Name, true)
5858
if err != nil {
5959
return nil, fmt.Errorf("error getting codespace: %w", err)
6060
}
@@ -67,10 +67,10 @@ func ConnectToLiveshare(ctx context.Context, log logger, apiClient apiClient, cs
6767
log.Println("Connecting to your codespace...")
6868

6969
return liveshare.Connect(ctx, liveshare.Options{
70-
SessionID: cs.Environment.Connection.SessionID,
71-
SessionToken: cs.Environment.Connection.SessionToken,
72-
RelaySAS: cs.Environment.Connection.RelaySAS,
73-
RelayEndpoint: cs.Environment.Connection.RelayEndpoint,
74-
HostPublicKeys: cs.Environment.Connection.HostPublicKeys,
70+
SessionID: codespace.Environment.Connection.SessionID,
71+
SessionToken: codespace.Environment.Connection.SessionToken,
72+
RelaySAS: codespace.Environment.Connection.RelaySAS,
73+
RelayEndpoint: codespace.Environment.Connection.RelayEndpoint,
74+
HostPublicKeys: codespace.Environment.Connection.HostPublicKeys,
7575
})
7676
}

internal/codespaces/states.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ type PostCreateState struct {
3636
// PollPostCreateStates watches for state changes in a codespace,
3737
// and calls the supplied poller for each batch of state changes.
3838
// It runs until it encounters an error, including cancellation of the context.
39-
func PollPostCreateStates(ctx context.Context, log logger, apiClient apiClient, cs *api.Codespace, poller func([]PostCreateState)) (err error) {
40-
session, err := ConnectToLiveshare(ctx, log, apiClient, cs)
39+
func PollPostCreateStates(ctx context.Context, log logger, apiClient apiClient, codespace *api.Codespace, poller func([]PostCreateState)) (err error) {
40+
session, err := ConnectToLiveshare(ctx, log, apiClient, codespace)
4141
if err != nil {
4242
return fmt.Errorf("connect to Live Share: %w", err)
4343
}

pkg/cmd/codespace/common.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,23 @@ func chooseCodespaceFromList(ctx context.Context, codespaces []*api.Codespace) (
135135

136136
// getOrChooseCodespace prompts the user to choose a codespace if the codespaceName is empty.
137137
// It then fetches the codespace record with full connection details.
138-
func getOrChooseCodespace(ctx context.Context, apiClient apiClient, codespaceName string) (cs *api.Codespace, err error) {
138+
func getOrChooseCodespace(ctx context.Context, apiClient apiClient, codespaceName string) (codespace *api.Codespace, err error) {
139139
if codespaceName == "" {
140-
cs, err = chooseCodespace(ctx, apiClient)
140+
codespace, err = chooseCodespace(ctx, apiClient)
141141
if err != nil {
142142
if err == errNoCodespaces {
143143
return nil, err
144144
}
145145
return nil, fmt.Errorf("choosing codespace: %w", err)
146146
}
147147
} else {
148-
cs, err = apiClient.GetCodespace(ctx, codespaceName, true)
148+
codespace, err = apiClient.GetCodespace(ctx, codespaceName, true)
149149
if err != nil {
150150
return nil, fmt.Errorf("getting full codespace details: %w", err)
151151
}
152152
}
153153

154-
return cs, nil
154+
return codespace, nil
155155
}
156156

157157
func safeClose(closer io.Closer, err *error) {

pkg/cmd/codespace/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (a *App) Create(ctx context.Context, opts createOptions) error {
107107
// showStatus polls the codespace for a list of post create states and their status. It will keep polling
108108
// until all states have finished. Once all states have finished, we poll once more to check if any new
109109
// states have been introduced and stop polling otherwise.
110-
func showStatus(ctx context.Context, log *output.Logger, apiClient apiClient, user *api.User, cs *api.Codespace) error {
110+
func showStatus(ctx context.Context, log *output.Logger, apiClient apiClient, user *api.User, codespace *api.Codespace) error {
111111
var lastState codespaces.PostCreateState
112112
var breakNextState bool
113113

@@ -156,7 +156,7 @@ func showStatus(ctx context.Context, log *output.Logger, apiClient apiClient, us
156156
}
157157
}
158158

159-
err := codespaces.PollPostCreateStates(ctx, log, apiClient, cs, poller)
159+
err := codespaces.PollPostCreateStates(ctx, log, apiClient, codespace, poller)
160160
if err != nil {
161161
if errors.Is(err, context.Canceled) && breakNextState {
162162
return nil // we cancelled the context to stop polling, we can ignore the error

pkg/cmd/codespace/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ func (a *App) Delete(ctx context.Context, opts deleteOptions) (err error) {
7575
nameFilter = c.Name
7676
}
7777
} else {
78-
cs, err := a.apiClient.GetCodespace(ctx, nameFilter, false)
78+
codespace, err := a.apiClient.GetCodespace(ctx, nameFilter, false)
7979
if err != nil {
8080
return fmt.Errorf("error fetching codespace information: %w", err)
8181
}
8282

83-
codespaces = []*api.Codespace{cs}
83+
codespaces = []*api.Codespace{codespace}
8484
}
8585

8686
codespacesToDelete := make([]*api.Codespace, 0, len(codespaces))

0 commit comments

Comments
 (0)
X Tutup