Skip to content

[new-workspace] Fix recent repositories for BBS – EXP-411 #18497

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 3 commits into from
Aug 14, 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
14 changes: 0 additions & 14 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,20 +855,6 @@ export type WorkspaceSoftDeletion = "user" | "gc";
export type WorkspaceType = "regular" | "prebuild";

export namespace Workspace {
export function getFullRepositoryName(ws: Workspace): string | undefined {
if (CommitContext.is(ws.context)) {
return ws.context.repository.owner + "/" + ws.context.repository.name;
}
return undefined;
}

export function getFullRepositoryUrl(ws: Workspace): string | undefined {
if (CommitContext.is(ws.context)) {
return `https://${ws.context.repository.host}/${getFullRepositoryName(ws)}`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just bogus. For BBS there is no symmetry between owner+repo and the repository URL. Instead one need to know if it's a personal or a project repository.

}
return undefined;
}

export function getPullRequestNumber(ws: Workspace): number | undefined {
if (PullRequestContext.is(ws.context)) {
return ws.context.nr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ class TestBitbucketServerRepositoryProvider {
author: "Alex Tugarev",
});
}

@test async test_getUserRepos_ok() {
const result = await this.service.getUserRepos(this.user);
expect(result).to.contain(
"https://7990-alextugarev-bbs-6v0gqcpgvj7.ws-eu102.gitpod.io/scm/~alex.tugarev/user.repo.git",
);
}
}

module.exports = new TestBitbucketServerRepositoryProvider();
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ export class BitbucketServerRepositoryProvider implements RepositoryProvider {
async getUserRepos(user: User): Promise<string[]> {
try {
const repos = await this.api.getRepos(user, { limit: 1000, permission: "REPO_READ" });
const result: string[] = [];
(repos.values || []).forEach((r) => {
const cloneUrl = r.links.clone.find((u) => u.name === "http")?.href;
if (cloneUrl) {
result.push(cloneUrl.replace("http://", "https://"));
}
});

return (repos.values || [])
.map((r) => {
const cloneUrl = r.links.clone.find((u) => u.name === "http")?.href!;
return cloneUrl;
})
.filter((u) => !!u);
return result;
} catch (error) {
log.error("BitbucketServerRepositoryProvider.getUserRepos", error);
return [];
Expand Down
8 changes: 7 additions & 1 deletion components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,13 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
})
.then((workspaces) => {
workspaces.forEach((ws) => {
const repoUrl = Workspace.getFullRepositoryUrl(ws.workspace);
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 });
Expand Down