Skip to content

Commit 295497f

Browse files
committed
Implement a '#/incremental-prebuild/' manual prefix
1 parent c44c8ac commit 295497f

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 { HostContextProvider } from "../../../src/auth/host-context-provider";
11+
import { IPrefixContextParser } from "../../../src/workspace/context-parser";
12+
13+
@injectable()
14+
export class StartIncrementalPrebuildContextParser implements IPrefixContextParser {
15+
@inject(HostContextProvider) protected readonly hostContextProvider: HostContextProvider;
16+
static PREFIX = 'incremental-prebuild/';
17+
18+
findPrefix(user: User, context: string): string | undefined {
19+
if (context.startsWith(StartIncrementalPrebuildContextParser.PREFIX)) {
20+
return StartIncrementalPrebuildContextParser.PREFIX;
21+
}
22+
}
23+
24+
public async handle(user: User, prefix: string, context: WorkspaceContext): Promise<WorkspaceContext> {
25+
if (!CommitContext.is(context)) {
26+
throw new Error("can only start incremental prebuilds on a commit context")
27+
}
28+
29+
const host = new URL(context.repository.cloneUrl).hostname;
30+
const hostContext = this.hostContextProvider.get(host);
31+
const result: StartPrebuildContext = {
32+
title: `Prebuild of "${context.title}"`,
33+
actual: context,
34+
commitHistory: await (hostContext?.contextParser?.fetchCommitHistory({}, user, context.repository.cloneUrl, context.revision) || [])
35+
};
36+
return result;
37+
}
38+
39+
}

0 commit comments

Comments
 (0)