5
5
*/
6
6
7
7
import { 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' ;
9
9
import { ErrorCodes } from '@gitpod/gitpod-protocol/lib/messaging/error' ;
10
10
import { generateWorkspaceID } from '@gitpod/gitpod-protocol/lib/util/generate-workspace-id' ;
11
11
import { log } from '@gitpod/gitpod-protocol/lib/util/logging' ;
12
12
import { TraceContext } from '@gitpod/gitpod-protocol/lib/util/tracing' ;
13
13
import { inject , injectable } from 'inversify' ;
14
14
import { ResponseError } from 'vscode-jsonrpc' ;
15
+ import { RepoURL } from '../repohost' ;
15
16
import { ConfigProvider } from './config-provider' ;
16
17
import { ImageSourceProvider } from './image-source-provider' ;
17
18
@@ -55,7 +56,7 @@ export class WorkspaceFactory {
55
56
// Basically we're using the raw alpine image bait-and-switch style without adding the GP layer.
56
57
const imageSource = await this . imageSourceProvider . getImageSource ( ctx , user , null as any , config ) ;
57
58
58
- const id = await generateWorkspaceID ( ) ;
59
+ const id = await this . generateWorkspaceID ( context ) ;
59
60
const date = new Date ( ) . toISOString ( ) ;
60
61
const newWs : Workspace = {
61
62
id,
@@ -94,7 +95,7 @@ export class WorkspaceFactory {
94
95
throw new Error ( `The original workspace has been deleted - cannot open this snapshot.` ) ;
95
96
}
96
97
97
- const id = await generateWorkspaceID ( ) ;
98
+ const id = await this . generateWorkspaceID ( context ) ;
98
99
const date = new Date ( ) . toISOString ( ) ;
99
100
const newWs = < Workspace > {
100
101
id,
@@ -169,7 +170,7 @@ export class WorkspaceFactory {
169
170
}
170
171
}
171
172
172
- const id = await generateWorkspaceID ( ) ;
173
+ const id = await this . generateWorkspaceID ( context ) ;
173
174
const newWs : Workspace = {
174
175
id,
175
176
type : "regular" ,
@@ -210,4 +211,16 @@ export class WorkspaceFactory {
210
211
return context . title ;
211
212
}
212
213
214
+ protected async generateWorkspaceID ( context : WorkspaceContext ) : Promise < string > {
215
+ let ctx = context ;
216
+ if ( PrebuiltWorkspaceContext . is ( context ) ) {
217
+ ctx = context . originalContext ;
218
+ }
219
+ if ( CommitContext . is ( ctx ) ) {
220
+ const parsed = RepoURL . parseRepoUrl ( ctx . repository . cloneUrl ) ;
221
+ return await generateWorkspaceID ( parsed ?. owner , parsed ?. repo ) ;
222
+ }
223
+ return await generateWorkspaceID ( ) ;
224
+ }
225
+
213
226
}
0 commit comments