MCPcopy Create free account
hub / github.com/cli/cli / showStatus

Method showStatus

pkg/cmd/codespace/create.go:458–517  ·  view source on GitHub ↗

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.

(ctx context.Context, codespace *api.Codespace)

Source from the content-addressed store, hash-verified

456// until all states have finished. Once all states have finished, we poll once more to check if any new
457// states have been introduced and stop polling otherwise.
458func (a *App) showStatus(ctx context.Context, codespace *api.Codespace) error {
459 var (
460 lastState codespaces.PostCreateState
461 breakNextState bool
462 )
463
464 finishedStates := make(map[string]bool)
465 ctx, stopPolling := context.WithCancel(ctx)
466 defer stopPolling()
467
468 poller := func(states []codespaces.PostCreateState) {
469 var inProgress bool
470 for _, state := range states {
471 if _, found := finishedStates[state.Name]; found {
472 continue // skip this state as we've processed it already
473 }
474
475 if state.Name != lastState.Name {
476 a.StartProgressIndicatorWithLabel(state.Name)
477
478 if state.Status == codespaces.PostCreateStateRunning {
479 inProgress = true
480 lastState = state
481 break
482 }
483
484 finishedStates[state.Name] = true
485 a.StopProgressIndicator()
486 } else {
487 if state.Status == codespaces.PostCreateStateRunning {
488 inProgress = true
489 break
490 }
491
492 finishedStates[state.Name] = true
493 a.StopProgressIndicator()
494 lastState = codespaces.PostCreateState{} // reset the value
495 }
496 }
497
498 if !inProgress {
499 if breakNextState {
500 stopPolling()
501 return
502 }
503 breakNextState = true
504 }
505 }
506
507 err := codespaces.PollPostCreateStates(ctx, a, a.apiClient, codespace, poller)
508 if err != nil {
509 if errors.Is(err, context.Canceled) && breakNextState {
510 return nil // we cancelled the context to stop polling, we can ignore the error
511 }
512
513 return fmt.Errorf("failed to poll state changes from codespace: %w", err)
514 }
515

Callers 1

CreateMethod · 0.95

Calls 4

StopProgressIndicatorMethod · 0.95
PollPostCreateStatesFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected