From 866c80d9f8d46ae05d6fd0599b59e6d79ec04ab6 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Wed, 15 Nov 2023 09:44:22 +0000 Subject: [PATCH] [server] remove obsolete and unused `getSuggestedContextURLs` --- .../dashboard/src/service/service-mock.ts | 3 - .../gitpod-protocol/go/gitpod-service.go | 21 ---- components/gitpod-protocol/go/mock.go | 15 --- .../gitpod-protocol/src/gitpod-service.ts | 1 - components/public-api-server/pkg/apiv1/scm.go | 23 ---- .../public-api-server/pkg/apiv1/scm_test.go | 15 --- components/server/src/auth/rate-limiter.ts | 1 - components/server/src/oauth-server/db.ts | 2 - .../src/workspace/gitpod-server-impl.ts | 111 ------------------ 9 files changed, 192 deletions(-) diff --git a/components/dashboard/src/service/service-mock.ts b/components/dashboard/src/service/service-mock.ts index 398e6992b3d2e9..a0016fe9e703f3 100644 --- a/components/dashboard/src/service/service-mock.ts +++ b/components/dashboard/src/service/service-mock.ts @@ -230,9 +230,6 @@ const gitpodServiceMock = createServiceMock({ getClientRegion: async () => { return "europe-west-1"; }, - getSuggestedContextURLs: async () => { - return []; - }, getIDEOptions: async () => { return { defaultDesktopIde: "code-desktop", diff --git a/components/gitpod-protocol/go/gitpod-service.go b/components/gitpod-protocol/go/gitpod-service.go index e33b2effb86113..e29fd81de497ca 100644 --- a/components/gitpod-protocol/go/gitpod-service.go +++ b/components/gitpod-protocol/go/gitpod-service.go @@ -42,7 +42,6 @@ type APIInterface interface { GetWorkspaceOwner(ctx context.Context, workspaceID string) (res *UserInfo, err error) GetWorkspaceUsers(ctx context.Context, workspaceID string) (res []*WorkspaceInstanceUser, err error) GetFeaturedRepositories(ctx context.Context) (res []*WhitelistedRepository, err error) - GetSuggestedContextURLs(ctx context.Context) (res []*string, err error) GetWorkspace(ctx context.Context, id string) (res *WorkspaceInfo, err error) GetIDEOptions(ctx context.Context) (res *IDEOptions, err error) IsWorkspaceOwner(ctx context.Context, workspaceID string) (res bool, err error) @@ -147,8 +146,6 @@ const ( FunctionGetWorkspaceUsers FunctionName = "getWorkspaceUsers" // FunctionGetFeaturedRepositories is the name of the getFeaturedRepositories function FunctionGetFeaturedRepositories FunctionName = "getFeaturedRepositories" - // FunctionGetSuggestedContextURLs is the name of the getSuggestedContextURLs function - FunctionGetSuggestedContextURLs FunctionName = "getSuggestedContextURLs" // FunctionGetWorkspace is the name of the getWorkspace function FunctionGetWorkspace FunctionName = "getWorkspace" // FunctionGetIDEOptions is the name of the getIDEOptions function @@ -1057,24 +1054,6 @@ func (gp *APIoverJSONRPC) ClosePort(ctx context.Context, workspaceID string, por return } -// GetSuggestedContextURLs calls getSuggestedContextURLs on the server -func (gp *APIoverJSONRPC) GetSuggestedContextURLs(ctx context.Context) (res []*string, err error) { - if gp == nil { - err = errNotConnected - return - } - var _params []interface{} - - var result []*string - err = gp.C.Call(ctx, "getSuggestedContextURLs", _params, &result) - if err != nil { - return - } - res = result - - return -} - // UpdateGitStatus calls UpdateGitStatus on the server func (gp *APIoverJSONRPC) UpdateGitStatus(ctx context.Context, workspaceID string, status *WorkspaceInstanceRepoStatus) (err error) { if gp == nil { diff --git a/components/gitpod-protocol/go/mock.go b/components/gitpod-protocol/go/mock.go index dd907add3a580b..84276f8097d068 100644 --- a/components/gitpod-protocol/go/mock.go +++ b/components/gitpod-protocol/go/mock.go @@ -521,21 +521,6 @@ func (mr *MockAPIInterfaceMockRecorder) GetSnapshots(ctx, workspaceID interface{ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSnapshots", reflect.TypeOf((*MockAPIInterface)(nil).GetSnapshots), ctx, workspaceID) } -// GetSuggestedContextURLs mocks base method. -func (m *MockAPIInterface) GetSuggestedContextURLs(ctx context.Context) ([]*string, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSuggestedContextURLs", ctx) - ret0, _ := ret[0].([]*string) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetSuggestedContextURLs indicates an expected call of GetSuggestedContextURLs. -func (mr *MockAPIInterfaceMockRecorder) GetSuggestedContextURLs(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSuggestedContextURLs", reflect.TypeOf((*MockAPIInterface)(nil).GetSuggestedContextURLs), ctx) -} - // GetSupportedWorkspaceClasses mocks base method. func (m *MockAPIInterface) GetSupportedWorkspaceClasses(ctx context.Context) ([]*SupportedWorkspaceClass, error) { m.ctrl.T.Helper() diff --git a/components/gitpod-protocol/src/gitpod-service.ts b/components/gitpod-protocol/src/gitpod-service.ts index 6705b60a63f6fd..e01080b2553435 100644 --- a/components/gitpod-protocol/src/gitpod-service.ts +++ b/components/gitpod-protocol/src/gitpod-service.ts @@ -110,7 +110,6 @@ export interface GitpodServer extends JsonRpcServer, AdminServer, getWorkspaceOwner(workspaceId: string): Promise; getWorkspaceUsers(workspaceId: string): Promise; getFeaturedRepositories(): Promise; - getSuggestedContextURLs(): Promise; getSuggestedRepositories(organizationId: string): Promise; searchRepositories(params: SearchRepositoriesParams): Promise; /** diff --git a/components/public-api-server/pkg/apiv1/scm.go b/components/public-api-server/pkg/apiv1/scm.go index 2ae419fa9f20a9..e14f3b9b4cc682 100644 --- a/components/public-api-server/pkg/apiv1/scm.go +++ b/components/public-api-server/pkg/apiv1/scm.go @@ -26,26 +26,3 @@ type SCMService struct { v1connect.UnimplementedSCMServiceHandler } - -func (s *SCMService) GetSuggestedRepoURLs(ctx context.Context, req *connect.Request[v1.GetSuggestedRepoURLsRequest]) (*connect.Response[v1.GetSuggestedRepoURLsResponse], error) { - conn, err := getConnection(ctx, s.connectionPool) - if err != nil { - return nil, err - } - - reposPtrs, err := conn.GetSuggestedContextURLs(ctx) - if err != nil { - return nil, proxy.ConvertError(err) - } - - repos := make([]string, len(reposPtrs)) - for i, repoPtr := range reposPtrs { - if repoPtr != nil { - repos[i] = *repoPtr - } - } - - return connect.NewResponse(&v1.GetSuggestedRepoURLsResponse{ - Repos: repos, - }), nil -} diff --git a/components/public-api-server/pkg/apiv1/scm_test.go b/components/public-api-server/pkg/apiv1/scm_test.go index 83001b7707d979..d3001ed7ef587b 100644 --- a/components/public-api-server/pkg/apiv1/scm_test.go +++ b/components/public-api-server/pkg/apiv1/scm_test.go @@ -22,21 +22,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestSCMService_GetSuggestedRepoURLs(t *testing.T) { - t.Run("proxies request to server", func(t *testing.T) { - serverMock, client := setupSCMService(t) - - str := "" - serverMock.EXPECT().GetSuggestedContextURLs(gomock.Any()).Return([]*string{&str}, nil) - - retrieved, err := client.GetSuggestedRepoURLs(context.Background(), connect.NewRequest(&v1.GetSuggestedRepoURLsRequest{})) - require.NoError(t, err) - requireEqualProto(t, &v1.GetSuggestedRepoURLsResponse{ - Repos: []string{""}, - }, retrieved.Msg) - }) -} - func setupSCMService(t *testing.T) (*protocol.MockAPIInterface, v1connect.SCMServiceClient) { t.Helper() diff --git a/components/server/src/auth/rate-limiter.ts b/components/server/src/auth/rate-limiter.ts index b8c3898b5df208..6ced1dbe4978ef 100644 --- a/components/server/src/auth/rate-limiter.ts +++ b/components/server/src/auth/rate-limiter.ts @@ -64,7 +64,6 @@ const defaultFunctions: FunctionsConfig = { getWorkspaceOwner: { group: "default", points: 1 }, getWorkspaceUsers: { group: "default", points: 1 }, getFeaturedRepositories: { group: "default", points: 1 }, - getSuggestedContextURLs: { group: "default", points: 1 }, getSuggestedRepositories: { group: "default", points: 1 }, searchRepositories: { group: "default", points: 1 }, getWorkspace: { group: "default", points: 1 }, diff --git a/components/server/src/oauth-server/db.ts b/components/server/src/oauth-server/db.ts index 496054bbfae290..a6191d504d5dc2 100644 --- a/components/server/src/oauth-server/db.ts +++ b/components/server/src/oauth-server/db.ts @@ -64,7 +64,6 @@ const localCli: OAuthClient = { { name: "function:createWorkspace" }, { name: "function:getToken" }, { name: "function:getSupportedWorkspaceClasses" }, - { name: "function:getSuggestedContextURLs" }, { name: "function:getIDEOptions" }, { name: "resource:default" }, ], @@ -137,7 +136,6 @@ const desktopClient: OAuthClient = { { name: "function:createWorkspace" }, { name: "function:getToken" }, { name: "function:getSupportedWorkspaceClasses" }, - { name: "function:getSuggestedContextURLs" }, { name: "function:getIDEOptions" }, { name: "resource:default" }, ], diff --git a/components/server/src/workspace/gitpod-server-impl.ts b/components/server/src/workspace/gitpod-server-impl.ts index d19cdc47acf722..4ac6a1af8e1463 100644 --- a/components/server/src/workspace/gitpod-server-impl.ts +++ b/components/server/src/workspace/gitpod-server-impl.ts @@ -1398,117 +1398,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable { ).filter((e) => e !== undefined) as WhitelistedRepository[]; } - public async getSuggestedContextURLs(ctx: TraceContext): Promise { - const user = await this.checkAndBlockUser("getSuggestedContextURLs"); - const suggestions: Array<{ url: string; lastUse?: string; priority: number }> = []; - const logCtx: LogContext = { userId: user.id }; - - // Fetch all data sources in parallel for maximum speed (don't await in this scope before `Promise.allSettled(promises)` below!) - const promises = []; - - // Example repositories - promises.push( - this.getFeaturedRepositories(ctx) - .then((exampleRepos) => { - exampleRepos.forEach((r) => suggestions.push({ url: r.url, priority: 0 })); - }) - .catch((error) => { - log.error(logCtx, "Could not get example repositories", error); - }), - ); - - // Repositories of all accessible projects - promises.push( - this.getAccessibleProjects().then((projects) => { - projects.forEach((project) => - suggestions.push({ url: project.cloneUrl.replace(/\.git$/, ""), priority: 1 }), - ); - }), - ); - - // User repositories (from Git hosts directly) - promises.push( - this.getAuthProviders(ctx) - .then((authProviders) => - Promise.all( - authProviders.map(async (p) => { - try { - const hostContext = this.hostContextProvider.get(p.host); - const services = hostContext?.services; - if (!services) { - log.error(logCtx, "Unsupported repository host: " + p.host); - return; - } - const userRepos = await services.repositoryProvider.getUserRepos(user); - userRepos.forEach((r) => - suggestions.push({ url: r.url.replace(/\.git$/, ""), priority: 5 }), - ); - } catch (error) { - log.debug(logCtx, "Could not get user repositories from host " + p.host, error); - } - }), - ), - ) - .catch((error) => { - log.error(logCtx, "Could not get auth providers", error); - }), - ); - - // Recent repositories - promises.push( - this.getWorkspaces(ctx, { - /* limit: 20 */ - }) - .then((workspaces) => { - workspaces.forEach((ws) => { - let repoUrl; - if (CommitContext.is(ws.workspace.context)) { - repoUrl = ws.workspace.context?.repository?.cloneUrl?.replace(/\.git$/, ""); - } - if (!repoUrl) { - repoUrl = ws.workspace.contextURL; - } - if (repoUrl) { - const lastUse = WorkspaceInfo.lastActiveISODate(ws); - suggestions.push({ url: repoUrl, lastUse, priority: 10 }); - } - }); - }) - .catch((error) => { - log.error(logCtx, "Could not fetch recent workspace repositories", error); - }), - ); - - await Promise.allSettled(promises); - - const uniqueURLs = new Set(); - return suggestions - .sort((a, b) => { - // priority first - if (a.priority !== b.priority) { - return a.priority < b.priority ? 1 : -1; - } - // Most recently used second - if (b.lastUse || a.lastUse) { - const la = a.lastUse || ""; - const lb = b.lastUse || ""; - return la < lb ? 1 : la === lb ? 0 : -1; - } - // Otherwise, alphasort - const ua = a.url.toLowerCase(); - const ub = b.url.toLowerCase(); - return ua > ub ? 1 : ua === ub ? 0 : -1; - }) - .filter((s) => { - if (uniqueURLs.has(s.url)) { - return false; - } - uniqueURLs.add(s.url); - return true; - }) - .map((s) => s.url); - } - public async getSuggestedRepositories(ctx: TraceContext, organizationId: string): Promise { traceAPIParams(ctx, { organizationId });