1
+ /**
2
+ * Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3
+ * Licensed under the Gitpod Enterprise Source Code License,
4
+ * See License.enterprise.txt in the project root folder.
5
+ */
6
+
7
+ import { User , WorkspaceContext , StartPrebuildContext , CommitContext } from "@gitpod/gitpod-protocol" ;
8
+ import { inject , injectable } from "inversify" ;
9
+ import { URL } from "url" ;
10
+ import { HostContextProvider } from "../../../src/auth/host-context-provider" ;
11
+ import { IPrefixContextParser } from "../../../src/workspace/context-parser" ;
12
+
13
+ @injectable ( )
14
+ export class StartIncrementalPrebuildContextParser implements IPrefixContextParser {
15
+ @inject ( HostContextProvider ) protected readonly hostContextProvider : HostContextProvider ;
16
+ static PREFIX = 'incremental-prebuild/' ;
17
+
18
+ findPrefix ( user : User , context : string ) : string | undefined {
19
+ if ( context . startsWith ( StartIncrementalPrebuildContextParser . PREFIX ) ) {
20
+ return StartIncrementalPrebuildContextParser . PREFIX ;
21
+ }
22
+ }
23
+
24
+ public async handle ( user : User , prefix : string , context : WorkspaceContext ) : Promise < WorkspaceContext > {
25
+ if ( ! CommitContext . is ( context ) ) {
26
+ throw new Error ( "can only start incremental prebuilds on a commit context" )
27
+ }
28
+
29
+ const host = new URL ( context . repository . cloneUrl ) . hostname ;
30
+ const hostContext = this . hostContextProvider . get ( host ) ;
31
+ const result : StartPrebuildContext = {
32
+ title : `Prebuild of "${ context . title } "` ,
33
+ actual : context ,
34
+ commitHistory : await ( hostContext ?. contextParser ?. fetchCommitHistory ( { } , user , context . repository . cloneUrl , context . revision ) || [ ] )
35
+ } ;
36
+ return result ;
37
+ }
38
+
39
+ }
0 commit comments