Skip to content

Commit c20606b

Browse files
committed
Implement a '#/incremental-prebuild/' manual prefix
1 parent 63c67c2 commit c20606b

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

components/dashboard/src/start/StartWorkspace.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
149149

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

components/server/ee/src/container-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { GitLabApp } from "./prebuilds/gitlab-app";
3131
import { BitbucketApp } from "./prebuilds/bitbucket-app";
3232
import { IPrefixContextParser } from "../../src/workspace/context-parser";
3333
import { StartPrebuildContextParser } from "./prebuilds/start-prebuild-context-parser";
34+
import { StartIncrementalPrebuildContextParser } from "./prebuilds/start-incremental-prebuild-context-parser";
3435
import { WorkspaceFactory } from "../../src/workspace/workspace-factory";
3536
import { WorkspaceFactoryEE } from "./workspace/workspace-factory";
3637
import { MonitoringEndpointsAppEE } from "./monitoring-endpoint-ee";
@@ -52,6 +53,7 @@ export const productionEEContainerModule = new ContainerModule((bind, unbind, is
5253
bind(PrebuildRateLimiter).toSelf().inSingletonScope();
5354
bind(PrebuildQueueMaintainer).toSelf().inSingletonScope();
5455
bind(IPrefixContextParser).to(StartPrebuildContextParser).inSingletonScope();
56+
bind(IPrefixContextParser).to(StartIncrementalPrebuildContextParser).inSingletonScope();
5557
bind(GithubApp).toSelf().inSingletonScope();
5658
bind(GithubAppRules).toSelf().inSingletonScope();
5759
bind(PrebuildStatusMaintainer).toSelf().inSingletonScope();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3+
* Licensed under the Gitpod Enterprise Source Code License,
4+
* See License.enterprise.txt in the project root folder.
5+
*/
6+
7+
import { User, WorkspaceContext, StartPrebuildContext, CommitContext } from "@gitpod/gitpod-protocol";
8+
import { inject, injectable } from "inversify";
9+
import { URL } from "url";
10+
import { Env } from '../../../src/env';
11+
import { HostContextProvider } from "../../../src/auth/host-context-provider";
12+
import { IPrefixContextParser } from "../../../src/workspace/context-parser";
13+
14+
@injectable()
15+
export class StartIncrementalPrebuildContextParser implements IPrefixContextParser {
16+
@inject(Env) protected env: Env;
17+
@inject(HostContextProvider) protected readonly hostContextProvider: HostContextProvider;
18+
static PREFIX = 'incremental-prebuild/';
19+
20+
findPrefix(user: User, context: string): string | undefined {
21+
if (context.startsWith(StartIncrementalPrebuildContextParser.PREFIX)) {
22+
return StartIncrementalPrebuildContextParser.PREFIX;
23+
}
24+
}
25+
26+
public async handle(user: User, prefix: string, context: WorkspaceContext): Promise<WorkspaceContext> {
27+
if (!CommitContext.is(context)) {
28+
throw new Error("can only start incremental prebuilds on a commit context")
29+
}
30+
31+
const host = new URL(context.repository.cloneUrl).hostname;
32+
const hostContext = this.hostContextProvider.get(host);
33+
const maxDepth = this.env.incrementalPrebuildsCommitHistory;
34+
const result: StartPrebuildContext = {
35+
title: `Prebuild of "${context.title}"`,
36+
actual: context,
37+
commitHistory: await (hostContext?.contextParser?.fetchCommitHistory({}, user, context.repository.cloneUrl, context.revision, maxDepth) || [])
38+
};
39+
return result;
40+
}
41+
42+
}

0 commit comments

Comments
 (0)