Skip to content

Commit dcfc8ae

Browse files
committed
Fix repo names for Bitbucket (Server)
1 parent ca933cb commit dcfc8ae

File tree

11 files changed

+21
-20
lines changed

11 files changed

+21
-20
lines changed

components/gitpod-protocol/src/gitpod-service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,6 @@ export interface GetDefaultWorkspaceImageResult {
311311

312312
export interface CreateProjectParams {
313313
name: string;
314-
/** @deprecated unused */
315-
slug: string;
316314
cloneUrl: string;
317315
teamId: string;
318316
appInstallationId: string;

components/gitpod-protocol/src/protocol.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,10 @@ export interface Repository {
12861286
* Optional date when the repository was last pushed to.
12871287
*/
12881288
pushedAt?: string;
1289+
/**
1290+
* Optional display name (e.g. for Bitbucket)
1291+
*/
1292+
displayName?: string;
12891293
}
12901294

12911295
export interface RepositoryInfo {

components/server/src/api/configuration-service-api.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import { PaginationToken, generatePaginationToken, parsePaginationToken } from "
2727
import { ctxUserId } from "../util/request-context";
2828
import { UserService } from "../user/user-service";
2929
import { SortOrder } from "@gitpod/public-api/lib/gitpod/v1/sorting_pb";
30-
import { Project } from "@gitpod/gitpod-protocol";
30+
import { CommitContext, Project } from "@gitpod/gitpod-protocol";
3131
import { DeepPartial } from "@gitpod/gitpod-protocol/lib/util/deep-partial";
32-
import { ContextService } from "../workspace/context-service";
32+
import { ContextParser } from "../workspace/context-parser-service";
3333

3434
function buildUpdateObject<T extends Record<string, any>>(obj: T): Partial<T> {
3535
const update: Partial<T> = {};
@@ -56,8 +56,8 @@ export class ConfigurationServiceAPI implements ServiceImpl<typeof Configuration
5656
private readonly apiConverter: PublicAPIConverter,
5757
@inject(UserService)
5858
private readonly userService: UserService,
59-
@inject(ContextService)
60-
private readonly contextService: ContextService,
59+
@inject(ContextParser)
60+
private readonly contextParser: ContextParser,
6161
) {}
6262

6363
async createConfiguration(
@@ -76,18 +76,20 @@ export class ConfigurationServiceAPI implements ServiceImpl<typeof Configuration
7676
throw new ApplicationError(ErrorCodes.NOT_FOUND, "user not found");
7777
}
7878

79-
const cloneUrl = await this.contextService.parseContextUrlAsCloneUrl(installer, req.cloneUrl);
80-
if (!cloneUrl) {
79+
const context = await this.contextParser.handle({}, installer, req.cloneUrl);
80+
if (!CommitContext.is(context)) {
8181
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "clone_url is not valid");
8282
}
8383

84+
// The dashboard, for example, does not provide an explicit name, so we infer it
85+
const name = req.name || (context.repository.displayName ?? context.repository.name);
86+
8487
const project = await this.projectService.createProject(
8588
{
8689
teamId: req.organizationId,
87-
name: req.name,
88-
cloneUrl,
90+
name,
91+
cloneUrl: context.repository.cloneUrl,
8992
appInstallationId: "",
90-
slug: "",
9193
},
9294
installer,
9395
);

components/server/src/bitbucket-server/bitbucket-server-context-parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export class BitbucketServerContextParser extends AbstractContextParser implemen
285285
defaultBranch: BitbucketServer.Branch,
286286
): Repository {
287287
const owner = repo.project.owner ? repo.project.owner.slug : repo.project.key;
288-
const name = repo.name;
288+
const name = repo.slug;
289289
const cloneUrl = repo.links.clone.find((u) => u.name === "http")?.href!;
290290
const webUrl = repo.links?.self[0]?.href?.replace(/\/browse$/, "");
291291

@@ -298,6 +298,7 @@ export class BitbucketServerContextParser extends AbstractContextParser implemen
298298
repoKind,
299299
private: !repo.public,
300300
defaultBranch: defaultBranch.displayId || DEFAULT_BRANCH,
301+
displayName: repo.name,
301302
};
302303

303304
return result;

components/server/src/bitbucket/bitbucket-context-parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ export class BitbucketContextParser extends AbstractContextParser implements ICo
328328
owner,
329329
private: !!repo.isPrivate,
330330
defaultBranch: repo.mainbranch ? repo.mainbranch.name : DEFAULT_BRANCH,
331+
displayName: repo.name,
331332
};
332333
if (!!repo.parent && !!repo.parent.full_name) {
333334
const api = await this.api(user);

components/server/src/projects/projects-service.spec.db.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ describe("ProjectsService", async () => {
319319
let project = await ps.createProject(
320320
{
321321
name: partial.name!,
322-
slug: "deprecated",
323322
teamId: org.id,
324323
cloneUrl: partial.cloneUrl!,
325324
appInstallationId: "noid",

components/server/src/projects/projects-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class ProjectsService {
224224
}
225225

226226
async createProject(
227-
{ name, slug, cloneUrl, teamId, appInstallationId }: CreateProjectParams,
227+
{ name, cloneUrl, teamId, appInstallationId }: CreateProjectParams,
228228
installer: User,
229229
projectSettingsDefaults: ProjectSettings = { prebuilds: Project.PREBUILD_SETTINGS_DEFAULTS },
230230
): Promise<Project> {
@@ -257,14 +257,14 @@ export class ProjectsService {
257257
if (!hostContext || !hostContext.services) {
258258
throw new ApplicationError(
259259
ErrorCodes.BAD_REQUEST,
260-
"No GIT provider has been configured for the provided repository.",
260+
"No Git provider has been configured for the provided repository.",
261261
);
262262
}
263263
const repoProvider = hostContext.services.repositoryProvider;
264264
if (!repoProvider) {
265265
throw new ApplicationError(
266266
ErrorCodes.BAD_REQUEST,
267-
"No GIT provider has been configured for the provided repository.",
267+
"No Git provider has been configured for the provided repository.",
268268
);
269269
}
270270
const canRead = await repoProvider.hasReadAccess(installer, parsedUrl.owner, parsedUrl.repo);

components/server/src/user/env-var-service.spec.db.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ describe("EnvVarService", async () => {
121121
project = await projectsService.createProject(
122122
{
123123
name: "my-project",
124-
slug: "my-project",
125124
teamId: org.id,
126125
cloneUrl: "https://github.com/gitpod-io/gitpod.git",
127126
appInstallationId: "noid",

components/server/src/workspace/context-service.spec.db.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ describe("ContextService", async () => {
198198
project = await projectService.createProject(
199199
{
200200
name: "my-project",
201-
slug: "my-project",
202201
teamId: org.id,
203202
cloneUrl: "https://github.com/gitpod-io/empty",
204203
appInstallationId: "noid",

components/server/src/workspace/workspace-factory.spec.db.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ describe("WorkspaceFactory", async () => {
110110
project = await projectService.createProject(
111111
{
112112
name: "my-project",
113-
slug: "my-project",
114113
teamId: org.id,
115114
cloneUrl: "https://github.com/gitpod-io/gitpod",
116115
appInstallationId: "noid",

0 commit comments

Comments
 (0)