Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable running prebuilds without a project #15026

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions components/dashboard/src/start/CreateWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
phase = StartPhase.Stopped;
statusMessage = <UsageLimitReachedModal hints={this.state?.error?.data} />;
break;
case ErrorCodes.PROJECT_REQUIRED:
statusMessage = (
<p className="text-base text-gitpod-red w-96">
<a className="gp-link" href="https://www.gitpod.io/docs/configure/projects">
Learn more about projects
</a>
</p>
);
break;
default:
statusMessage = (
<p className="text-base text-gitpod-red w-96">
Expand Down
18 changes: 0 additions & 18 deletions components/gitpod-protocol/src/context-url.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions components/gitpod-protocol/src/context-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions components/gitpod-protocol/src/messaging/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ export interface WithCommitHistory {

export interface StartPrebuildContext extends WorkspaceContext, WithCommitHistory {
actual: WorkspaceContext;
project?: Project;
project: Project;
branch?: string;
}

Expand Down
10 changes: 9 additions & 1 deletion components/server/ee/src/prebuilds/prebuild-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -19,14 +21,9 @@ export class StartPrebuildContextParser implements IPrefixContextParser {
}

public async handle(user: User, prefix: string, context: WorkspaceContext): Promise<WorkspaceContext> {
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.`,
);
}
}