Skip to content

Commit

Permalink
Fix repo names for Bitbucket (Server) (#20264)
Browse files Browse the repository at this point in the history
* Fix repo names for Bitbucket (Server)

* remove unused project mutation

* Update tests

* Use `ContextService` again
  • Loading branch information
filiptronicek authored Oct 7, 2024
1 parent 9d42ec3 commit 42a0293
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 53 deletions.
35 changes: 0 additions & 35 deletions components/dashboard/src/data/projects/create-project-mutation.ts

This file was deleted.

2 changes: 0 additions & 2 deletions components/gitpod-protocol/src/gitpod-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,6 @@ export interface GetDefaultWorkspaceImageResult {

export interface CreateProjectParams {
name: string;
/** @deprecated unused */
slug: string;
cloneUrl: string;
teamId: string;
appInstallationId: string;
Expand Down
4 changes: 4 additions & 0 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,10 @@ export interface Repository {
* Optional date when the repository was last pushed to.
*/
pushedAt?: string;
/**
* Optional display name (e.g. for Bitbucket)
*/
displayName?: string;
}

export interface RepositoryInfo {
Expand Down
14 changes: 8 additions & 6 deletions components/server/src/api/configuration-service-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { PaginationToken, generatePaginationToken, parsePaginationToken } from "
import { ctxUserId } from "../util/request-context";
import { UserService } from "../user/user-service";
import { SortOrder } from "@gitpod/public-api/lib/gitpod/v1/sorting_pb";
import { Project } from "@gitpod/gitpod-protocol";
import { CommitContext, Project } from "@gitpod/gitpod-protocol";
import { DeepPartial } from "@gitpod/gitpod-protocol/lib/util/deep-partial";
import { ContextService } from "../workspace/context-service";

Expand Down Expand Up @@ -76,18 +76,20 @@ export class ConfigurationServiceAPI implements ServiceImpl<typeof Configuration
throw new ApplicationError(ErrorCodes.NOT_FOUND, "user not found");
}

const cloneUrl = await this.contextService.parseContextUrlAsCloneUrl(installer, req.cloneUrl);
if (!cloneUrl) {
const context = await this.contextService.parseContextUrl(installer, req.cloneUrl);
if (!CommitContext.is(context)) {
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "clone_url is not valid");
}

// The dashboard, for example, does not provide an explicit name, so we infer it
const name = req.name || (context.repository.displayName ?? context.repository.name);

const project = await this.projectService.createProject(
{
teamId: req.organizationId,
name: req.name,
cloneUrl,
name,
cloneUrl: context.repository.cloneUrl,
appInstallationId: "",
slug: "",
},
installer,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class TestBitbucketServerContextParser {
host: "bitbucket.gitpod-dev.com",
owner: "GIT",
name: "gitpod-test-repo",
displayName: "Gitpod Test Repo",
cloneUrl: "https://bitbucket.gitpod-dev.com/scm/git/gitpod-test-repo.git",
webUrl: "https://bitbucket.gitpod-dev.com/projects/GIT/repos/gitpod-test-repo",
defaultBranch: "master",
Expand Down Expand Up @@ -123,6 +124,7 @@ class TestBitbucketServerContextParser {
host: "bitbucket.gitpod-dev.com",
owner: "GIT",
name: "gitpod-test-repo",
displayName: "Gitpod Test Repo",
cloneUrl: "https://bitbucket.gitpod-dev.com/scm/git/gitpod-test-repo.git",
webUrl: "https://bitbucket.gitpod-dev.com/projects/GIT/repos/gitpod-test-repo",
defaultBranch: "master",
Expand Down Expand Up @@ -150,6 +152,7 @@ class TestBitbucketServerContextParser {
host: "bitbucket.gitpod-dev.com",
owner: "geropl",
name: "test-user-repo",
displayName: "test-user-repo",
cloneUrl: "https://bitbucket.gitpod-dev.com/scm/~geropl/test-user-repo.git",
webUrl: "https://bitbucket.gitpod-dev.com/users/geropl/repos/test-user-repo",
defaultBranch: "main",
Expand Down Expand Up @@ -177,6 +180,7 @@ class TestBitbucketServerContextParser {
defaultBranch: "main",
host: "bitbucket.gitpod-dev.com",
name: "test-user-repo",
displayName: "test-user-repo",
owner: "geropl",
private: true,
repoKind: "users",
Expand All @@ -203,6 +207,7 @@ class TestBitbucketServerContextParser {
defaultBranch: "master",
host: "bitbucket.gitpod-dev.com",
name: "gitpod-test-repo",
displayName: "Gitpod Test Repo",
owner: "GIT",
private: true,
repoKind: "projects",
Expand All @@ -229,6 +234,7 @@ class TestBitbucketServerContextParser {
defaultBranch: "master",
host: "bitbucket.gitpod-dev.com",
name: "gitpod-test-repo",
displayName: "Gitpod Test Repo",
owner: "GIT",
private: true,
repoKind: "projects",
Expand Down Expand Up @@ -256,6 +262,7 @@ class TestBitbucketServerContextParser {
defaultBranch: "main",
host: "bitbucket.gitpod-dev.com",
name: "browser-extension-test",
displayName: "browser-extension-test",
owner: "svenefftinge",
repoKind: "users",
private: false,
Expand Down Expand Up @@ -284,6 +291,7 @@ class TestBitbucketServerContextParser {
defaultBranch: "main",
host: "bitbucket.gitpod-dev.com",
name: "browser-extension-test",
displayName: "browser-extension-test",
owner: "svenefftinge",
repoKind: "users",
private: false,
Expand All @@ -310,6 +318,7 @@ class TestBitbucketServerContextParser {
host: "bitbucket.gitpod-dev.com",
owner: "GIT",
name: "gitpod-test-repo",
displayName: "Gitpod Test Repo",
cloneUrl: "https://bitbucket.gitpod-dev.com/scm/git/gitpod-test-repo.git",
webUrl: "https://bitbucket.gitpod-dev.com/projects/GIT/repos/gitpod-test-repo",
defaultBranch: "master",
Expand All @@ -323,6 +332,7 @@ class TestBitbucketServerContextParser {
host: "bitbucket.gitpod-dev.com",
owner: "GIT",
name: "gitpod-test-repo",
displayName: "Gitpod Test Repo",
cloneUrl: "https://bitbucket.gitpod-dev.com/scm/git/gitpod-test-repo.git",
webUrl: "https://bitbucket.gitpod-dev.com/projects/GIT/repos/gitpod-test-repo",
defaultBranch: "master",
Expand Down Expand Up @@ -350,6 +360,7 @@ class TestBitbucketServerContextParser {
host: "bitbucket.gitpod-dev.com",
owner: "GIT",
name: "gitpod-test-repo",
displayName: "Gitpod Test Repo",
cloneUrl: "https://bitbucket.gitpod-dev.com/scm/git/gitpod-test-repo.git",
webUrl: "https://bitbucket.gitpod-dev.com/projects/GIT/repos/gitpod-test-repo",
defaultBranch: "master",
Expand All @@ -363,6 +374,7 @@ class TestBitbucketServerContextParser {
host: "bitbucket.gitpod-dev.com",
owner: "GIT",
name: "gitpod-test-repo",
displayName: "Gitpod Test Repo",
cloneUrl: "https://bitbucket.gitpod-dev.com/scm/git/gitpod-test-repo.git",
webUrl: "https://bitbucket.gitpod-dev.com/projects/GIT/repos/gitpod-test-repo",
defaultBranch: "master",
Expand All @@ -389,6 +401,7 @@ class TestBitbucketServerContextParser {
host: "bitbucket.gitpod-dev.com",
owner: "GIT",
name: "gitpod-test-repo",
displayName: "Gitpod Test Repo",
cloneUrl: "https://bitbucket.gitpod-dev.com/scm/git/gitpod-test-repo.git",
webUrl: "https://bitbucket.gitpod-dev.com/projects/GIT/repos/gitpod-test-repo",
defaultBranch: "master",
Expand All @@ -415,6 +428,7 @@ class TestBitbucketServerContextParser {
host: "bitbucket.gitpod-dev.com",
owner: "GIT",
name: "gitpod-test-repo",
displayName: "Gitpod Test Repo",
cloneUrl: "https://bitbucket.gitpod-dev.com/scm/git/gitpod-test-repo.git",
webUrl: "https://bitbucket.gitpod-dev.com/projects/GIT/repos/gitpod-test-repo",
defaultBranch: "master",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class BitbucketServerContextParser extends AbstractContextParser implemen
defaultBranch: BitbucketServer.Branch,
): Repository {
const owner = repo.project.owner ? repo.project.owner.slug : repo.project.key;
const name = repo.name;
const name = repo.slug;
const cloneUrl = repo.links.clone.find((u) => u.name === "http")?.href!;
const webUrl = repo.links?.self[0]?.href?.replace(/\/browse$/, "");

Expand All @@ -298,6 +298,7 @@ export class BitbucketServerContextParser extends AbstractContextParser implemen
repoKind,
private: !repo.public,
defaultBranch: defaultBranch.displayId || DEFAULT_BRANCH,
displayName: repo.name,
};

return result;
Expand Down
22 changes: 22 additions & 0 deletions components/server/src/bitbucket/bitbucket-context-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -109,6 +110,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -133,6 +135,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -157,6 +160,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -181,6 +185,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -205,6 +210,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -229,6 +235,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -253,6 +260,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -277,6 +285,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -301,6 +310,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -325,6 +335,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -349,6 +360,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -373,6 +385,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -397,6 +410,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -417,6 +431,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -430,6 +445,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -452,6 +468,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "corneliusltf",
name: "sample-repository",
displayName: "Sample Repository",
cloneUrl: "https://bitbucket.org/corneliusltf/sample-repository.git",
defaultBranch: "master",
private: false,
Expand All @@ -461,6 +478,7 @@ class TestBitbucketContextParser {
defaultBranch: "master",
host: "bitbucket.org",
name: "integration-tests",
displayName: "Integration Tests",
owner: "gitpod",
private: false,
},
Expand All @@ -475,6 +493,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand All @@ -497,6 +516,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests",
displayName: "Integration Tests",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests.git",
defaultBranch: "master",
private: false,
Expand Down Expand Up @@ -525,6 +545,7 @@ class TestBitbucketContextParser {
host: "bitbucket.org",
owner: "gitpod",
name: "integration-tests-forked-repository",
displayName: "integration-tests-forked-repository",
cloneUrl: "https://bitbucket.org/gitpod/integration-tests-forked-repository.git",
defaultBranch: "master",
private: false,
Expand All @@ -534,6 +555,7 @@ class TestBitbucketContextParser {
defaultBranch: "master",
host: "bitbucket.org",
name: "my-sample-repo",
displayName: "my-sample-repo",
owner: "corneliusludmann",
private: false,
},
Expand Down
Loading

0 comments on commit 42a0293

Please sign in to comment.