Revert other rename changes
This commit is contained in:
parent
811d841fae
commit
bdc9ad30e7
6 changed files with 35 additions and 33 deletions
|
|
@ -147,6 +147,7 @@ func (a *API) GetRepository(ctx context.Context, nwo string) (*Repository, error
|
|||
return &response, nil
|
||||
}
|
||||
|
||||
// Codespace represents a codespace.
|
||||
type Codespace struct {
|
||||
Name string `json:"name"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
|
|
@ -177,6 +178,7 @@ type CodespaceEnvironmentGitStatus struct {
|
|||
}
|
||||
|
||||
const (
|
||||
// CodespaceEnvironmentStateAvailable is the state for a running codespace environment.
|
||||
CodespaceEnvironmentStateAvailable = "Available"
|
||||
)
|
||||
|
||||
|
|
@ -421,7 +423,7 @@ type CreateCodespaceParams struct {
|
|||
// CreateCodespace creates a codespace with the given parameters and returns a non-nil error if it
|
||||
// fails to create.
|
||||
func (a *API) CreateCodespace(ctx context.Context, params *CreateCodespaceParams) (*Codespace, error) {
|
||||
cs, err := a.startCreate(ctx, params.RepositoryID, params.Machine, params.Branch, params.Location)
|
||||
codespace, err := a.startCreate(ctx, params.RepositoryID, params.Machine, params.Branch, params.Location)
|
||||
if err != errProvisioningInProgress {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -440,17 +442,17 @@ func (a *API) CreateCodespace(ctx context.Context, params *CreateCodespaceParams
|
|||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
case <-ticker.C:
|
||||
cs, err = a.GetCodespace(ctx, cs.Name, false)
|
||||
codespace, err = a.GetCodespace(ctx, codespace.Name, false)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get codespace: %w", err)
|
||||
}
|
||||
|
||||
// we continue to poll until the codespace shows as provisioned
|
||||
if cs.State != CodespaceStateProvisioned {
|
||||
if codespace.State != CodespaceStateProvisioned {
|
||||
continue
|
||||
}
|
||||
|
||||
return cs, nil
|
||||
return codespace, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -535,14 +537,14 @@ type getCodespaceRepositoryContentsResponse struct {
|
|||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
func (a *API) GetCodespaceRepositoryContents(ctx context.Context, cs *Codespace, path string) ([]byte, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, a.githubAPI+"/repos/"+cs.RepositoryNWO+"/contents/"+path, nil)
|
||||
func (a *API) GetCodespaceRepositoryContents(ctx context.Context, codespace *Codespace, path string) ([]byte, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, a.githubAPI+"/repos/"+codespace.RepositoryNWO+"/contents/"+path, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating request: %w", err)
|
||||
}
|
||||
|
||||
q := req.URL.Query()
|
||||
q.Add("ref", cs.Branch)
|
||||
q.Add("ref", codespace.Branch)
|
||||
req.URL.RawQuery = q.Encode()
|
||||
|
||||
a.setHeaders(req)
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ type logger interface {
|
|||
Println(v ...interface{}) (int, error)
|
||||
}
|
||||
|
||||
func connectionReady(cs *api.Codespace) bool {
|
||||
return cs.Environment.Connection.SessionID != "" &&
|
||||
cs.Environment.Connection.SessionToken != "" &&
|
||||
cs.Environment.Connection.RelayEndpoint != "" &&
|
||||
cs.Environment.Connection.RelaySAS != "" &&
|
||||
cs.Environment.State == api.CodespaceEnvironmentStateAvailable
|
||||
func connectionReady(codespace *api.Codespace) bool {
|
||||
return codespace.Environment.Connection.SessionID != "" &&
|
||||
codespace.Environment.Connection.SessionToken != "" &&
|
||||
codespace.Environment.Connection.RelayEndpoint != "" &&
|
||||
codespace.Environment.Connection.RelaySAS != "" &&
|
||||
codespace.Environment.State == api.CodespaceEnvironmentStateAvailable
|
||||
}
|
||||
|
||||
type apiClient interface {
|
||||
|
|
@ -30,17 +30,17 @@ type apiClient interface {
|
|||
|
||||
// ConnectToLiveshare waits for a Codespace to become running,
|
||||
// and connects to it using a Live Share session.
|
||||
func ConnectToLiveshare(ctx context.Context, log logger, apiClient apiClient, cs *api.Codespace) (*liveshare.Session, error) {
|
||||
func ConnectToLiveshare(ctx context.Context, log logger, apiClient apiClient, codespace *api.Codespace) (*liveshare.Session, error) {
|
||||
var startedCodespace bool
|
||||
if cs.Environment.State != api.CodespaceEnvironmentStateAvailable {
|
||||
if codespace.Environment.State != api.CodespaceEnvironmentStateAvailable {
|
||||
startedCodespace = true
|
||||
log.Print("Starting your codespace...")
|
||||
if err := apiClient.StartCodespace(ctx, cs.Name); err != nil {
|
||||
if err := apiClient.StartCodespace(ctx, codespace.Name); err != nil {
|
||||
return nil, fmt.Errorf("error starting codespace: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
for retries := 0; !connectionReady(cs); retries++ {
|
||||
for retries := 0; !connectionReady(codespace); retries++ {
|
||||
if retries > 1 {
|
||||
if retries%2 == 0 {
|
||||
log.Print(".")
|
||||
|
|
@ -54,7 +54,7 @@ func ConnectToLiveshare(ctx context.Context, log logger, apiClient apiClient, cs
|
|||
}
|
||||
|
||||
var err error
|
||||
cs, err = apiClient.GetCodespace(ctx, cs.Name, true)
|
||||
codespace, err = apiClient.GetCodespace(ctx, codespace.Name, true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting codespace: %w", err)
|
||||
}
|
||||
|
|
@ -67,10 +67,10 @@ func ConnectToLiveshare(ctx context.Context, log logger, apiClient apiClient, cs
|
|||
log.Println("Connecting to your codespace...")
|
||||
|
||||
return liveshare.Connect(ctx, liveshare.Options{
|
||||
SessionID: cs.Environment.Connection.SessionID,
|
||||
SessionToken: cs.Environment.Connection.SessionToken,
|
||||
RelaySAS: cs.Environment.Connection.RelaySAS,
|
||||
RelayEndpoint: cs.Environment.Connection.RelayEndpoint,
|
||||
HostPublicKeys: cs.Environment.Connection.HostPublicKeys,
|
||||
SessionID: codespace.Environment.Connection.SessionID,
|
||||
SessionToken: codespace.Environment.Connection.SessionToken,
|
||||
RelaySAS: codespace.Environment.Connection.RelaySAS,
|
||||
RelayEndpoint: codespace.Environment.Connection.RelayEndpoint,
|
||||
HostPublicKeys: codespace.Environment.Connection.HostPublicKeys,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ type PostCreateState struct {
|
|||
// PollPostCreateStates watches for state changes in a codespace,
|
||||
// and calls the supplied poller for each batch of state changes.
|
||||
// It runs until it encounters an error, including cancellation of the context.
|
||||
func PollPostCreateStates(ctx context.Context, log logger, apiClient apiClient, cs *api.Codespace, poller func([]PostCreateState)) (err error) {
|
||||
session, err := ConnectToLiveshare(ctx, log, apiClient, cs)
|
||||
func PollPostCreateStates(ctx context.Context, log logger, apiClient apiClient, codespace *api.Codespace, poller func([]PostCreateState)) (err error) {
|
||||
session, err := ConnectToLiveshare(ctx, log, apiClient, codespace)
|
||||
if err != nil {
|
||||
return fmt.Errorf("connect to Live Share: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,9 +135,9 @@ func chooseCodespaceFromList(ctx context.Context, codespaces []*api.Codespace) (
|
|||
|
||||
// getOrChooseCodespace prompts the user to choose a codespace if the codespaceName is empty.
|
||||
// It then fetches the codespace record with full connection details.
|
||||
func getOrChooseCodespace(ctx context.Context, apiClient apiClient, codespaceName string) (cs *api.Codespace, err error) {
|
||||
func getOrChooseCodespace(ctx context.Context, apiClient apiClient, codespaceName string) (codespace *api.Codespace, err error) {
|
||||
if codespaceName == "" {
|
||||
cs, err = chooseCodespace(ctx, apiClient)
|
||||
codespace, err = chooseCodespace(ctx, apiClient)
|
||||
if err != nil {
|
||||
if err == errNoCodespaces {
|
||||
return nil, err
|
||||
|
|
@ -145,13 +145,13 @@ func getOrChooseCodespace(ctx context.Context, apiClient apiClient, codespaceNam
|
|||
return nil, fmt.Errorf("choosing codespace: %w", err)
|
||||
}
|
||||
} else {
|
||||
cs, err = apiClient.GetCodespace(ctx, codespaceName, true)
|
||||
codespace, err = apiClient.GetCodespace(ctx, codespaceName, true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting full codespace details: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return cs, nil
|
||||
return codespace, nil
|
||||
}
|
||||
|
||||
func safeClose(closer io.Closer, err *error) {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ func (a *App) Create(ctx context.Context, opts createOptions) error {
|
|||
// showStatus polls the codespace for a list of post create states and their status. It will keep polling
|
||||
// until all states have finished. Once all states have finished, we poll once more to check if any new
|
||||
// states have been introduced and stop polling otherwise.
|
||||
func showStatus(ctx context.Context, log *output.Logger, apiClient apiClient, user *api.User, cs *api.Codespace) error {
|
||||
func showStatus(ctx context.Context, log *output.Logger, apiClient apiClient, user *api.User, codespace *api.Codespace) error {
|
||||
var lastState codespaces.PostCreateState
|
||||
var breakNextState bool
|
||||
|
||||
|
|
@ -156,7 +156,7 @@ func showStatus(ctx context.Context, log *output.Logger, apiClient apiClient, us
|
|||
}
|
||||
}
|
||||
|
||||
err := codespaces.PollPostCreateStates(ctx, log, apiClient, cs, poller)
|
||||
err := codespaces.PollPostCreateStates(ctx, log, apiClient, codespace, poller)
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) && breakNextState {
|
||||
return nil // we cancelled the context to stop polling, we can ignore the error
|
||||
|
|
|
|||
|
|
@ -75,12 +75,12 @@ func (a *App) Delete(ctx context.Context, opts deleteOptions) (err error) {
|
|||
nameFilter = c.Name
|
||||
}
|
||||
} else {
|
||||
cs, err := a.apiClient.GetCodespace(ctx, nameFilter, false)
|
||||
codespace, err := a.apiClient.GetCodespace(ctx, nameFilter, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error fetching codespace information: %w", err)
|
||||
}
|
||||
|
||||
codespaces = []*api.Codespace{cs}
|
||||
codespaces = []*api.Codespace{codespace}
|
||||
}
|
||||
|
||||
codespacesToDelete := make([]*api.Codespace, 0, len(codespaces))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue