diff --git a/components/dashboard/src/start/CreateWorkspace.tsx b/components/dashboard/src/start/CreateWorkspace.tsx index 27ec29eef19d0d..d38c76128f2b6b 100644 --- a/components/dashboard/src/start/CreateWorkspace.tsx +++ b/components/dashboard/src/start/CreateWorkspace.tsx @@ -207,6 +207,15 @@ export default class CreateWorkspace extends React.Component; break; + case ErrorCodes.PROJECT_REQUIRED: + statusMessage = ( +

+ + Learn more about projects + +

+ ); + break; default: statusMessage = (

diff --git a/components/gitpod-protocol/src/context-url.spec.ts b/components/gitpod-protocol/src/context-url.spec.ts index 7f31e59060a509..5549bb9dc8bdcf 100644 --- a/components/gitpod-protocol/src/context-url.spec.ts +++ b/components/gitpod-protocol/src/context-url.spec.ts @@ -41,24 +41,6 @@ export class ContextUrlTest { expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo.git"); } - @test public parseContextUrl_withPrebuild() { - const actual = ContextURL.getNormalizedURL({ - contextURL: "prebuild/https://github.com/gitpod-io/gitpod-test-repo", - context: {}, - } as WsContextUrl); - expect(actual?.host).to.equal("github.com"); - expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo"); - } - - @test public parseContextUrl_withPrebuild_withoutSchema() { - const actual = ContextURL.getNormalizedURL({ - contextURL: "prebuild/github.com/gitpod-io/gitpod-test-repo", - context: {}, - } as WsContextUrl); - expect(actual?.host).to.equal("github.com"); - expect(actual?.pathname).to.equal("/gitpod-io/gitpod-test-repo"); - } - @test public parseContextUrl_badUrl() { const actual = ContextURL.getNormalizedURL({ contextURL: "[Object object]", context: {} } as WsContextUrl); expect(actual).to.be.undefined; diff --git a/components/gitpod-protocol/src/context-url.ts b/components/gitpod-protocol/src/context-url.ts index ee75e008527880..74995651ccb884 100644 --- a/components/gitpod-protocol/src/context-url.ts +++ b/components/gitpod-protocol/src/context-url.ts @@ -15,7 +15,6 @@ import { Workspace } from "."; * TODO(gpl) See if we can get this into `server` code to remove the burden from clients */ export namespace ContextURL { - export const INCREMENTAL_PREBUILD_PREFIX = "incremental-prebuild"; export const PREBUILD_PREFIX = "prebuild"; export const IMAGEBUILD_PREFIX = "imagebuild"; export const SNAPSHOT_PREFIX = "snapshot"; @@ -91,7 +90,6 @@ export namespace ContextURL { const firstSegment = segments[0]; if ( firstSegment === PREBUILD_PREFIX || - firstSegment === INCREMENTAL_PREBUILD_PREFIX || firstSegment === IMAGEBUILD_PREFIX || firstSegment === SNAPSHOT_PREFIX || firstSegment.startsWith(REFERRER_PREFIX) diff --git a/components/gitpod-protocol/src/messaging/error.ts b/components/gitpod-protocol/src/messaging/error.ts index 9923477e599524..10376f02650686 100644 --- a/components/gitpod-protocol/src/messaging/error.ts +++ b/components/gitpod-protocol/src/messaging/error.ts @@ -35,6 +35,9 @@ export namespace ErrorCodes { // 430 Repository not whitelisted (custom status code) export const REPOSITORY_NOT_WHITELISTED = 430; + // 440 Prebuilds now always require a project (custom status code) + export const PROJECT_REQUIRED = 440; + // 450 Payment error export const PAYMENT_ERROR = 450; diff --git a/components/gitpod-protocol/src/protocol.ts b/components/gitpod-protocol/src/protocol.ts index 498ee53bcca63d..7c3fec948138f6 100644 --- a/components/gitpod-protocol/src/protocol.ts +++ b/components/gitpod-protocol/src/protocol.ts @@ -1127,7 +1127,7 @@ export interface WithCommitHistory { export interface StartPrebuildContext extends WorkspaceContext, WithCommitHistory { actual: WorkspaceContext; - project?: Project; + project: Project; branch?: string; } diff --git a/components/server/ee/src/prebuilds/prebuild-manager.ts b/components/server/ee/src/prebuilds/prebuild-manager.ts index 80a4345dd96999..167ed9f1d4a6bc 100644 --- a/components/server/ee/src/prebuilds/prebuild-manager.ts +++ b/components/server/ee/src/prebuilds/prebuild-manager.ts @@ -35,6 +35,8 @@ import { StopWorkspacePolicy } from "@gitpod/ws-manager/lib"; import { error } from "console"; import { IncrementalPrebuildsService } from "./incremental-prebuilds-service"; import { PrebuildRateLimiterConfig } from "../../../src/workspace/prebuild-rate-limiter"; +import { ResponseError } from "vscode-ws-jsonrpc"; +import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; export class WorkspaceRunningError extends Error { constructor(msg: string, public instance: WorkspaceInstance) { @@ -124,7 +126,13 @@ export class PrebuildManager { try { if (user.blocked) { - throw new Error(`Blocked users cannot start prebuilds (${user.name})`); + throw new ResponseError(ErrorCodes.USER_BLOCKED, `Blocked users cannot start prebuilds (${user.name})`); + } + if (!project) { + throw new ResponseError( + ErrorCodes.PROJECT_REQUIRED, + `Running prebuilds without a project is no longer supported. Please add '${cloneURL}' as a project in a Gitpod team.`, + ); } const existingPB = await this.findNonFailedPrebuiltWorkspace({ span }, cloneURL, commitSHAIdentifier); diff --git a/components/server/ee/src/prebuilds/start-prebuild-context-parser.ts b/components/server/ee/src/prebuilds/start-prebuild-context-parser.ts index 9594c329478307..c2317c76da1b13 100644 --- a/components/server/ee/src/prebuilds/start-prebuild-context-parser.ts +++ b/components/server/ee/src/prebuilds/start-prebuild-context-parser.ts @@ -4,8 +4,10 @@ * See License.enterprise.txt in the project root folder. */ -import { User, WorkspaceContext, StartPrebuildContext, IssueContext, ContextURL } from "@gitpod/gitpod-protocol"; +import { User, WorkspaceContext, ContextURL } from "@gitpod/gitpod-protocol"; +import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; import { injectable } from "inversify"; +import { ResponseError } from "vscode-ws-jsonrpc"; import { IPrefixContextParser } from "../../../src/workspace/context-parser"; @injectable() @@ -19,14 +21,9 @@ export class StartPrebuildContextParser implements IPrefixContextParser { } public async handle(user: User, prefix: string, context: WorkspaceContext): Promise { - if (IssueContext.is(context)) { - throw new Error("cannot start prebuilds on an issue context"); - } - - const result: StartPrebuildContext = { - title: `Prebuild of "${context.title}"`, - actual: context, - }; - return result; + throw new ResponseError( + ErrorCodes.PROJECT_REQUIRED, + `Running prebuilds without a project is no longer supported. Please add your repository as a project in a Gitpod team.`, + ); } }