6
6
7
7
import { inject , injectable } from "inversify" ;
8
8
import { DBWithTracing , ProjectDB , TeamDB , TracedWorkspaceDB , UserDB , WorkspaceDB } from "@gitpod/gitpod-db/lib" ;
9
- import { Branch , CommitContext , PrebuildWithStatus , CreateProjectParams , FindPrebuildsParams , Project , User , WorkspaceConfig } from "@gitpod/gitpod-protocol" ;
10
- import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing" ;
9
+ import { Branch , PrebuildWithStatus , CreateProjectParams , FindPrebuildsParams , Project , User } from "@gitpod/gitpod-protocol" ;
11
10
import { HostContextProvider } from "../auth/host-context-provider" ;
12
- import { FileProvider , RepoURL } from "../repohost" ;
11
+ import { RepoURL } from "../repohost" ;
13
12
import { log } from '@gitpod/gitpod-protocol/lib/util/logging' ;
14
- import { ContextParser } from "../workspace/context-parser-service" ;
15
- import { ConfigInferrer } from "./config-inferrer" ;
16
13
import { PartialProject } from "@gitpod/gitpod-protocol/src/teams-projects-protocol" ;
17
14
18
15
@injectable ( )
@@ -23,7 +20,6 @@ export class ProjectsService {
23
20
@inject ( UserDB ) protected readonly userDB : UserDB ;
24
21
@inject ( TracedWorkspaceDB ) protected readonly workspaceDb : DBWithTracing < WorkspaceDB > ;
25
22
@inject ( HostContextProvider ) protected readonly hostContextProvider : HostContextProvider ;
26
- @inject ( ContextParser ) protected contextParser : ContextParser ;
27
23
28
24
async getProject ( projectId : string ) : Promise < Project | undefined > {
29
25
return this . projectDB . findProjectById ( projectId ) ;
@@ -179,53 +175,6 @@ export class ProjectsService {
179
175
return result ;
180
176
}
181
177
182
- protected async getRepositoryFileProviderAndCommitContext ( ctx : TraceContext , user : User , cloneUrl : string ) : Promise < { fileProvider : FileProvider , commitContext : CommitContext } > {
183
- const normalizedContextUrl = this . contextParser . normalizeContextURL ( cloneUrl ) ;
184
- const commitContext = ( await this . contextParser . handle ( ctx , user , normalizedContextUrl ) ) as CommitContext ;
185
- const { host } = commitContext . repository ;
186
- const hostContext = this . hostContextProvider . get ( host ) ;
187
- if ( ! hostContext || ! hostContext . services ) {
188
- throw new Error ( `Cannot fetch repository configuration for host: ${ host } ` ) ;
189
- }
190
- const fileProvider = hostContext . services . fileProvider ;
191
- return { fileProvider, commitContext } ;
192
- }
193
-
194
- async fetchRepositoryConfiguration ( ctx : TraceContext , user : User , cloneUrl : string ) : Promise < string | undefined > {
195
- const { fileProvider, commitContext } = await this . getRepositoryFileProviderAndCommitContext ( ctx , user , cloneUrl ) ;
196
- const configString = await fileProvider . getGitpodFileContent ( commitContext , user ) ;
197
- return configString ;
198
- }
199
-
200
- // a static cache used to prefetch inferrer related files in parallel in advance
201
- private requestedPaths = new Set < string > ( ) ;
202
-
203
- async guessRepositoryConfiguration ( ctx : TraceContext , user : User , cloneUrl : string ) : Promise < string | undefined > {
204
- const { fileProvider, commitContext } = await this . getRepositoryFileProviderAndCommitContext ( ctx , user , cloneUrl ) ;
205
- const cache : { [ path : string ] : Promise < string | undefined > } = { } ;
206
- const readFile = async ( path : string ) => {
207
- if ( path in cache ) {
208
- return await cache [ path ] ;
209
- }
210
- this . requestedPaths . add ( path ) ;
211
- const content = fileProvider . getFileContent ( commitContext , user , path ) ;
212
- cache [ path ] = content ;
213
- return await content ;
214
- }
215
- // eagerly fetch for all files that the inferrer usually asks for.
216
- this . requestedPaths . forEach ( path => ! ( path in cache ) && readFile ( path ) ) ;
217
- const config : WorkspaceConfig = await new ConfigInferrer ( ) . getConfig ( {
218
- config : { } ,
219
- read : readFile ,
220
- exists : async ( path : string ) => ! ! ( await readFile ( path ) ) ,
221
- } ) ;
222
- if ( ! config . tasks ) {
223
- return ;
224
- }
225
- const configString = `tasks:\n - ${ config . tasks . map ( task => Object . entries ( task ) . map ( ( [ phase , command ] ) => `${ phase } : ${ command } ` ) . join ( '\n ' ) ) . join ( '\n - ' ) } ` ;
226
- return configString ;
227
- }
228
-
229
178
async updateProjectPartial ( partialProject : PartialProject ) : Promise < void > {
230
179
return this . projectDB . updateProject ( partialProject ) ;
231
180
}
0 commit comments