Skip to content

Commit e99800d

Browse files
authored
[server] fix Suggested Context URLs for BBS (#18451)
* add repositories of all accessible projects * remove user repositories from Apps (wrong permission query) * implement `getUserRepos` for BBS
1 parent d6ccb0d commit e99800d

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

components/server/src/bitbucket-server/bitbucket-server-api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,16 @@ export class BitbucketServerApi {
279279
);
280280
}
281281

282+
/**
283+
* https://developer.atlassian.com/server/bitbucket/rest/v811/api-group-repository/#api-api-latest-repos-get
284+
*/
282285
async getRepos(
283286
user: User,
284287
query: {
285288
permission?: "REPO_READ" | "REPO_WRITE" | "REPO_ADMIN";
289+
/**
290+
* defaults to 25
291+
*/
286292
limit: number;
287293
},
288294
) {

components/server/src/bitbucket-server/bitbucket-server-repository-provider.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { inject, injectable } from "inversify";
99
import { RepoURL } from "../repohost";
1010
import { RepositoryProvider } from "../repohost/repository-provider";
1111
import { BitbucketServerApi } from "./bitbucket-server-api";
12+
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
1213

1314
@injectable()
1415
export class BitbucketServerRepositoryProvider implements RepositoryProvider {
@@ -144,8 +145,19 @@ export class BitbucketServerRepositoryProvider implements RepositoryProvider {
144145
}
145146

146147
async getUserRepos(user: User): Promise<string[]> {
147-
// TODO(janx): Not implemented yet
148-
return [];
148+
try {
149+
const repos = await this.api.getRepos(user, { limit: 1000, permission: "REPO_READ" });
150+
151+
return (repos.values || [])
152+
.map((r) => {
153+
const cloneUrl = r.links.clone.find((u) => u.name === "http")?.href!;
154+
return cloneUrl;
155+
})
156+
.filter((u) => !!u);
157+
} catch (error) {
158+
log.error("BitbucketServerRepositoryProvider.getUserRepos", error);
159+
return [];
160+
}
149161
}
150162

151163
async hasReadAccess(user: User, owner: string, repo: string): Promise<boolean> {

components/server/src/prebuilds/bitbucket-server-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class BitbucketServerService extends RepositoryService {
2525
@inject(BitbucketServerContextParser) protected contextParser: BitbucketServerContextParser;
2626

2727
async getRepositoriesForAutomatedPrebuilds(user: User): Promise<ProviderRepository[]> {
28-
const repos = await this.api.getRepos(user, { limit: 100, permission: "REPO_ADMIN" });
28+
const repos = await this.api.getRepos(user, { limit: 1000, permission: "REPO_ADMIN" });
2929
return (repos.values || []).map((r) => {
3030
const cloneUrl = r.links.clone.find((u) => u.name === "http")?.href!;
3131
// const webUrl = r.links?.self[0]?.href?.replace("/browse", "");

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

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
333333
);
334334

335335
if (!this.disposables.disposed) {
336-
for (const projectId of projects) {
337-
this.disposables.push(this.subscriber.listenForPrebuildUpdates(projectId, handler));
336+
for (const project of projects) {
337+
this.disposables.push(this.subscriber.listenForPrebuildUpdates(project.id, handler));
338338
}
339339
}
340340

@@ -347,10 +347,10 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
347347
}
348348

349349
// update all project this user has access to
350-
const allProjects: string[] = [];
350+
const allProjects: Project[] = [];
351351
const teams = await this.organizationService.listOrganizationsByMember(this.userID, this.userID);
352352
for (const team of teams) {
353-
allProjects.push(...(await this.projectsService.getProjects(this.userID, team.id)).map((p) => p.id));
353+
allProjects.push(...(await this.projectsService.getProjects(this.userID, team.id)));
354354
}
355355
return allProjects;
356356
}
@@ -1753,26 +1753,13 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
17531753
}),
17541754
);
17551755

1756-
// User repositories (from Apps)
1756+
// Repositories of all accessible projects
17571757
promises.push(
1758-
this.getAuthProviders(ctx)
1759-
.then((authProviders) =>
1760-
Promise.all(
1761-
authProviders.map(async (p) => {
1762-
try {
1763-
const userRepos = await this.getProviderRepositoriesForUser(ctx, { provider: p.host });
1764-
userRepos.forEach((r) =>
1765-
suggestions.push({ url: r.cloneUrl.replace(/\.git$/, ""), priority: 5 }),
1766-
);
1767-
} catch (error) {
1768-
log.debug(logCtx, "Could not get user repositories from App for " + p.host, error);
1769-
}
1770-
}),
1771-
),
1772-
)
1773-
.catch((error) => {
1774-
log.error(logCtx, "Could not get auth providers", error);
1775-
}),
1758+
this.getAccessibleProjects().then((projects) => {
1759+
projects.forEach((project) =>
1760+
suggestions.push({ url: project.cloneUrl.replace(/\.git$/, ""), priority: 1 }),
1761+
);
1762+
}),
17761763
);
17771764

17781765
// User repositories (from Git hosts directly)

0 commit comments

Comments
 (0)