Skip to content
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

[projects] add check for createProject #5421

Merged
merged 1 commit into from
Sep 14, 2021
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
25 changes: 15 additions & 10 deletions components/dashboard/src/projects/NewProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,21 @@ export default function NewProject() {
return;
}

await getGitpodService().server.createProject({
name: repo.name,
cloneUrl: repo.cloneUrl,
account: repo.account,
provider,
...(User.is(teamOrUser) ? { userId: teamOrUser.id } : { teamId: teamOrUser.id }),
appInstallationId: String(repo.installationId),
});

history.push(`/${User.is(teamOrUser) ? 'projects' : 't/'+teamOrUser.slug}/${repo.name}/configure`);
try {
await getGitpodService().server.createProject({
name: repo.name,
cloneUrl: repo.cloneUrl,
account: repo.account,
provider,
...(User.is(teamOrUser) ? { userId: teamOrUser.id } : { teamId: teamOrUser.id }),
Copy link
Member

Choose a reason for hiding this comment

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

Had to blink twise 🙂

appInstallationId: String(repo.installationId),
});

history.push(`/${User.is(teamOrUser) ? 'projects' : 't/'+teamOrUser.slug}/${repo.name}/configure`);
} catch (error) {
const message = (error && error?.message) || "Failed to create new project."
window.alert(message);
}
}

const toSimpleName = (fullName: string) => {
Expand Down
4 changes: 4 additions & 0 deletions components/server/src/projects/projects-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export class ProjectsService {
}

async createProject({ name, cloneUrl, teamId, userId, appInstallationId }: CreateProjectParams): Promise<Project> {
const projects = await this.getProjectsByCloneUrls([cloneUrl]);
if (projects.length > 0) {
throw new Error("Project for repository already exists.");
}
const project = Project.create({
name,
cloneUrl,
Expand Down