diff --git a/components/dashboard/src/projects/ProjectSettings.tsx b/components/dashboard/src/projects/ProjectSettings.tsx
index 132874511d0db3..ff5a1798dd4bb6 100644
--- a/components/dashboard/src/projects/ProjectSettings.tsx
+++ b/components/dashboard/src/projects/ProjectSettings.tsx
@@ -4,12 +4,11 @@
* See License.AGPL.txt in the project root for license information.
*/
-import { Project, ProjectSettings } from "@gitpod/gitpod-protocol";
+import { PrebuildSettings, Project, ProjectSettings } from "@gitpod/gitpod-protocol";
import { useCallback, useContext, useState, Fragment, useMemo, useEffect } from "react";
import { useHistory } from "react-router";
import { CheckboxInputField } from "../components/forms/CheckboxInputField";
import { PageWithSubMenu } from "../components/PageWithSubMenu";
-import PillLabel from "../components/PillLabel";
import { getGitpodService } from "../service/service";
import { ProjectContext, useCurrentProject } from "./project-context";
import { getProjectSettingsMenu, getProjectTabs } from "./projects.routes";
@@ -63,7 +62,7 @@ export default function ProjectSettingsView() {
if (!project) {
return;
}
- setPrebuildBranchPattern(project?.settings?.prebuildBranchPattern || "");
+ setPrebuildBranchPattern(project?.settings?.prebuilds?.branchMatchingPattern || "");
}, [project]);
const setProjectName = useCallback(
@@ -105,27 +104,37 @@ export default function ProjectSettingsView() {
[project, setProject, toast, projectName],
);
+ const setPrebuildsEnabled = useCallback(
+ async (value: boolean) => {
+ if (!project) {
+ return;
+ }
+
+ await updateProjectSettings({
+ prebuilds: {
+ ...project.settings?.prebuilds,
+ enable: value,
+ },
+ });
+ },
+ [project, updateProjectSettings],
+ );
+
const setPrebuildBranchStrategy = useCallback(
- async (value: ProjectSettings.PrebuildBranchStrategy) => {
+ async (value: PrebuildSettings.BranchStrategy) => {
if (!project) {
return;
}
- const oldValue = Project.getPrebuildBranchStrategy(project);
+ const oldValue = Project.getPrebuildSettings(project).branchStrategy;
if (oldValue === value) {
return;
}
- const update: ProjectSettings = {};
- if (value === "defaultBranch") {
- update.prebuildDefaultBranchOnly = true;
- update.prebuildBranchPattern = "";
- }
- if (value === "allBranches") {
- update.prebuildDefaultBranchOnly = false;
- update.prebuildBranchPattern = "";
- }
- if (value === "selectedBranches") {
- update.prebuildDefaultBranchOnly = false;
- update.prebuildBranchPattern = "**";
+ const update: ProjectSettings = { ...project.settings };
+ update.prebuilds = { ...update.prebuilds };
+ update.prebuilds.branchStrategy = value;
+
+ if (value === "matched-branches") {
+ update.prebuilds.branchMatchingPattern = update.prebuilds.branchMatchingPattern || "**";
}
await updateProjectSettings(update);
},
@@ -133,13 +142,23 @@ export default function ProjectSettingsView() {
);
const debouncedUpdatePrebuildBranchPattern = useMemo(() => {
- return debounce(async (prebuildBranchPattern) => {
- await updateProjectSettings({ prebuildBranchPattern });
+ return debounce(async (prebuildBranchPattern: string) => {
+ if (!project) {
+ return;
+ }
+ const update: ProjectSettings = { ...project.settings };
+ update.prebuilds = { ...update.prebuilds };
+ update.prebuilds.branchMatchingPattern = prebuildBranchPattern;
+
+ await updateProjectSettings(update);
}, 1500);
- }, [updateProjectSettings]);
+ }, [updateProjectSettings, project]);
const updatePrebuildBranchPattern = useCallback(
async (value: string) => {
+ if (!value) {
+ return;
+ }
setPrebuildBranchPattern(value);
debouncedUpdatePrebuildBranchPattern(value);
@@ -162,11 +181,28 @@ export default function ProjectSettingsView() {
const setWorkspaceClassForPrebuild = useCallback(
async (value: string) => {
if (!project) {
- return value;
+ return;
}
- const before = project.settings?.workspaceClasses?.prebuild;
- updateProjectSettings({ workspaceClasses: { ...project.settings?.workspaceClasses, prebuild: value } });
- return before;
+ const update: ProjectSettings = { ...project.settings };
+ update.prebuilds = { ...update.prebuilds };
+ update.prebuilds.workspaceClass = value;
+
+ await updateProjectSettings(update);
+ },
+ [project, updateProjectSettings],
+ );
+
+ const setPrebuildInterval = useCallback(
+ async (value: string) => {
+ if (!project) {
+ return;
+ }
+ const newInterval = Math.abs(Math.min(Number.parseInt(value), 100)) || 0;
+ const update: ProjectSettings = { ...project.settings };
+ update.prebuilds = { ...update.prebuilds };
+ update.prebuilds.prebuildInterval = newInterval;
+
+ await updateProjectSettings(update);
},
[project, updateProjectSettings],
);
@@ -178,9 +214,7 @@ export default function ProjectSettingsView() {
// TODO: Render a generic error screen for when an entity isn't found
if (!project) return null;
- const enablePrebuilds = Project.isPrebuildsEnabled(project);
-
- const prebuildBranchStrategy = Project.getPrebuildBranchStrategy(project);
+ const prebuildSettings = Project.getPrebuildSettings(project);
return (
@@ -203,13 +237,12 @@ export default function ProjectSettingsView() {
label="Enable prebuilds"
hint={
- {enablePrebuilds ? (
-
- Prebuilds will run for any before
or init
tasks.
-
- ) : (
- "Requires permissions to configure repository webhooks."
- )}{" "}
+
+ Prebuilds reduce wait time for new workspaces.
+ {!prebuildSettings.enable
+ ? " Enabling requires permissions to configure repository webhooks."
+ : ""}
+ {" "}
}
- checked={enablePrebuilds}
- onChange={(checked) => updateProjectSettings({ enablePrebuilds: checked })}
+ checked={!!prebuildSettings.enable}
+ onChange={setPrebuildsEnabled}
/>
- {enablePrebuilds && (
+ {prebuildSettings.enable && (
<>
- setPrebuildBranchStrategy(val as ProjectSettings.PrebuildBranchStrategy)}
- >
-
-
-
-
- {prebuildBranchStrategy === "selectedBranches" && (
+
+
+
+
setPrebuildInterval(target.value)}
+ />
+
+ The number of commits to be skipped between prebuild runs.
+
+
+
+
+
setPrebuildBranchStrategy(val as PrebuildSettings.BranchStrategy)}
+ >
+
+
+
+
+
+ Run prebuilds on the selected branches only.
+
+
+ {prebuildSettings.branchStrategy === "matched-branches" && (