Skip to content

Commit

Permalink
Parse context URLs when creating configurations (#19552)
Browse files Browse the repository at this point in the history
* Parse context URLs when creating configurations

* Rename `cloneUrl` to `contextUrl`

* fix on server impl

* Revert "fix on server impl"

This reverts commit e61032d.

* Revert "Rename `cloneUrl` to `contextUrl`"

This reverts commit 649ab77.
  • Loading branch information
filiptronicek authored Mar 18, 2024
1 parent 962ce3c commit f9aee7f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,9 @@ export const useCreateConfiguration = () => {
throw new Error("No org currently selected");
}

// TODO: Should we push this into the api?
// ensure a .git suffix
const normalizedCloneURL = cloneUrl.endsWith(".git") ? cloneUrl : `${cloneUrl}.git`;

const response = await configurationClient.createConfiguration({
name,
cloneUrl: normalizedCloneURL,
cloneUrl,
organizationId: org.id,
});
if (!response.configuration) {
Expand Down
10 changes: 9 additions & 1 deletion components/server/src/api/configuration-service-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { UserService } from "../user/user-service";
import { SortOrder } from "@gitpod/public-api/lib/gitpod/v1/sorting_pb";
import { Project } from "@gitpod/gitpod-protocol";
import { DeepPartial } from "@gitpod/gitpod-protocol/lib/util/deep-partial";
import { ContextService } from "../workspace/context-service";

function buildUpdateObject<T extends Record<string, any>>(obj: T): Partial<T> {
const update: Partial<T> = {};
Expand All @@ -55,6 +56,8 @@ export class ConfigurationServiceAPI implements ServiceImpl<typeof Configuration
private readonly apiConverter: PublicAPIConverter,
@inject(UserService)
private readonly userService: UserService,
@inject(ContextService)
private readonly contextService: ContextService,
) {}

async createConfiguration(
Expand All @@ -73,11 +76,16 @@ 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) {
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "clone_url is not valid");
}

const project = await this.projectService.createProject(
{
teamId: req.organizationId,
name: req.name,
cloneUrl: req.cloneUrl,
cloneUrl,
appInstallationId: "",
slug: "",
},
Expand Down
10 changes: 10 additions & 0 deletions components/server/src/workspace/context-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ export class ContextService {
}
}

public async parseContextUrlAsCloneUrl(user: User, contextUrl: string): Promise<string | undefined> {
const normalizedContextUrl = this.contextParser.normalizeContextURL(contextUrl);
const context = await this.contextParser.handle({}, user, normalizedContextUrl);
if (CommitContext.is(context)) {
return context.repository.cloneUrl;
}

return undefined;
}

public async parseContext(
user: User,
contextUrl: string,
Expand Down

0 comments on commit f9aee7f

Please sign in to comment.