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 { Env } from '../../../src/env' ;
11
+ import { HostContextProvider } from "../../../src/auth/host-context-provider" ;
12
+ import { IPrefixContextParser } from "../../../src/workspace/context-parser" ;
13
+
14
+ @injectable ( )
15
+ export class StartIncrementalPrebuildContextParser implements IPrefixContextParser {
16
+ @inject ( Env ) protected env : Env ;
17
+ @inject ( HostContextProvider ) protected readonly hostContextProvider : HostContextProvider ;
18
+ static PREFIX = 'incremental-prebuild/' ;
19
+
20
+ findPrefix ( user : User , context : string ) : string | undefined {
21
+ if ( context . startsWith ( StartIncrementalPrebuildContextParser . PREFIX ) ) {
22
+ return StartIncrementalPrebuildContextParser . PREFIX ;
23
+ }
24
+ }
25
+
26
+ public async handle ( user : User , prefix : string , context : WorkspaceContext ) : Promise < WorkspaceContext > {
27
+ if ( ! CommitContext . is ( context ) ) {
28
+ throw new Error ( "can only start incremental prebuilds on a commit context" )
29
+ }
30
+
31
+ const host = new URL ( context . repository . cloneUrl ) . hostname ;
32
+ const hostContext = this . hostContextProvider . get ( host ) ;
33
+ const maxDepth = this . env . incrementalPrebuildsCommitHistory ;
34
+ const result : StartPrebuildContext = {
35
+ title : `Prebuild of "${ context . title } "` ,
36
+ actual : context ,
37
+ commitHistory : await ( hostContext ?. contextParser ?. fetchCommitHistory ( { } , user , context . repository . cloneUrl , context . revision , maxDepth ) || [ ] )
38
+ } ;
39
+ return result ;
40
+ }
41
+
42
+ }
0 commit comments