Skip to content

Commit

Permalink
EVG-19805: Periodic build interval can be specified with cron express…
Browse files Browse the repository at this point in the history
…ion (#1849)
  • Loading branch information
sophstad committed May 31, 2023
1 parent 9179c83 commit fde47fb
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 36 deletions.
2 changes: 2 additions & 0 deletions src/gql/fragments/projectSettings/periodicBuilds.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ fragment ProjectPeriodicBuildsSettings on Project {
periodicBuilds {
alias
configFile
cron
id
intervalHours
message
Expand All @@ -13,6 +14,7 @@ fragment RepoPeriodicBuildsSettings on RepoRef {
periodicBuilds {
alias
configFile
cron
id
intervalHours
message
Expand Down
11 changes: 11 additions & 0 deletions src/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3122,6 +3122,7 @@ export type ProjectSettingsFieldsFragment = {
__typename?: "PeriodicBuild";
alias: string;
configFile: string;
cron: string;
id: string;
intervalHours: number;
message: string;
Expand Down Expand Up @@ -3309,6 +3310,7 @@ export type RepoSettingsFieldsFragment = {
__typename?: "PeriodicBuild";
alias: string;
configFile: string;
cron: string;
id: string;
intervalHours: number;
message: string;
Expand Down Expand Up @@ -3540,6 +3542,7 @@ export type ProjectPeriodicBuildsSettingsFragment = {
__typename?: "PeriodicBuild";
alias: string;
configFile: string;
cron: string;
id: string;
intervalHours: number;
message: string;
Expand All @@ -3553,6 +3556,7 @@ export type RepoPeriodicBuildsSettingsFragment = {
__typename?: "PeriodicBuild";
alias: string;
configFile: string;
cron: string;
id: string;
intervalHours: number;
message: string;
Expand Down Expand Up @@ -3689,6 +3693,7 @@ export type ProjectEventSettingsFragment = {
__typename?: "PeriodicBuild";
alias: string;
configFile: string;
cron: string;
id: string;
intervalHours: number;
message: string;
Expand Down Expand Up @@ -5828,6 +5833,7 @@ export type ProjectEventLogsQuery = {
__typename?: "PeriodicBuild";
alias: string;
configFile: string;
cron: string;
id: string;
intervalHours: number;
message: string;
Expand Down Expand Up @@ -6022,6 +6028,7 @@ export type ProjectEventLogsQuery = {
__typename?: "PeriodicBuild";
alias: string;
configFile: string;
cron: string;
id: string;
intervalHours: number;
message: string;
Expand Down Expand Up @@ -6231,6 +6238,7 @@ export type ProjectSettingsQuery = {
__typename?: "PeriodicBuild";
alias: string;
configFile: string;
cron: string;
id: string;
intervalHours: number;
message: string;
Expand Down Expand Up @@ -6464,6 +6472,7 @@ export type RepoEventLogsQuery = {
__typename?: "PeriodicBuild";
alias: string;
configFile: string;
cron: string;
id: string;
intervalHours: number;
message: string;
Expand Down Expand Up @@ -6658,6 +6667,7 @@ export type RepoEventLogsQuery = {
__typename?: "PeriodicBuild";
alias: string;
configFile: string;
cron: string;
id: string;
intervalHours: number;
message: string;
Expand Down Expand Up @@ -6858,6 +6868,7 @@ export type RepoSettingsQuery = {
__typename?: "PeriodicBuild";
alias: string;
configFile: string;
cron: string;
id: string;
intervalHours: number;
message: string;
Expand Down
70 changes: 61 additions & 9 deletions src/pages/projectSettings/tabs/PeriodicBuildsTab/getFormSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import widgets from "components/SpruceForm/Widgets";
import { timeZones } from "constants/fieldMaps";
import { GetFormSchema } from "../types";
import { form, ProjectType } from "../utils";
import { IntervalSpecifier } from "./types";

const { overrideRadioBox } = form;

Expand All @@ -26,11 +27,58 @@ export const getFormSchema = (
items: {
type: "object" as "object",
properties: {
intervalHours: {
type: "number" as "number",
title: "Interval",
minimum: 1,
default: 24,
interval: {
type: "object" as "object",
title: "Interval Specifier",
properties: {
specifier: {
type: "string" as "string",
title: "",
default: IntervalSpecifier.Hours,
oneOf: [
{
type: "string" as "string",
title: "Hours",
enum: [IntervalSpecifier.Hours],
},
{
type: "string" as "string",
title: "Cron",
enum: [IntervalSpecifier.Cron],
},
],
},
},
dependencies: {
specifier: {
oneOf: [
{
properties: {
specifier: {
enum: [IntervalSpecifier.Hours],
},
intervalHours: {
type: "number" as "number",
title: "Interval",
minimum: 1,
default: 24,
},
},
},
{
properties: {
specifier: {
enum: [IntervalSpecifier.Cron],
},
cron: {
type: "string" as "string",
title: "Cron Expression",
},
},
},
],
},
},
},
configFile: {
type: "string" as "string",
Expand Down Expand Up @@ -71,7 +119,6 @@ export const getFormSchema = (
default: new Date().toString(),
},
},
required: ["intervalHours"],
},
}
),
Expand All @@ -91,9 +138,14 @@ export const getFormSchema = (
"ui:useExpandableCard": true,
items: {
"ui:displayTitle": "New Periodic Build",
intervalHours: {
"ui:data-cy": "interval-input",
"ui:description": "Number of hours between runs.",
interval: {
specifier: {
"ui:widget": widgets.SegmentedControlWidget,
},
intervalHours: {
"ui:data-cy": "interval-input",
"ui:description": "Number of hours between runs.",
},
},
configFile: {
"ui:data-cy": "config-file-input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ProjectSettingsInput, RepoSettingsInput } from "gql/generated/types";
import { data } from "../testData";
import { ProjectType } from "../utils";
import { formToGql, gqlToForm } from "./transformers";
import { FormState } from "./types";
import { FormState, IntervalSpecifier } from "./types";

const { projectBase, repoBase } = data;

Expand Down Expand Up @@ -49,7 +49,11 @@ const repoForm: FormState = {
alias: "",
configFile: "evergreen.yml",
id: "123",
intervalHours: 24,
interval: {
specifier: IntervalSpecifier.Hours,
intervalHours: 24,
cron: "",
},
message: "",
nextRunTime:
"Wed Mar 30 2022 17:07:10 GMT+0000 (Coordinated Universal Time)",
Expand All @@ -59,7 +63,11 @@ const repoForm: FormState = {
alias: "test",
configFile: "evergreen.yml",
id: "456",
intervalHours: 12,
interval: {
specifier: IntervalSpecifier.Cron,
intervalHours: null,
cron: "*/5 * * * *",
},
message: "Build Message",
nextRunTime:
"Wed Mar 30 2022 17:07:10 GMT+0000 (Coordinated Universal Time)",
Expand All @@ -75,6 +83,7 @@ const repoResult: Pick<RepoSettingsInput, "projectRef"> = {
{
alias: "",
configFile: "evergreen.yml",
cron: "",
id: "123",
intervalHours: 24,
message: "",
Expand All @@ -83,8 +92,9 @@ const repoResult: Pick<RepoSettingsInput, "projectRef"> = {
{
alias: "test",
configFile: "evergreen.yml",
cron: "*/5 * * * *",
id: "456",
intervalHours: 12,
intervalHours: 0,
message: "Build Message",
nextRunTime: new Date("2022-03-30T17:07:10.000Z"),
},
Expand Down
73 changes: 52 additions & 21 deletions src/pages/projectSettings/tabs/PeriodicBuildsTab/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@ import {
ProjectSettingsQuery,
RepoSettingsQuery,
} from "gql/generated/types";
import { string } from "utils";
import { FormToGqlFunction, GqlToFormFunction } from "../types";
import { ProjectType } from "../utils";
import { FormState } from "./types";

const { omitTypename } = string;
import { FormState, IntervalSpecifier } from "./types";

type Tab = ProjectSettingsTabRoutes.PeriodicBuilds;

const getTitle = (
definition: Pick<PeriodicBuild, "message" | "intervalHours">
definition: Pick<PeriodicBuild, "cron" | "intervalHours" | "message">
) => {
if (!definition) {
return "";
}
if (definition.message) {
return definition.message;
const { cron, intervalHours, message } = definition;
if (message) {
return message;
}
return `Every ${definition.intervalHours} hours`;
return intervalHours ? `Every ${intervalHours} hours` : cron;
};

export const gqlToForm: GqlToFormFunction<Tab> = (
Expand All @@ -41,11 +39,34 @@ export const gqlToForm: GqlToFormFunction<Tab> = (
periodicBuildsOverride:
projectType !== ProjectType.AttachedProject || !!periodicBuilds,
periodicBuilds:
periodicBuilds?.map((definition) =>
omitTypename({
...definition,
nextRunTime: definition.nextRunTime.toString(),
displayTitle: getTitle(definition),
periodicBuilds?.map(
({
alias,
configFile,
id,
intervalHours,
cron,
message,
nextRunTime,
}) => ({
alias,
configFile,
id,
message,
nextRunTime: nextRunTime.toString(),
displayTitle: getTitle({ cron, intervalHours, message }),
interval:
cron === ""
? {
specifier: IntervalSpecifier.Hours,
cron: "",
intervalHours,
}
: {
specifier: IntervalSpecifier.Cron,
intervalHours: null,
cron,
},
})
) ?? [],
};
Expand All @@ -58,14 +79,24 @@ export const formToGql: FormToGqlFunction<Tab> = (
projectRef: {
id: projectId,
periodicBuilds: periodicBuildsOverride
? periodicBuilds.map((build) => ({
alias: build.alias,
configFile: build.configFile,
id: build.id || "",
intervalHours: build.intervalHours,
message: build.message,
nextRunTime: new Date(build.nextRunTime),
}))
? periodicBuilds.map(
({ alias, configFile, id, interval, message, nextRunTime }) => ({
alias,
configFile,
id: id || "",
message,
nextRunTime: new Date(nextRunTime),
...(interval.specifier === IntervalSpecifier.Cron
? {
cron: interval.cron,
intervalHours: 0,
}
: {
cron: "",
intervalHours: interval.intervalHours,
}),
})
)
: null,
},
});
11 changes: 10 additions & 1 deletion src/pages/projectSettings/tabs/PeriodicBuildsTab/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { ProjectType } from "../utils";

export enum IntervalSpecifier {
Hours = "HOURS",
Cron = "CRON",
}

type FormPeriodicBuild = {
id: string;
intervalHours: number;
interval: {
specifier: IntervalSpecifier;
intervalHours: number;
cron: string;
};
configFile: string;
displayTitle?: string;
alias: string;
Expand Down
4 changes: 3 additions & 1 deletion src/pages/projectSettings/tabs/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,16 @@ const repoBase: RepoSettingsQuery["repoSettings"] = {
configFile: "evergreen.yml",
id: "123",
intervalHours: 24,
cron: "",
message: "",
nextRunTime: new Date("2022-03-30T17:07:10.942Z"),
},
{
alias: "test",
configFile: "evergreen.yml",
id: "456",
intervalHours: 12,
intervalHours: 0,
cron: "*/5 * * * *",
message: "Build Message",
nextRunTime: new Date("2022-03-30T17:07:10.942Z"),
},
Expand Down

0 comments on commit fde47fb

Please sign in to comment.