Skip to content

Commit

Permalink
Implement a '#/incremental-prebuild/' manual prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jankeromnes committed May 21, 2021
1 parent 862e3a2 commit d1ab495
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/dashboard/src/start/StartWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,

// Successfully stopped and headless: the prebuild is done, let's try to use it!
if (!error && workspaceInstance.status.phase === 'stopped' && this.state.workspace?.type !== 'regular') {
const contextUrl = this.state.workspace?.contextURL.replace('prebuild/', '')!;
const contextUrl = this.state.workspace?.contextURL.replace('incremental-prebuild/', '').replace('prebuild/', '')!;
this.redirectTo(gitpodHostUrl.withContext(contextUrl).toString());
}

Expand Down
2 changes: 2 additions & 0 deletions components/server/ee/src/container-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { GitLabApp } from "./prebuilds/gitlab-app";
import { BitbucketApp } from "./prebuilds/bitbucket-app";
import { IPrefixContextParser } from "../../src/workspace/context-parser";
import { StartPrebuildContextParser } from "./prebuilds/start-prebuild-context-parser";
import { StartIncrementalPrebuildContextParser } from "./prebuilds/start-incremental-prebuild-context-parser";
import { WorkspaceFactory } from "../../src/workspace/workspace-factory";
import { WorkspaceFactoryEE } from "./workspace/workspace-factory";
import { MonitoringEndpointsAppEE } from "./monitoring-endpoint-ee";
Expand All @@ -52,6 +53,7 @@ export const productionEEContainerModule = new ContainerModule((bind, unbind, is
bind(PrebuildRateLimiter).toSelf().inSingletonScope();
bind(PrebuildQueueMaintainer).toSelf().inSingletonScope();
bind(IPrefixContextParser).to(StartPrebuildContextParser).inSingletonScope();
bind(IPrefixContextParser).to(StartIncrementalPrebuildContextParser).inSingletonScope();
bind(GithubApp).toSelf().inSingletonScope();
bind(GithubAppRules).toSelf().inSingletonScope();
bind(PrebuildStatusMaintainer).toSelf().inSingletonScope();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
* Licensed under the Gitpod Enterprise Source Code License,
* See License.enterprise.txt in the project root folder.
*/

import { User, WorkspaceContext, StartPrebuildContext, CommitContext } from "@gitpod/gitpod-protocol";
import { inject, injectable } from "inversify";
import { URL } from "url";
import { Env } from '../../../src/env';
import { HostContextProvider } from "../../../src/auth/host-context-provider";
import { IPrefixContextParser } from "../../../src/workspace/context-parser";

@injectable()
export class StartIncrementalPrebuildContextParser implements IPrefixContextParser {
@inject(Env) protected env: Env;
@inject(HostContextProvider) protected readonly hostContextProvider: HostContextProvider;
static PREFIX = 'incremental-prebuild/';

findPrefix(user: User, context: string): string | undefined {
if (context.startsWith(StartIncrementalPrebuildContextParser.PREFIX)) {
return StartIncrementalPrebuildContextParser.PREFIX;
}
}

public async handle(user: User, prefix: string, context: WorkspaceContext): Promise<WorkspaceContext> {
if (!CommitContext.is(context)) {
throw new Error("can only start incremental prebuilds on a commit context")
}

const host = new URL(context.repository.cloneUrl).hostname;
const hostContext = this.hostContextProvider.get(host);
const maxDepth = this.env.incrementalPrebuildsCommitHistory;
const result: StartPrebuildContext = {
title: `Prebuild of "${context.title}"`,
actual: context,
commitHistory: await (hostContext?.contextParser?.fetchCommitHistory({}, user, context.repository.cloneUrl, context.revision, maxDepth) || [])
};
return result;
}

}

0 comments on commit d1ab495

Please sign in to comment.