55 */
66
77import { DBWithTracing , TracedWorkspaceDB , WorkspaceDB , ProjectDB , TeamDB } from '@gitpod/gitpod-db/lib' ;
8- import { AdditionalContentContext , CommitContext , IssueContext , PullRequestContext , Repository , SnapshotContext , User , Workspace , WorkspaceConfig , WorkspaceContext , WorkspaceProbeContext } from '@gitpod/gitpod-protocol' ;
8+ import { AdditionalContentContext , CommitContext , IssueContext , PrebuiltWorkspaceContext , PullRequestContext , Repository , SnapshotContext , User , Workspace , WorkspaceConfig , WorkspaceContext , WorkspaceProbeContext } from '@gitpod/gitpod-protocol' ;
99import { ErrorCodes } from '@gitpod/gitpod-protocol/lib/messaging/error' ;
1010import { generateWorkspaceID } from '@gitpod/gitpod-protocol/lib/util/generate-workspace-id' ;
1111import { log } from '@gitpod/gitpod-protocol/lib/util/logging' ;
1212import { TraceContext } from '@gitpod/gitpod-protocol/lib/util/tracing' ;
1313import { inject , injectable } from 'inversify' ;
1414import { ResponseError } from 'vscode-jsonrpc' ;
15+ import { RepoURL } from '../repohost' ;
1516import { ConfigProvider } from './config-provider' ;
1617import { ImageSourceProvider } from './image-source-provider' ;
1718
@@ -55,7 +56,7 @@ export class WorkspaceFactory {
5556 // Basically we're using the raw alpine image bait-and-switch style without adding the GP layer.
5657 const imageSource = await this . imageSourceProvider . getImageSource ( ctx , user , null as any , config ) ;
5758
58- const id = await generateWorkspaceID ( ) ;
59+ const id = await this . generateWorkspaceID ( context ) ;
5960 const date = new Date ( ) . toISOString ( ) ;
6061 const newWs : Workspace = {
6162 id,
@@ -94,7 +95,7 @@ export class WorkspaceFactory {
9495 throw new Error ( `The original workspace has been deleted - cannot open this snapshot.` ) ;
9596 }
9697
97- const id = await generateWorkspaceID ( ) ;
98+ const id = await this . generateWorkspaceID ( context ) ;
9899 const date = new Date ( ) . toISOString ( ) ;
99100 const newWs = < Workspace > {
100101 id,
@@ -166,7 +167,7 @@ export class WorkspaceFactory {
166167 }
167168 }
168169
169- const id = await generateWorkspaceID ( ) ;
170+ const id = await this . generateWorkspaceID ( context ) ;
170171 const newWs : Workspace = {
171172 id,
172173 type : "regular" ,
@@ -207,4 +208,16 @@ export class WorkspaceFactory {
207208 return context . title ;
208209 }
209210
211+ protected async generateWorkspaceID ( context : WorkspaceContext ) : Promise < string > {
212+ let ctx = context ;
213+ if ( PrebuiltWorkspaceContext . is ( context ) ) {
214+ ctx = context . originalContext ;
215+ }
216+ if ( CommitContext . is ( ctx ) ) {
217+ const parsed = RepoURL . parseRepoUrl ( ctx . repository . cloneUrl ) ;
218+ return await generateWorkspaceID ( parsed ?. owner , parsed ?. repo ) ;
219+ }
220+ return await generateWorkspaceID ( ) ;
221+ }
222+
210223}
0 commit comments