|
7 | 7 | import { BlobServiceClient } from "@gitpod/content-service/lib/blobs_grpc_pb";
|
8 | 8 | import { DownloadUrlRequest, DownloadUrlResponse, UploadUrlRequest, UploadUrlResponse } from '@gitpod/content-service/lib/blobs_pb';
|
9 | 9 | import { AppInstallationDB, UserDB, UserMessageViewsDB, WorkspaceDB, DBWithTracing, TracedWorkspaceDB, DBGitpodToken, DBUser, UserStorageResourcesDB, TeamDB } from '@gitpod/gitpod-db/lib';
|
10 |
| -import { AuthProviderEntry, AuthProviderInfo, Branding, CommitContext, Configuration, CreateWorkspaceMode, DisposableCollection, GetWorkspaceTimeoutResult, GitpodClient, GitpodServer, GitpodToken, GitpodTokenType, InstallPluginsParams, PermissionName, PortVisibility, PrebuiltWorkspace, PrebuiltWorkspaceContext, PreparePluginUploadParams, ResolvedPlugins, ResolvePluginsParams, SetWorkspaceTimeoutResult, StartPrebuildContext, StartWorkspaceResult, Terms, Token, UninstallPluginParams, User, UserEnvVar, UserEnvVarValue, UserInfo, WhitelistedRepository, Workspace, WorkspaceContext, WorkspaceCreationResult, WorkspaceImageBuild, WorkspaceInfo, WorkspaceInstance, WorkspaceInstancePort, WorkspaceInstanceUser, WorkspaceTimeoutDuration, GuessGitTokenScopesParams, GuessedGitTokenScopes, Team, TeamMemberInfo, TeamMembershipInvite, CreateProjectParams, Project, ProviderRepository, PrebuildInfo, TeamMemberRole, WithDefaultConfig, FindPrebuildsParams } from '@gitpod/gitpod-protocol'; |
| 10 | +import { AuthProviderEntry, AuthProviderInfo, Branding, CommitContext, Configuration, CreateWorkspaceMode, DisposableCollection, GetWorkspaceTimeoutResult, GitpodClient, GitpodServer, GitpodToken, GitpodTokenType, InstallPluginsParams, PermissionName, PortVisibility, PrebuiltWorkspace, PrebuiltWorkspaceContext, PreparePluginUploadParams, ResolvedPlugins, ResolvePluginsParams, SetWorkspaceTimeoutResult, StartPrebuildContext, StartWorkspaceResult, Terms, Token, UninstallPluginParams, User, UserEnvVar, UserEnvVarValue, UserInfo, WhitelistedRepository, Workspace, WorkspaceContext, WorkspaceCreationResult, WorkspaceImageBuild, WorkspaceInfo, WorkspaceInstance, WorkspaceInstancePort, WorkspaceInstanceUser, WorkspaceTimeoutDuration, GuessGitTokenScopesParams, GuessedGitTokenScopes, Team, TeamMemberInfo, TeamMembershipInvite, CreateProjectParams, Project, ProviderRepository, PrebuildInfo, TeamMemberRole, WithDefaultConfig, FindPrebuildsParams, WorkspaceConfig } from '@gitpod/gitpod-protocol'; |
11 | 11 | import { AccountStatement } from "@gitpod/gitpod-protocol/lib/accounting-protocol";
|
12 | 12 | import { AdminBlockUserRequest, AdminGetListRequest, AdminGetListResult, AdminGetWorkspacesRequest, AdminModifyPermanentWorkspaceFeatureFlagRequest, AdminModifyRoleOrPermissionRequest, WorkspaceAndInstance } from '@gitpod/gitpod-protocol/lib/admin-protocol';
|
13 | 13 | import { GetLicenseInfoResult, LicenseFeature, LicenseValidationResult } from '@gitpod/gitpod-protocol/lib/license-protocol';
|
@@ -52,6 +52,7 @@ import { HeadlessLogUrls } from "@gitpod/gitpod-protocol/lib/headless-workspace-
|
52 | 52 | import { HeadlessLogService } from "./headless-log-service";
|
53 | 53 | import { InvalidGitpodYMLError } from "./config-provider";
|
54 | 54 | import { ProjectsService } from "../projects/projects-service";
|
| 55 | +import { ConfigInferrer } from "gitpod-yml-inferrer"; |
55 | 56 |
|
56 | 57 | @injectable()
|
57 | 58 | export class GitpodServerImpl<Client extends GitpodClient, Server extends GitpodServer> implements GitpodServer, Disposable {
|
@@ -1561,6 +1562,48 @@ export class GitpodServerImpl<Client extends GitpodClient, Server extends Gitpod
|
1561 | 1562 | return configString;
|
1562 | 1563 | }
|
1563 | 1564 |
|
| 1565 | + public async guessProjectConfiguration(projectId: string): Promise<string | undefined> { |
| 1566 | + const user = this.checkUser("guessProjectConfiguration"); |
| 1567 | + const span = opentracing.globalTracer().startSpan("guessProjectConfiguration"); |
| 1568 | + span.setTag("projectId", projectId); |
| 1569 | + |
| 1570 | + const project = await this.projectsService.getProject(projectId); |
| 1571 | + if (!project) { |
| 1572 | + throw new ResponseError(ErrorCodes.NOT_FOUND, "Project not found"); |
| 1573 | + } |
| 1574 | + await this.guardProjectOperation(user, projectId, "get"); |
| 1575 | + |
| 1576 | + const normalizedContextUrl = this.contextParser.normalizeContextURL(project.cloneUrl); |
| 1577 | + const context = (await this.contextParser.handle({ span }, user, normalizedContextUrl)) as CommitContext; |
| 1578 | + const { host } = context.repository; |
| 1579 | + const hostContext = this.hostContextProvider.get(host); |
| 1580 | + if (!hostContext || !hostContext.services) { |
| 1581 | + throw new Error(`Cannot fetch repository configuration for host: ${host}`); |
| 1582 | + } |
| 1583 | + const repoHost = hostContext.services; |
| 1584 | + const cache: { [path: string]: string } = {}; |
| 1585 | + const readFile = async (path: string) => { |
| 1586 | + if (path in cache) { |
| 1587 | + return cache[path]; |
| 1588 | + } |
| 1589 | + const content = await repoHost.fileProvider.getFileContent(context, user, path); |
| 1590 | + if (content) { |
| 1591 | + cache[path] = content; |
| 1592 | + } |
| 1593 | + return content; |
| 1594 | + } |
| 1595 | + const config: WorkspaceConfig = await new ConfigInferrer().getConfig({ |
| 1596 | + config: {}, |
| 1597 | + read: readFile, |
| 1598 | + exists: async (path: string) => !!(await readFile(path)), |
| 1599 | + }); |
| 1600 | + if (config.tasks) { |
| 1601 | + const configString = `tasks:\n - ${config.tasks.map(task => Object.entries(task).map(([phase, command]) => `${phase}: ${command}`).join('\n ')).join('\n - ')}`; |
| 1602 | + return configString; |
| 1603 | + } |
| 1604 | + return; |
| 1605 | + } |
| 1606 | + |
1564 | 1607 | public async getContentBlobUploadUrl(name: string): Promise<string> {
|
1565 | 1608 | const user = this.checkAndBlockUser("getContentBlobUploadUrl");
|
1566 | 1609 | await this.guardAccess({ kind: "contentBlob", name: name, userID: user.id }, "create");
|
|
0 commit comments