feat: add schedule integration
This commit is contained in:
@@ -219,7 +219,6 @@
|
||||
{
|
||||
"name": "New favorite photo",
|
||||
"key": "newFavoritePhoto",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when you favorite a photo.",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -235,7 +234,6 @@
|
||||
{
|
||||
"name": "New photo in album",
|
||||
"key": "newPhotoInAlbum",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when you add a new photo in an album.",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -274,7 +272,6 @@
|
||||
{
|
||||
"name": "New photo",
|
||||
"key": "newPhoto",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when you add a new photo.",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -290,7 +287,6 @@
|
||||
{
|
||||
"name": "New album",
|
||||
"key": "newAlbum",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when you create a new album.",
|
||||
"substeps": [
|
||||
{
|
||||
|
@@ -219,7 +219,6 @@
|
||||
{
|
||||
"name": "New repository",
|
||||
"key": "newRepository",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new repository is created",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -235,7 +234,6 @@
|
||||
{
|
||||
"name": "New organization",
|
||||
"key": "newOrganization",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new organization is created",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -251,7 +249,6 @@
|
||||
{
|
||||
"name": "New branch",
|
||||
"key": "newBranch",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new branch is created",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -290,7 +287,6 @@
|
||||
{
|
||||
"name": "New notification",
|
||||
"key": "newNotification",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new notification is created",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -330,7 +326,6 @@
|
||||
{
|
||||
"name": "New pull request",
|
||||
"key": "newPullRequest",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new pull request is created",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -369,7 +364,6 @@
|
||||
{
|
||||
"name": "New watcher",
|
||||
"key": "newWatcher",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new watcher is added to a repo",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -408,7 +402,6 @@
|
||||
{
|
||||
"name": "New milestone",
|
||||
"key": "newMilestone",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new milestone is created",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -447,7 +440,6 @@
|
||||
{
|
||||
"name": "New commit comment",
|
||||
"key": "newCommitComment",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new commit comment is created",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -486,7 +478,6 @@
|
||||
{
|
||||
"name": "New label",
|
||||
"key": "newLabel",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new label is created",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -525,7 +516,6 @@
|
||||
{
|
||||
"name": "New collaborator",
|
||||
"key": "newCollaborator",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new collaborator is added to a repo",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -564,7 +554,6 @@
|
||||
{
|
||||
"name": "New release",
|
||||
"key": "newRelease",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new release is created",
|
||||
"substeps": [
|
||||
{
|
||||
@@ -603,7 +592,6 @@
|
||||
{
|
||||
"name": "New commit",
|
||||
"key": "newCommit",
|
||||
"interval": "15m",
|
||||
"description": "Triggers when a new commit is created",
|
||||
"substeps": [
|
||||
{
|
||||
|
1
packages/backend/src/apps/schedule/assets/favicon.svg
Normal file
1
packages/backend/src/apps/schedule/assets/favicon.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 24 24"><path fill="#1976d2" d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"></path><path fill="#1976d2" d="M12.5 7H11v6l5.25 3.15.75-1.23-4.5-2.67z"></path></svg>
|
After Width: | Height: | Size: 345 B |
0
packages/backend/src/apps/schedule/index.d.ts
vendored
Normal file
0
packages/backend/src/apps/schedule/index.d.ts
vendored
Normal file
18
packages/backend/src/apps/schedule/index.ts
Normal file
18
packages/backend/src/apps/schedule/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import Triggers from './triggers';
|
||||
import {
|
||||
IService,
|
||||
IApp,
|
||||
IJSONObject,
|
||||
} from '@automatisch/types';
|
||||
|
||||
export default class Schedule implements IService {
|
||||
triggers: Triggers;
|
||||
|
||||
constructor(
|
||||
appData: IApp,
|
||||
connectionData: IJSONObject,
|
||||
parameters: IJSONObject
|
||||
) {
|
||||
this.triggers = new Triggers(connectionData, parameters);
|
||||
}
|
||||
}
|
46
packages/backend/src/apps/schedule/info.json
Normal file
46
packages/backend/src/apps/schedule/info.json
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "Schedule",
|
||||
"key": "schedule",
|
||||
"iconUrl": "{BASE_URL}/apps/schedule/assets/favicon.svg",
|
||||
"docUrl": "https://automatisch.io/docs/schedule",
|
||||
"primaryColor": "0059F7",
|
||||
"requiresAuthentication": false,
|
||||
"triggers": [
|
||||
{
|
||||
"name": "Every hour",
|
||||
"key": "everyHour",
|
||||
"description": "Triggers every hour.",
|
||||
"substeps": [
|
||||
{
|
||||
"key": "chooseTrigger",
|
||||
"name": "Set up a trigger",
|
||||
"arguments": [
|
||||
{
|
||||
"label": "Trigger on weekends?",
|
||||
"key": "triggersOnWeekend",
|
||||
"type": "dropdown",
|
||||
"description": "Should this flow trigger on Saturday and Sunday?",
|
||||
"required": true,
|
||||
"value": true,
|
||||
"variables": false,
|
||||
"options": [
|
||||
{
|
||||
"label": "Yes",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"label": "No",
|
||||
"value": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "testStep",
|
||||
"name": "Test trigger"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
10
packages/backend/src/apps/schedule/triggers.ts
Normal file
10
packages/backend/src/apps/schedule/triggers.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
import EveryHour from './triggers/every-hour';
|
||||
|
||||
export default class Triggers {
|
||||
everyHour: EveryHour;
|
||||
|
||||
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
||||
this.everyHour = new EveryHour(parameters);
|
||||
}
|
||||
}
|
35
packages/backend/src/apps/schedule/triggers/every-hour.ts
Normal file
35
packages/backend/src/apps/schedule/triggers/every-hour.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import type { IJSONObject, IJSONValue, ITrigger } from '@automatisch/types';
|
||||
import { cronTimes, getNextCronDateTime, getDateTimeObjectRepresentation } from '../utils';
|
||||
|
||||
export default class EveryHour implements ITrigger {
|
||||
triggersOnWeekend?: boolean | string;
|
||||
|
||||
constructor(parameters: IJSONObject) {
|
||||
if (parameters.triggersOnWeekend) {
|
||||
this.triggersOnWeekend = parameters.triggersOnWeekend as string;
|
||||
}
|
||||
}
|
||||
|
||||
get interval() {
|
||||
if (this.triggersOnWeekend) {
|
||||
return cronTimes.everyHour;
|
||||
}
|
||||
|
||||
return cronTimes.everyHourExcludingWeekends;
|
||||
}
|
||||
|
||||
async run(startDateTime: Date) {
|
||||
const dateTime = DateTime.fromJSDate(startDateTime);
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(dateTime) as IJSONValue;
|
||||
|
||||
return [dateTimeObjectRepresentation] as IJSONValue;
|
||||
}
|
||||
|
||||
async testRun() {
|
||||
const nextCronDateTime = getNextCronDateTime(this.interval);
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(nextCronDateTime) as IJSONValue;
|
||||
|
||||
return [dateTimeObjectRepresentation] as IJSONValue;
|
||||
}
|
||||
}
|
28
packages/backend/src/apps/schedule/utils.ts
Normal file
28
packages/backend/src/apps/schedule/utils.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import cronParser from 'cron-parser';
|
||||
|
||||
export const cronTimes = {
|
||||
everyHour: '0 * * * *',
|
||||
everyHourExcludingWeekends: '0 * * * 1-5',
|
||||
};
|
||||
|
||||
export function getNextCronDateTime(cronString: string) {
|
||||
const cronDate = cronParser.parseExpression(cronString);
|
||||
const matchingNextCronDateTime = cronDate.next();
|
||||
const matchingNextDateTime = DateTime.fromJSDate(matchingNextCronDateTime.toDate());
|
||||
|
||||
return matchingNextDateTime;
|
||||
};
|
||||
|
||||
export function getDateTimeObjectRepresentation(dateTime: DateTime) {
|
||||
const defaults = dateTime.toObject();
|
||||
|
||||
return {
|
||||
...defaults,
|
||||
ISO_date_time: dateTime.toISO(),
|
||||
pretty_date: dateTime.toLocaleString(DateTime.DATE_MED),
|
||||
pretty_time: dateTime.toLocaleString(DateTime.TIME_WITH_SECONDS),
|
||||
pretty_day_of_week: dateTime.toFormat('cccc'),
|
||||
day_of_week: dateTime.weekday,
|
||||
};
|
||||
}
|
@@ -219,7 +219,6 @@
|
||||
{
|
||||
"name": "My Tweet",
|
||||
"key": "myTweet",
|
||||
"interval": "15m",
|
||||
"description": "Will be triggered when you tweet something new.",
|
||||
"substeps": [
|
||||
{
|
||||
|
Reference in New Issue
Block a user