Skip to content

[server] fix Suggested Context URLs for BBS – EXP-354 #18451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,16 @@ export class BitbucketServerApi {
);
}

/**
* https://developer.atlassian.com/server/bitbucket/rest/v811/api-group-repository/#api-api-latest-repos-get
*/
async getRepos(
user: User,
query: {
permission?: "REPO_READ" | "REPO_WRITE" | "REPO_ADMIN";
/**
* defaults to 25
*/
limit: number;
},
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { inject, injectable } from "inversify";
import { RepoURL } from "../repohost";
import { RepositoryProvider } from "../repohost/repository-provider";
import { BitbucketServerApi } from "./bitbucket-server-api";
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";

@injectable()
export class BitbucketServerRepositoryProvider implements RepositoryProvider {
Expand Down Expand Up @@ -144,8 +145,19 @@ export class BitbucketServerRepositoryProvider implements RepositoryProvider {
}

async getUserRepos(user: User): Promise<string[]> {
// TODO(janx): Not implemented yet
return [];
try {
const repos = await this.api.getRepos(user, { limit: 1000, permission: "REPO_READ" });

return (repos.values || [])
.map((r) => {
const cloneUrl = r.links.clone.find((u) => u.name === "http")?.href!;
return cloneUrl;
})
.filter((u) => !!u);
} catch (error) {
log.error("BitbucketServerRepositoryProvider.getUserRepos", error);
return [];
}
}

async hasReadAccess(user: User, owner: string, repo: string): Promise<boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class BitbucketServerService extends RepositoryService {
@inject(BitbucketServerContextParser) protected contextParser: BitbucketServerContextParser;

async getRepositoriesForAutomatedPrebuilds(user: User): Promise<ProviderRepository[]> {
const repos = await this.api.getRepos(user, { limit: 100, permission: "REPO_ADMIN" });
const repos = await this.api.getRepos(user, { limit: 1000, permission: "REPO_ADMIN" });
return (repos.values || []).map((r) => {
const cloneUrl = r.links.clone.find((u) => u.name === "http")?.href!;
// const webUrl = r.links?.self[0]?.href?.replace("/browse", "");
Expand Down
33 changes: 10 additions & 23 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
);

if (!this.disposables.disposed) {
for (const projectId of projects) {
this.disposables.push(this.subscriber.listenForPrebuildUpdates(projectId, handler));
for (const project of projects) {
this.disposables.push(this.subscriber.listenForPrebuildUpdates(project.id, handler));
}
}

Expand All @@ -347,10 +347,10 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
}

// update all project this user has access to
const allProjects: string[] = [];
const allProjects: Project[] = [];
const teams = await this.organizationService.listOrganizationsByMember(this.userID, this.userID);
for (const team of teams) {
allProjects.push(...(await this.projectsService.getProjects(this.userID, team.id)).map((p) => p.id));
allProjects.push(...(await this.projectsService.getProjects(this.userID, team.id)));
}
return allProjects;
}
Expand Down Expand Up @@ -1753,26 +1753,13 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
}),
);

// User repositories (from Apps)
// Repositories of all accessible projects
promises.push(
this.getAuthProviders(ctx)
.then((authProviders) =>
Promise.all(
authProviders.map(async (p) => {
try {
const userRepos = await this.getProviderRepositoriesForUser(ctx, { provider: p.host });
userRepos.forEach((r) =>
suggestions.push({ url: r.cloneUrl.replace(/\.git$/, ""), priority: 5 }),
);
} catch (error) {
log.debug(logCtx, "Could not get user repositories from App for " + p.host, error);
}
}),
),
)
.catch((error) => {
log.error(logCtx, "Could not get auth providers", error);
}),
this.getAccessibleProjects().then((projects) => {
projects.forEach((project) =>
suggestions.push({ url: project.cloneUrl.replace(/\.git$/, ""), priority: 1 }),
);
}),
);

// User repositories (from Git hosts directly)
Expand Down