diff --git a/internal/codespaces/api/api.go b/internal/codespaces/api/api.go index cdf9b3f60..65c52c85b 100644 --- a/internal/codespaces/api/api.go +++ b/internal/codespaces/api/api.go @@ -179,16 +179,16 @@ type CodespaceEnvironmentConnection struct { HostPublicKeys []string `json:"hostPublicKeys"` } -func (a *API) ListCodespaces(ctx context.Context, user string) ([]*Codespace, error) { +func (a *API) ListCodespaces(ctx context.Context) ([]*Codespace, error) { req, err := http.NewRequest( - http.MethodGet, a.githubAPI+"/vscs_internal/user/"+user+"/codespaces", nil, + http.MethodGet, a.githubAPI+"/user/codespaces", nil, ) if err != nil { return nil, fmt.Errorf("error creating request: %w", err) } a.setHeaders(req) - resp, err := a.do(ctx, req, "/vscs_internal/user/*/codespaces") + resp, err := a.do(ctx, req, "/user/codespaces") if err != nil { return nil, fmt.Errorf("error making request: %w", err) } diff --git a/internal/codespaces/api/api_test.go b/internal/codespaces/api/api_test.go index 6fb162030..8bbe1c8a9 100644 --- a/internal/codespaces/api/api_test.go +++ b/internal/codespaces/api/api_test.go @@ -34,7 +34,7 @@ func TestListCodespaces(t *testing.T) { token: "faketoken", } ctx := context.TODO() - codespaces, err := api.ListCodespaces(ctx, "testuser") + codespaces, err := api.ListCodespaces(ctx) if err != nil { t.Fatal(err) } diff --git a/pkg/cmd/codespace/code.go b/pkg/cmd/codespace/code.go index cfcd989e2..0448d8b9f 100644 --- a/pkg/cmd/codespace/code.go +++ b/pkg/cmd/codespace/code.go @@ -32,13 +32,8 @@ func newCodeCmd(app *App) *cobra.Command { // VSCode opens a codespace in the local VS VSCode application. func (a *App) VSCode(ctx context.Context, codespaceName string, useInsiders bool) error { - user, err := a.apiClient.GetUser(ctx) - if err != nil { - return fmt.Errorf("error getting user: %w", err) - } - if codespaceName == "" { - codespace, err := chooseCodespace(ctx, a.apiClient, user) + codespace, err := chooseCodespace(ctx, a.apiClient) if err != nil { if err == errNoCodespaces { return err diff --git a/pkg/cmd/codespace/common.go b/pkg/cmd/codespace/common.go index da40c2b86..ecce47b2a 100644 --- a/pkg/cmd/codespace/common.go +++ b/pkg/cmd/codespace/common.go @@ -35,7 +35,7 @@ type apiClient interface { GetUser(ctx context.Context) (*api.User, error) GetCodespaceToken(ctx context.Context, user, name string) (string, error) GetCodespace(ctx context.Context, token, user, name string) (*api.Codespace, error) - ListCodespaces(ctx context.Context, user string) ([]*api.Codespace, error) + ListCodespaces(ctx context.Context) ([]*api.Codespace, error) DeleteCodespace(ctx context.Context, user, name string) error StartCodespace(ctx context.Context, token string, codespace *api.Codespace) error CreateCodespace(ctx context.Context, params *api.CreateCodespaceParams) (*api.Codespace, error) @@ -48,8 +48,8 @@ type apiClient interface { var errNoCodespaces = errors.New("you have no codespaces") -func chooseCodespace(ctx context.Context, apiClient apiClient, user *api.User) (*api.Codespace, error) { - codespaces, err := apiClient.ListCodespaces(ctx, user.Login) +func chooseCodespace(ctx context.Context, apiClient apiClient) (*api.Codespace, error) { + codespaces, err := apiClient.ListCodespaces(ctx) if err != nil { return nil, fmt.Errorf("error getting codespaces: %w", err) } @@ -99,7 +99,7 @@ func chooseCodespaceFromList(ctx context.Context, codespaces []*api.Codespace) ( // It then fetches the codespace token and the codespace record. func getOrChooseCodespace(ctx context.Context, apiClient apiClient, user *api.User, codespaceName string) (codespace *api.Codespace, token string, err error) { if codespaceName == "" { - codespace, err = chooseCodespace(ctx, apiClient, user) + codespace, err = chooseCodespace(ctx, apiClient) if err != nil { if err == errNoCodespaces { return nil, "", err diff --git a/pkg/cmd/codespace/delete.go b/pkg/cmd/codespace/delete.go index c0292f357..8ea821dc9 100644 --- a/pkg/cmd/codespace/delete.go +++ b/pkg/cmd/codespace/delete.go @@ -67,7 +67,7 @@ func (a *App) Delete(ctx context.Context, opts deleteOptions) error { var codespaces []*api.Codespace nameFilter := opts.codespaceName if nameFilter == "" { - codespaces, err = a.apiClient.ListCodespaces(ctx, user.Login) + codespaces, err = a.apiClient.ListCodespaces(ctx) if err != nil { return fmt.Errorf("error getting codespaces: %w", err) } diff --git a/pkg/cmd/codespace/delete_test.go b/pkg/cmd/codespace/delete_test.go index 35e37fae8..bf16f82f0 100644 --- a/pkg/cmd/codespace/delete_test.go +++ b/pkg/cmd/codespace/delete_test.go @@ -167,10 +167,7 @@ func TestDelete(t *testing.T) { }, } if tt.opts.codespaceName == "" { - apiMock.ListCodespacesFunc = func(_ context.Context, userLogin string) ([]*api.Codespace, error) { - if userLogin != user.Login { - return nil, fmt.Errorf("unexpected user %q", userLogin) - } + apiMock.ListCodespacesFunc = func(_ context.Context) ([]*api.Codespace, error) { return tt.codespaces, nil } } else { diff --git a/pkg/cmd/codespace/list.go b/pkg/cmd/codespace/list.go index 1f87f1ba1..a6a4b9a1b 100644 --- a/pkg/cmd/codespace/list.go +++ b/pkg/cmd/codespace/list.go @@ -28,12 +28,7 @@ func newListCmd(app *App) *cobra.Command { } func (a *App) List(ctx context.Context, asJSON bool) error { - user, err := a.apiClient.GetUser(ctx) - if err != nil { - return fmt.Errorf("error getting user: %w", err) - } - - codespaces, err := a.apiClient.ListCodespaces(ctx, user.Login) + codespaces, err := a.apiClient.ListCodespaces(ctx) if err != nil { return fmt.Errorf("error getting codespaces: %w", err) } diff --git a/pkg/cmd/codespace/mock_api.go b/pkg/cmd/codespace/mock_api.go index 268a6552e..669083a32 100644 --- a/pkg/cmd/codespace/mock_api.go +++ b/pkg/cmd/codespace/mock_api.go @@ -46,7 +46,7 @@ import ( // GetUserFunc: func(ctx context.Context) (*api.User, error) { // panic("mock out the GetUser method") // }, -// ListCodespacesFunc: func(ctx context.Context, user string) ([]*api.Codespace, error) { +// ListCodespacesFunc: func(ctx context.Context) ([]*api.Codespace, error) { // panic("mock out the ListCodespaces method") // }, // StartCodespaceFunc: func(ctx context.Context, token string, codespace *api.Codespace) error { @@ -90,7 +90,7 @@ type apiClientMock struct { GetUserFunc func(ctx context.Context) (*api.User, error) // ListCodespacesFunc mocks the ListCodespaces method. - ListCodespacesFunc func(ctx context.Context, user string) ([]*api.Codespace, error) + ListCodespacesFunc func(ctx context.Context) ([]*api.Codespace, error) // StartCodespaceFunc mocks the StartCodespace method. StartCodespaceFunc func(ctx context.Context, token string, codespace *api.Codespace) error @@ -183,8 +183,6 @@ type apiClientMock struct { ListCodespaces []struct { // Ctx is the ctx argument value. Ctx context.Context - // User is the user argument value. - User string } // StartCodespace holds details about calls to the StartCodespace method. StartCodespace []struct { @@ -585,33 +583,29 @@ func (mock *apiClientMock) GetUserCalls() []struct { } // ListCodespaces calls ListCodespacesFunc. -func (mock *apiClientMock) ListCodespaces(ctx context.Context, user string) ([]*api.Codespace, error) { +func (mock *apiClientMock) ListCodespaces(ctx context.Context) ([]*api.Codespace, error) { if mock.ListCodespacesFunc == nil { panic("apiClientMock.ListCodespacesFunc: method is nil but apiClient.ListCodespaces was just called") } callInfo := struct { - Ctx context.Context - User string + Ctx context.Context }{ - Ctx: ctx, - User: user, + Ctx: ctx, } mock.lockListCodespaces.Lock() mock.calls.ListCodespaces = append(mock.calls.ListCodespaces, callInfo) mock.lockListCodespaces.Unlock() - return mock.ListCodespacesFunc(ctx, user) + return mock.ListCodespacesFunc(ctx) } // ListCodespacesCalls gets all the calls that were made to ListCodespaces. // Check the length with: // len(mockedapiClient.ListCodespacesCalls()) func (mock *apiClientMock) ListCodespacesCalls() []struct { - Ctx context.Context - User string + Ctx context.Context } { var calls []struct { - Ctx context.Context - User string + Ctx context.Context } mock.lockListCodespaces.RLock() calls = mock.calls.ListCodespaces