Skip to content

Commit 12afee9

Browse files
committed
[server][dashboard] Fix PrebuildLogs buttons (Run Prebuild, New Workspace)
1 parent 1f4f75b commit 12afee9

File tree

6 files changed

+85
-86
lines changed

6 files changed

+85
-86
lines changed

components/dashboard/src/components/PrebuildLogs.tsx

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -68,47 +68,47 @@ export default function PrebuildLogs(props: PrebuildLogsProps) {
6868
case "unknown":
6969
break;
7070

71-
// Preparing means that we haven't actually started the workspace instance just yet, but rather
72-
// are still preparing for launch. This means we're building the Docker image for the workspace.
73-
case "preparing":
74-
getGitpodService().server.watchWorkspaceImageBuildLogs(workspace!.id);
75-
break;
76-
77-
// Pending means the workspace does not yet consume resources in the cluster, but rather is looking for
78-
// some space within the cluster. If for example the cluster needs to scale up to accomodate the
79-
// workspace, the workspace will be in Pending state until that happened.
80-
case "pending":
81-
break;
82-
83-
// Creating means the workspace is currently being created. That includes downloading the images required
84-
// to run the workspace over the network. The time spent in this phase varies widely and depends on the current
85-
// network speed, image size and cache states.
86-
case "creating":
87-
break;
88-
89-
// Initializing is the phase in which the workspace is executing the appropriate workspace initializer (e.g. Git
90-
// clone or backup download). After this phase one can expect the workspace to either be Running or Failed.
91-
case "initializing":
92-
break;
93-
94-
// Running means the workspace is able to actively perform work, either by serving a user through Theia,
95-
// or as a headless workspace.
96-
case "running":
97-
break;
98-
99-
// Interrupted is an exceptional state where the container should be running but is temporarily unavailable.
100-
// When in this state, we expect it to become running or stopping anytime soon.
101-
case "interrupted":
102-
break;
103-
104-
// Stopping means that the workspace is currently shutting down. It could go to stopped every moment.
105-
case "stopping":
106-
break;
107-
108-
// Stopped means the workspace ended regularly because it was shut down.
109-
case "stopped":
110-
getGitpodService().server.watchWorkspaceImageBuildLogs(workspace!.id);
111-
break;
71+
// Preparing means that we haven't actually started the workspace instance just yet, but rather
72+
// are still preparing for launch. This means we're building the Docker image for the workspace.
73+
case "preparing":
74+
getGitpodService().server.watchWorkspaceImageBuildLogs(workspace!.id);
75+
break;
76+
77+
// Pending means the workspace does not yet consume resources in the cluster, but rather is looking for
78+
// some space within the cluster. If for example the cluster needs to scale up to accomodate the
79+
// workspace, the workspace will be in Pending state until that happened.
80+
case "pending":
81+
break;
82+
83+
// Creating means the workspace is currently being created. That includes downloading the images required
84+
// to run the workspace over the network. The time spent in this phase varies widely and depends on the current
85+
// network speed, image size and cache states.
86+
case "creating":
87+
break;
88+
89+
// Initializing is the phase in which the workspace is executing the appropriate workspace initializer (e.g. Git
90+
// clone or backup download). After this phase one can expect the workspace to either be Running or Failed.
91+
case "initializing":
92+
break;
93+
94+
// Running means the workspace is able to actively perform work, either by serving a user through Theia,
95+
// or as a headless workspace.
96+
case "running":
97+
break;
98+
99+
// Interrupted is an exceptional state where the container should be running but is temporarily unavailable.
100+
// When in this state, we expect it to become running or stopping anytime soon.
101+
case "interrupted":
102+
break;
103+
104+
// Stopping means that the workspace is currently shutting down. It could go to stopped every moment.
105+
case "stopping":
106+
break;
107+
108+
// Stopped means the workspace ended regularly because it was shut down.
109+
case "stopped":
110+
getGitpodService().server.watchWorkspaceImageBuildLogs(workspace!.id);
111+
break;
112112
}
113113
if (workspaceInstance?.status.conditions.failed) {
114114
setError(new Error(workspaceInstance.status.conditions.failed));

components/dashboard/src/projects/ConfigureProject.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,19 @@ export default function () {
170170
<div className="flex-1 h-96 rounded-xl overflow-hidden bg-gray-100 dark:bg-gray-700 flex flex-col">
171171
<div className="flex-grow flex">{startPrebuildResult
172172
? <PrebuildLogs workspaceId={startPrebuildResult.wsid} onInstanceUpdate={onInstanceUpdate} />
173-
: <div className="flex-grow flex flex-col items-center justify-center">
173+
: (!prebuildWasTriggered && <div className="flex-grow flex flex-col items-center justify-center">
174174
<img className="w-14" role="presentation" src={isDark ? PrebuildLogsEmptyDark : PrebuildLogsEmpty} />
175175
<h3 className="text-center text-lg text-gray-500 dark:text-gray-50 mt-4">No Recent Prebuild</h3>
176176
<p className="text-center text-base text-gray-500 dark:text-gray-400 mt-2 w-64">Edit the project configuration on the left to get started. <a className="gp-link" href="https://www.gitpod.io/docs/config-gitpod-file/">Learn more</a></p>
177-
</div>
177+
</div>)
178178
}</div>
179179
<div className="h-20 px-6 bg-gray-50 dark:bg-gray-800 border-t border-gray-200 dark:border-gray-600 flex space-x-2">
180180
{prebuildWasTriggered && <PrebuildInstanceStatus prebuildInstance={prebuildInstance} isDark={isDark} />}
181181
<div className="flex-grow" />
182-
<button className="secondary">New Workspace</button>
183-
<button disabled={isDetecting} onClick={buildProject}>Run Prebuild</button>
182+
{(prebuildInstance?.status.phase === "stopped" && !prebuildInstance?.status.conditions.failed)
183+
? <a className="my-auto" href={`/#${project?.cloneUrl}`}><button className="secondary">New Workspace</button></a>
184+
: <button disabled={true} className="secondary">New Workspace</button>}
185+
<button disabled={isDetecting || (prebuildWasTriggered && prebuildInstance?.status.phase !== "stopped")} onClick={buildProject}>Run Prebuild</button>
184186
</div>
185187
</div>
186188
</div>

components/dashboard/src/projects/Prebuild.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useContext, useEffect, useState } from "react";
1010
import { useLocation, useRouteMatch } from "react-router";
1111
import Header from "../components/Header";
1212
import PrebuildLogs from "../components/PrebuildLogs";
13-
import { getGitpodService } from "../service/service";
13+
import { getGitpodService, gitpodHostUrl } from "../service/service";
1414
import { TeamsContext, getCurrentTeam } from "../teams/teams-context";
1515
import { ThemeContext } from "../theme-context";
1616
import { prebuildStatusIcon, prebuildStatusLabel, PrebuildInstanceStatus } from "./Prebuilds";
@@ -97,8 +97,9 @@ export default function () {
9797
<div className="h-20 px-6 bg-gray-50 dark:bg-gray-800 border-t border-gray-200 dark:border-gray-600 flex space-x-2">
9898
{prebuildInstance && <PrebuildInstanceStatus prebuildInstance={prebuildInstance} isDark={isDark} />}
9999
<div className="flex-grow" />
100-
<button className="secondary">New Workspace</button>
101-
<button>Run Prebuild</button>
100+
{prebuildInstance?.status.phase === "stopped"
101+
? <a className="my-auto" href={gitpodHostUrl.withContext(`${prebuild?.info.changeUrl}`).toString()}><button>New Workspace</button></a>
102+
: <button disabled={true}>New Workspace</button>}
102103
</div>
103104
</div>
104105
</div>

components/dashboard/src/projects/Project.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ export default function () {
6363

6464
const branchContextMenu = (branch: Project.BranchDetails) => {
6565
const entries: ContextMenuEntry[] = [];
66-
entries.push({
67-
title: "New Workspace",
68-
onClick: () => onNewWorkspace(branch)
69-
});
7066
entries.push({
7167
title: "Rerun Prebuild",
7268
onClick: () => triggerPrebuild(branch),
@@ -109,10 +105,6 @@ export default function () {
109105
return true;
110106
}
111107

112-
const onNewWorkspace = (branch: Project.BranchDetails) => {
113-
window.location.href = gitpodHostUrl.withContext(`${branch.url}`).toString();
114-
}
115-
116108
const triggerPrebuild = (branch: Project.BranchDetails) => {
117109
if (project) {
118110
getGitpodService().server.triggerPrebuild(project.id, branch.name)

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl<GitpodClient, GitpodSer
15251525
: (await this.projectsService.getBranchDetails(user, project)).filter(b => b.isDefault));
15261526
if (branchDetails.length !== 1) {
15271527
log.debug({ userId: user.id }, 'Cannot find branch details.', { project, branchName });
1528+
throw new ResponseError(ErrorCodes.NOT_FOUND, `Could not find ${!branchName ? 'a default branch' : `branch '${branchName}'`} in repository ${project.cloneUrl}`);
15281529
}
15291530
const contextURL = branchDetails[0].url;
15301531

components/server/ee/src/workspace/workspace-factory.ts

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class WorkspaceFactoryEE extends WorkspaceFactory {
133133
{ // TODO(at) store prebuild info
134134
if (project) {
135135
// do not await
136-
this.storePrebuildInfo(ctx, project, pws, user).catch(err => {
136+
this.storePrebuildInfo(ctx, project, pws, ws, user).catch(err => {
137137
log.error(`failed to store prebuild info`, err);
138138
TraceContext.logError({span}, err);
139139
});
@@ -152,39 +152,42 @@ export class WorkspaceFactoryEE extends WorkspaceFactory {
152152
}
153153
}
154154

155-
protected async storePrebuildInfo(ctx: TraceContext, project: Project, pws: PrebuiltWorkspace, user: User) {
155+
protected async storePrebuildInfo(ctx: TraceContext, project: Project, pws: PrebuiltWorkspace, ws: Workspace, user: User) {
156156
const span = TraceContext.startSpan("storePrebuildInfo", ctx);
157157
const { userId, teamId, name: projectName, id: projectId } = project;
158158
const parsedUrl = parseRepoUrl(project.cloneUrl);
159-
if (parsedUrl) {
160-
const { owner, repo, host } = parsedUrl;
161-
const repositoryProvider = this.hostContextProvider.get(host)?.services?.repositoryProvider;
162-
if (repositoryProvider) {
163-
const commit = await repositoryProvider.getCommitInfo(user, owner, repo, pws.commit);
164-
if (commit) {
165-
await this.db.trace({span}).storePrebuildInfo({
166-
id: pws.id,
167-
buildWorkspaceId: pws.buildWorkspaceId,
168-
teamId,
169-
userId,
170-
projectName,
171-
projectId,
172-
startedAt: pws.creationTime,
173-
startedBy: "", // TODO
174-
startedByAvatar: "", // TODO
175-
cloneUrl: pws.cloneURL,
176-
branch: pws.branch || "unknown",
177-
changeAuthor: commit.author,
178-
changeAuthorAvatar: commit.authorAvatarUrl,
179-
changeDate: commit.authorDate || "",
180-
changeHash: commit.sha,
181-
changeTitle: commit.commitMessage,
182-
// changePR
183-
// changeUrl
184-
});
185-
}
186-
}
159+
if (!parsedUrl) {
160+
return;
161+
}
162+
const { owner, repo, host } = parsedUrl;
163+
const repositoryProvider = this.hostContextProvider.get(host)?.services?.repositoryProvider;
164+
if (!repositoryProvider) {
165+
return;
166+
}
167+
const commit = await repositoryProvider.getCommitInfo(user, owner, repo, pws.commit);
168+
if (!commit) {
169+
return;
187170
}
171+
await this.db.trace({span}).storePrebuildInfo({
172+
id: pws.id,
173+
buildWorkspaceId: pws.buildWorkspaceId,
174+
teamId,
175+
userId,
176+
projectName,
177+
projectId,
178+
startedAt: pws.creationTime,
179+
startedBy: "", // TODO
180+
startedByAvatar: "", // TODO
181+
cloneUrl: pws.cloneURL,
182+
branch: pws.branch || "unknown",
183+
changeAuthor: commit.author,
184+
changeAuthorAvatar: commit.authorAvatarUrl,
185+
changeDate: commit.authorDate || "",
186+
changeHash: commit.sha,
187+
changeTitle: commit.commitMessage,
188+
// changePR
189+
changeUrl: ws.contextURL,
190+
});
188191
}
189192

190193
protected async createForPrebuiltWorkspace(ctx: TraceContext, user: User, context: PrebuiltWorkspaceContext, normalizedContextURL: string): Promise<Workspace> {

0 commit comments

Comments
 (0)