Skip to content

Commit dddd7b0

Browse files
svenefftingeroboquat
authored andcommitted
[server] Add priorization to repo URLs
added priorization to suggested repo URLs, so that new users get their own repositories suggested before the generic templates
1 parent e2df77f commit dddd7b0

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
12561256

12571257
public async getSuggestedContextURLs(ctx: TraceContext): Promise<string[]> {
12581258
const user = this.checkAndBlockUser("getSuggestedContextURLs");
1259-
const suggestions: Array<{ url: string; lastUse?: string }> = [];
1259+
const suggestions: Array<{ url: string; lastUse?: string; priority: number }> = [];
12601260
const logCtx: LogContext = { userId: user.id };
12611261

12621262
// Fetch all data sources in parallel for maximum speed (don't await in this scope before `Promise.allSettled(promises)` below!)
@@ -1266,7 +1266,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
12661266
promises.push(
12671267
this.getFeaturedRepositories(ctx)
12681268
.then((exampleRepos) => {
1269-
exampleRepos.forEach((r) => suggestions.push({ url: r.url }));
1269+
exampleRepos.forEach((r) => suggestions.push({ url: r.url, priority: 0 }));
12701270
})
12711271
.catch((error) => {
12721272
log.error(logCtx, "Could not get example repositories", error);
@@ -1281,7 +1281,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
12811281
authProviders.map(async (p) => {
12821282
try {
12831283
const userRepos = await this.getProviderRepositoriesForUser(ctx, { provider: p.host });
1284-
userRepos.forEach((r) => suggestions.push({ url: r.cloneUrl.replace(/\.git$/, "") }));
1284+
userRepos.forEach((r) =>
1285+
suggestions.push({ url: r.cloneUrl.replace(/\.git$/, ""), priority: 5 }),
1286+
);
12851287
} catch (error) {
12861288
log.debug(logCtx, "Could not get user repositories from App for " + p.host, error);
12871289
}
@@ -1307,7 +1309,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
13071309
return;
13081310
}
13091311
const userRepos = await services.repositoryProvider.getUserRepos(user);
1310-
userRepos.forEach((r) => suggestions.push({ url: r.replace(/\.git$/, "") }));
1312+
userRepos.forEach((r) =>
1313+
suggestions.push({ url: r.replace(/\.git$/, ""), priority: 5 }),
1314+
);
13111315
} catch (error) {
13121316
log.debug(logCtx, "Could not get user repositories from host " + p.host, error);
13131317
}
@@ -1329,7 +1333,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
13291333
const repoUrl = Workspace.getFullRepositoryUrl(ws.workspace);
13301334
if (repoUrl) {
13311335
const lastUse = WorkspaceInfo.lastActiveISODate(ws);
1332-
suggestions.push({ url: repoUrl, lastUse });
1336+
suggestions.push({ url: repoUrl, lastUse, priority: 10 });
13331337
}
13341338
});
13351339
})
@@ -1343,7 +1347,11 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
13431347
const uniqueURLs = new Set();
13441348
return suggestions
13451349
.sort((a, b) => {
1346-
// Most recently used first
1350+
// priority first
1351+
if (a.priority !== b.priority) {
1352+
return a.priority < b.priority ? 1 : -1;
1353+
}
1354+
// Most recently used second
13471355
if (b.lastUse || a.lastUse) {
13481356
const la = a.lastUse || "";
13491357
const lb = b.lastUse || "";

0 commit comments

Comments
 (0)