-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a '#/incremental-prebuild/' manual prefix
- Loading branch information
1 parent
862e3a2
commit d1ab495
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
components/server/ee/src/prebuilds/start-incremental-prebuild-context-parser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |