Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class PrebuildUpdatableSHA1646803519382 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<void> {
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 ''");
}
}

Expand Down
26 changes: 19 additions & 7 deletions components/server/ee/src/prebuilds/github-enterprise-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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/';
Expand Down Expand Up @@ -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;
Expand All @@ -113,21 +117,29 @@ 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 {
span.finish();
}
}

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.
*
Expand Down