| 81 | } |
| 82 | |
| 83 | func (cs *CodespaceSelector) fetchCodespaces(ctx context.Context) (codespaces []*api.Codespace, err error) { |
| 84 | codespaces, err = cs.api.ListCodespaces(ctx, api.ListCodespacesOptions{}) |
| 85 | if err != nil { |
| 86 | return nil, fmt.Errorf("error getting codespaces: %w", err) |
| 87 | } |
| 88 | |
| 89 | if len(codespaces) == 0 { |
| 90 | return nil, errNoCodespaces |
| 91 | } |
| 92 | |
| 93 | // Note that repo filtering done here can also be done in api.ListCodespaces. |
| 94 | // We do it here instead so that we can differentiate no codespaces in general vs. none after filtering. |
| 95 | if cs.repoName != "" { |
| 96 | var filteredCodespaces []*api.Codespace |
| 97 | for _, c := range codespaces { |
| 98 | if !strings.EqualFold(c.Repository.FullName, cs.repoName) { |
| 99 | continue |
| 100 | } |
| 101 | |
| 102 | filteredCodespaces = append(filteredCodespaces, c) |
| 103 | } |
| 104 | |
| 105 | codespaces = filteredCodespaces |
| 106 | } |
| 107 | |
| 108 | if cs.repoOwner != "" { |
| 109 | codespaces = filterCodespacesByRepoOwner(codespaces, cs.repoOwner) |
| 110 | } |
| 111 | |
| 112 | if len(codespaces) == 0 { |
| 113 | return nil, errNoFilteredCodespaces |
| 114 | } |
| 115 | |
| 116 | return codespaces, err |
| 117 | } |
| 118 | |
| 119 | func (cs *CodespaceSelector) chooseCodespace(ctx context.Context, codespaces []*api.Codespace) (codespace *api.Codespace, err error) { |
| 120 | skipPromptForSingleOption := cs.repoName != "" |