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

Method showStatus

pkg/cmd/codespace/create.go:457–516  ·  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

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

Callers 1

CreateMethod · 0.95

Calls 4

StopProgressIndicatorMethod · 0.95
PollPostCreateStatesFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected