From 14c6487b7609894ab6d1ccc507f2fe7a0ffe02b0 Mon Sep 17 00:00:00 2001 From: Sven Efftinge Date: Thu, 10 Mar 2022 11:31:54 +0000 Subject: [PATCH] [server] fix compile error --- .../1646803519382-PrebuildUpdatableSHA.ts | 2 +- .../ee/src/prebuilds/github-enterprise-app.ts | 26 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/components/gitpod-db/src/typeorm/migration/1646803519382-PrebuildUpdatableSHA.ts b/components/gitpod-db/src/typeorm/migration/1646803519382-PrebuildUpdatableSHA.ts index 0739c264b72610..cfa98cfbd02239 100644 --- a/components/gitpod-db/src/typeorm/migration/1646803519382-PrebuildUpdatableSHA.ts +++ b/components/gitpod-db/src/typeorm/migration/1646803519382-PrebuildUpdatableSHA.ts @@ -11,7 +11,7 @@ export class PrebuildUpdatableSHA1646803519382 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { if (!(await columnExists(queryRunner, "d_b_prebuilt_workspace_updatable", "commitSHA"))) { - await queryRunner.query("ALTER TABLE d_b_prebuilt_workspace_updatable ADD COLUMN commitSHA varchar(255) NOT NULL"); + await queryRunner.query("ALTER TABLE d_b_prebuilt_workspace_updatable ADD COLUMN commitSHA varchar(255) NOT NULL DEFAULT ''"); } } diff --git a/components/server/ee/src/prebuilds/github-enterprise-app.ts b/components/server/ee/src/prebuilds/github-enterprise-app.ts index 684a0772e9666b..3815035caabc29 100644 --- a/components/server/ee/src/prebuilds/github-enterprise-app.ts +++ b/components/server/ee/src/prebuilds/github-enterprise-app.ts @@ -13,9 +13,11 @@ import { TraceContext } from '@gitpod/gitpod-protocol/lib/util/tracing'; import { TokenService } from '../../../src/user/token-service'; import { HostContextProvider } from '../../../src/auth/host-context-provider'; import { log } from '@gitpod/gitpod-protocol/lib/util/logging'; -import { Project, StartPrebuildResult, User } from '@gitpod/gitpod-protocol'; +import { CommitContext, CommitInfo, Project, StartPrebuildResult, User } from '@gitpod/gitpod-protocol'; import { GitHubService } from './github-service'; import { URL } from 'url'; +import { ContextParser } from '../../../src/workspace/context-parser-service'; +import { RepoURL } from '../../../src/repohost'; @injectable() export class GitHubEnterpriseApp { @@ -26,6 +28,7 @@ export class GitHubEnterpriseApp { @inject(HostContextProvider) protected readonly hostContextProvider: HostContextProvider; @inject(ProjectDB) protected readonly projectDB: ProjectDB; @inject(TeamDB) protected readonly teamDB: TeamDB; + @inject(ContextParser) protected readonly contextParser: ContextParser; protected _router = express.Router(); public static path = '/apps/ghe/'; @@ -103,7 +106,8 @@ export class GitHubEnterpriseApp { try { const contextURL = this.createContextUrl(payload); span.setTag('contextURL', contextURL); - const config = await this.prebuildManager.fetchConfig({ span }, user, contextURL); + const context = await this.contextParser.handle({ span }, user, contextURL) as CommitContext; + const config = await this.prebuildManager.fetchConfig({ span }, user, context); if (!this.prebuildManager.shouldPrebuild(config)) { log.info('GitHub Enterprise push event: No config. No prebuild.'); return undefined; @@ -113,14 +117,12 @@ export class GitHubEnterpriseApp { const cloneURL = payload.repository.clone_url; const projectAndOwner = await this.findProjectAndOwner(cloneURL, user); - + const commitInfo = await this.getCommitInfo(user, payload.repository.url, payload.after); const ws = await this.prebuildManager.startPrebuild({ span }, { + context, user: projectAndOwner.user, project: projectAndOwner?.project, - branch: this.getBranchFromRef(payload.ref), - contextURL, - cloneURL, - commit: payload.after, + commitInfo }); return ws; } finally { @@ -128,6 +130,16 @@ export class GitHubEnterpriseApp { } } + private async getCommitInfo(user: User, repoURL: string, commitSHA: string) { + const parsedRepo = RepoURL.parseRepoUrl(repoURL)!; + const hostCtx = this.hostContextProvider.get(parsedRepo.host); + let commitInfo: CommitInfo | undefined; + if (hostCtx?.services?.repositoryProvider) { + commitInfo = await hostCtx?.services?.repositoryProvider.getCommitInfo(user, parsedRepo.owner, parsedRepo.repo, commitSHA); + } + return commitInfo; + } + /** * Finds the relevant user account and project to the provided webhook event information. *