Skip to content

Commit 17b6b38

Browse files
author
Laurie T. Malau
committed
Introduce project slug
Fixes #5847
1 parent a4a1719 commit 17b6b38

File tree

8 files changed

+52
-5
lines changed

8 files changed

+52
-5
lines changed

components/dashboard/src/projects/NewProject.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export default function NewProject() {
170170
try {
171171
await getGitpodService().server.createProject({
172172
name: repo.name,
173+
slug: (repo.path ? repo.path : repo.name),
173174
cloneUrl: repo.cloneUrl,
174175
account: repo.account,
175176
provider,
@@ -255,6 +256,7 @@ export default function NewProject() {
255256
)}
256257
</div>
257258
<div className="p-6 flex-col">
259+
{console.log(filteredRepos)}
258260
{filteredRepos.length > 0 && (
259261
<div className="overscroll-contain max-h-80 overflow-y-auto pr-2">
260262
{filteredRepos.map((r, index) => (

components/dashboard/src/projects/Projects.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,24 @@ export default function () {
8383
return moment(lastPrebuilds.get(p1.id)?.info?.startedAt || '1970-01-01').diff(moment(lastPrebuilds.get(p0.id)?.info?.startedAt || '1970-01-01'));
8484
}
8585

86-
const teamOrUserSlug = !!team ? 't/'+team.slug : 'projects';
86+
function renderProjectLink(project: Project): React.ReactElement {
87+
let slug = '';
88+
const name = project.name;
89+
90+
if (project.slug) {
91+
slug = project.slug;
92+
} else {
93+
// For existing projects that don't have a slug yet
94+
slug = name.replace(/ /g, "-");
95+
}
96+
97+
return (
98+
<Link to={`/${teamOrUserSlug}/${slug}`}>
99+
<span className="text-xl font-semibold">{name}</span>
100+
</Link>)
101+
}
102+
103+
const teamOrUserSlug = !!team ? 't/' + team.slug : 'projects';
87104

88105
return <>
89106
<Header title="Projects" subtitle="Manage recently added projects." />
@@ -119,9 +136,7 @@ export default function () {
119136
<div className="h-42 border border-gray-100 dark:border-gray-800 rounded-t-xl">
120137
<div className="h-32 p-6">
121138
<div className="flex text-gray-700 dark:text-gray-200 font-medium">
122-
<Link to={`/${teamOrUserSlug}/${p.name}`}>
123-
<span className="text-xl font-semibold">{p.name}</span>
124-
</Link>
139+
{renderProjectLink(p)}
125140
<span className="flex-grow" />
126141
<div className="justify-end">
127142
<ContextMenu menuEntries={[

components/gitpod-db/src/typeorm/entity/db-project.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export class DBProject {
1818
@Column()
1919
name: string;
2020

21+
@Column()
22+
slug?: string;
23+
2124
@Column()
2225
cloneUrl: string;
2326

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import {MigrationInterface, QueryRunner} from "typeorm";
8+
import { columnExists } from "./helper/helper";
9+
10+
export class AddSlugToProject1634894637934 implements MigrationInterface {
11+
12+
public async up(queryRunner: QueryRunner): Promise<any> {
13+
if (!(await columnExists(queryRunner, "d_b_project", "slug"))) {
14+
await queryRunner.query("ALTER TABLE d_b_project ADD COLUMN `slug` varchar(255) NULL");
15+
}
16+
}
17+
18+
public async down(queryRunner: QueryRunner): Promise<any> {
19+
}
20+
21+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
234234

235235
export interface CreateProjectParams {
236236
name: string;
237+
slug?: string;
237238
account: string;
238239
provider: string;
239240
cloneUrl: string;
@@ -255,6 +256,7 @@ export interface GetProviderRepositoriesParams {
255256
}
256257
export interface ProviderRepository {
257258
name: string;
259+
path?: string;
258260
account: string;
259261
accountAvatarUrl: string;
260262
cloneUrl: string;

components/gitpod-protocol/src/teams-projects-protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface ProjectConfig {
1414
export interface Project {
1515
id: string;
1616
name: string;
17+
slug?: string;
1718
cloneUrl: string;
1819
teamId?: string;
1920
userId?: string;

components/server/ee/src/gitlab/gitlab-app-support.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class GitLabAppSupport {
3737
const projectsWithAccess = await api.Projects.all({ min_access_level: "40", perPage: 100 });
3838
for (const project of projectsWithAccess) {
3939
const anyProject = project as any;
40+
const path = anyProject.path as string;
4041
const fullPath = anyProject.path_with_namespace as string;
4142
const cloneUrl = anyProject.http_url_to_repo as string;
4243
const updatedAt = anyProject.last_activity_at as string;
@@ -45,6 +46,7 @@ export class GitLabAppSupport {
4546

4647
(account === usersGitLabAccount ? ownersRepos : result).push({
4748
name: project.name,
49+
path,
4850
account,
4951
cloneUrl,
5052
updatedAt,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@ export class ProjectsService {
9090
return result;
9191
}
9292

93-
async createProject({ name, cloneUrl, teamId, userId, appInstallationId }: CreateProjectParams): Promise<Project> {
93+
async createProject({ name, slug, cloneUrl, teamId, userId, appInstallationId }: CreateProjectParams): Promise<Project> {
9494
const projects = await this.getProjectsByCloneUrls([cloneUrl]);
9595
if (projects.length > 0) {
9696
throw new Error("Project for repository already exists.");
9797
}
9898
const project = Project.create({
9999
name,
100+
slug,
100101
cloneUrl,
101102
...(!!userId ? { userId } : { teamId }),
102103
appInstallationId

0 commit comments

Comments
 (0)