Skip to content

Commit

Permalink
[server] remove obsolete and unused getSuggestedContextURLs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTugarev committed Nov 15, 2023
1 parent eaae6cc commit 866c80d
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 192 deletions.
3 changes: 0 additions & 3 deletions components/dashboard/src/service/service-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,6 @@ const gitpodServiceMock = createServiceMock({
getClientRegion: async () => {
return "europe-west-1";
},
getSuggestedContextURLs: async () => {
return [];
},
getIDEOptions: async () => {
return {
defaultDesktopIde: "code-desktop",
Expand Down
21 changes: 0 additions & 21 deletions components/gitpod-protocol/go/gitpod-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 0 additions & 15 deletions components/gitpod-protocol/go/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion components/gitpod-protocol/src/gitpod-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
getWorkspaceOwner(workspaceId: string): Promise<UserInfo | undefined>;
getWorkspaceUsers(workspaceId: string): Promise<WorkspaceInstanceUser[]>;
getFeaturedRepositories(): Promise<WhitelistedRepository[]>;
getSuggestedContextURLs(): Promise<string[]>;
getSuggestedRepositories(organizationId: string): Promise<SuggestedRepository[]>;
searchRepositories(params: SearchRepositoriesParams): Promise<SuggestedRepository[]>;
/**
Expand Down
23 changes: 0 additions & 23 deletions components/public-api-server/pkg/apiv1/scm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 0 additions & 15 deletions components/public-api-server/pkg/apiv1/scm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 0 additions & 1 deletion components/server/src/auth/rate-limiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
2 changes: 0 additions & 2 deletions components/server/src/oauth-server/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
],
Expand Down Expand Up @@ -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" },
],
Expand Down
111 changes: 0 additions & 111 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1398,117 +1398,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
).filter((e) => e !== undefined) as WhitelistedRepository[];
}

public async getSuggestedContextURLs(ctx: TraceContext): Promise<string[]> {
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<SuggestedRepository[]> {
traceAPIParams(ctx, { organizationId });

Expand Down

0 comments on commit 866c80d

Please sign in to comment.