Merge pull request #668 from automatisch/refactor/action-arguments

refactor: Use only arguments for action definitions
This commit is contained in:
Ömer Faruk Aydın
2022-11-01 00:50:45 +01:00
committed by GitHub
10 changed files with 262 additions and 331 deletions

View File

@@ -4,46 +4,32 @@ export default defineAction({
name: 'Send a message to channel',
key: 'sendMessageToChannel',
description: 'Send a message to a specific channel you specify.',
substeps: [
arguments: [
{
key: 'chooseConnection',
name: 'Choose connection',
},
{
key: 'chooseAction',
name: 'Set up action',
arguments: [
{
label: 'Channel',
key: 'channel',
type: 'dropdown' as const,
required: true,
description: 'Pick a channel to send the message to.',
variables: false,
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listChannels',
},
],
label: 'Channel',
key: 'channel',
type: 'dropdown' as const,
required: true,
description: 'Pick a channel to send the message to.',
variables: false,
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listChannels',
},
},
{
label: 'Message text',
key: 'message',
type: 'string' as const,
required: true,
description: 'The content of your new message.',
variables: true,
}
],
],
},
},
{
key: 'testStep',
name: 'Test action',
label: 'Message text',
key: 'message',
type: 'string' as const,
required: true,
description: 'The content of your new message.',
variables: true,
},
],
@@ -51,7 +37,10 @@ export default defineAction({
const data = {
content: $.step.parameters.message as string,
};
const response = await $.http?.post(`/channels/${$.step.parameters.channel}/messages`, data);
const response = await $.http?.post(
`/channels/${$.step.parameters.channel}/messages`,
data
);
$.setActionItem({ raw: response.data });
},

View File

@@ -1,4 +1,3 @@
import { IActionOutput } from '@automatisch/types';
import defineAction from '../../../../helpers/define-action';
import getRepoOwnerAndRepo from '../../common/get-repo-owner-and-repo';
@@ -6,51 +5,37 @@ export default defineAction({
name: 'Create issue',
key: 'createIssue',
description: 'Create a new issue.',
substeps: [
arguments: [
{
key: 'chooseConnection',
name: 'Choose connection',
},
{
key: 'chooseAction',
name: 'Set up action',
arguments: [
{
label: 'Repo',
key: 'repo',
type: 'dropdown' as const,
required: false,
variables: false,
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listRepos',
},
],
label: 'Repo',
key: 'repo',
type: 'dropdown' as const,
required: false,
variables: false,
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listRepos',
},
},
{
label: 'Title',
key: 'title',
type: 'string' as const,
required: true,
variables: true,
},
{
label: 'Body',
key: 'body',
type: 'string' as const,
required: true,
variables: true,
},
],
],
},
},
{
key: 'testStep',
name: 'Test action',
label: 'Title',
key: 'title',
type: 'string' as const,
required: true,
variables: true,
},
{
label: 'Body',
key: 'body',
type: 'string' as const,
required: true,
variables: true,
},
],

View File

@@ -5,69 +5,55 @@ export default defineAction({
name: 'Find message',
key: 'findMessage',
description: 'Find a Slack message using the Slack Search feature.',
substeps: [
arguments: [
{
key: 'chooseConnection',
name: 'Choose connection',
label: 'Search Query',
key: 'query',
type: 'string' as const,
required: true,
description:
'Search query to use for finding matching messages. See the Slack Search Documentation for more information on constructing a query.',
variables: true,
},
{
key: 'setupAction',
name: 'Set up action',
arguments: [
label: 'Sort by',
key: 'sortBy',
type: 'dropdown' as const,
description:
'Sort messages by their match strength or by their date. Default is score.',
required: true,
value: 'score',
variables: false,
options: [
{
label: 'Search Query',
key: 'query',
type: 'string' as const,
required: true,
description:
'Search query to use for finding matching messages. See the Slack Search Documentation for more information on constructing a query.',
variables: true,
},
{
label: 'Sort by',
key: 'sortBy',
type: 'dropdown' as const,
description:
'Sort messages by their match strength or by their date. Default is score.',
required: true,
label: 'Match strength',
value: 'score',
variables: false,
options: [
{
label: 'Match strength',
value: 'score',
},
{
label: 'Message date time',
value: 'timestamp',
},
],
},
{
label: 'Sort direction',
key: 'sortDirection',
type: 'dropdown' as const,
description:
'Sort matching messages in ascending or descending order. Default is descending.',
required: true,
value: 'desc',
variables: false,
options: [
{
label: 'Descending (newest or best match first)',
value: 'desc',
},
{
label: 'Ascending (oldest or worst match first)',
value: 'asc',
},
],
label: 'Message date time',
value: 'timestamp',
},
],
},
{
key: 'testStep',
name: 'Test action',
label: 'Sort direction',
key: 'sortDirection',
type: 'dropdown' as const,
description:
'Sort matching messages in ascending or descending order. Default is descending.',
required: true,
value: 'desc',
variables: false,
options: [
{
label: 'Descending (newest or best match first)',
value: 'desc',
},
{
label: 'Ascending (oldest or worst match first)',
value: 'asc',
},
],
},
],

View File

@@ -5,46 +5,32 @@ export default defineAction({
name: 'Send a message to channel',
key: 'sendMessageToChannel',
description: 'Send a message to a specific channel you specify.',
substeps: [
arguments: [
{
key: 'chooseConnection',
name: 'Choose connection',
},
{
key: 'setupAction',
name: 'Set up action',
arguments: [
{
label: 'Channel',
key: 'channel',
type: 'dropdown' as const,
required: true,
description: 'Pick a channel to send the message to.',
variables: false,
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listChannels',
},
],
label: 'Channel',
key: 'channel',
type: 'dropdown' as const,
required: true,
description: 'Pick a channel to send the message to.',
variables: false,
source: {
type: 'query',
name: 'getData',
arguments: [
{
name: 'key',
value: 'listChannels',
},
},
{
label: 'Message text',
key: 'message',
type: 'string' as const,
required: true,
description: 'The content of your new message.',
variables: true,
},
],
],
},
},
{
key: 'testStep',
name: 'Test action',
label: 'Message text',
key: 'message',
type: 'string' as const,
required: true,
description: 'The content of your new message.',
variables: true,
},
],

View File

@@ -6,86 +6,72 @@ export default defineAction({
name: 'Send Email',
key: 'sendEmail',
description: 'Send an email',
substeps: [
arguments: [
{
key: 'chooseConnection',
name: 'Choose connection',
label: 'From name',
key: 'fromName',
type: 'string' as const,
required: false,
description: 'Display name of the sender.',
variables: true,
},
{
key: 'chooseAction',
name: 'Set up action',
arguments: [
{
label: 'From name',
key: 'fromName',
type: 'string' as const,
required: false,
description: 'Display name of the sender.',
variables: true,
},
{
label: 'From email',
key: 'fromEmail',
type: 'string' as const,
required: true,
description: 'Email address of the sender.',
variables: true,
},
{
label: 'Reply to',
key: 'replyTo',
type: 'string' as const,
required: false,
description:
'Email address to reply to. Defaults to the from email address.',
variables: true,
},
{
label: 'To',
key: 'to',
type: 'string' as const,
required: true,
description:
'Comma seperated list of email addresses to send the email to.',
variables: true,
},
{
label: 'Cc',
key: 'cc',
type: 'string' as const,
required: false,
description: 'Comma seperated list of email addresses.',
variables: true,
},
{
label: 'Bcc',
key: 'bcc',
type: 'string' as const,
required: false,
description: 'Comma seperated list of email addresses.',
variables: true,
},
{
label: 'Subject',
key: 'subject',
type: 'string' as const,
required: true,
description: 'Subject of the email.',
variables: true,
},
{
label: 'Body',
key: 'body',
type: 'string' as const,
required: true,
description: 'Body of the email.',
variables: true,
},
],
label: 'From email',
key: 'fromEmail',
type: 'string' as const,
required: true,
description: 'Email address of the sender.',
variables: true,
},
{
key: 'testStep',
name: 'Test action',
label: 'Reply to',
key: 'replyTo',
type: 'string' as const,
required: false,
description:
'Email address to reply to. Defaults to the from email address.',
variables: true,
},
{
label: 'To',
key: 'to',
type: 'string' as const,
required: true,
description:
'Comma seperated list of email addresses to send the email to.',
variables: true,
},
{
label: 'Cc',
key: 'cc',
type: 'string' as const,
required: false,
description: 'Comma seperated list of email addresses.',
variables: true,
},
{
label: 'Bcc',
key: 'bcc',
type: 'string' as const,
required: false,
description: 'Comma seperated list of email addresses.',
variables: true,
},
{
label: 'Subject',
key: 'subject',
type: 'string' as const,
required: true,
description: 'Subject of the email.',
variables: true,
},
{
label: 'Body',
key: 'body',
type: 'string' as const,
required: true,
description: 'Body of the email.',
variables: true,
},
],

View File

@@ -4,46 +4,32 @@ export default defineAction({
name: 'Send SMS',
key: 'sendSms',
description: 'Send an SMS',
substeps: [
arguments: [
{
key: 'chooseConnection',
name: 'Choose connection',
label: 'From Number',
key: 'fromNumber',
type: 'string' as const,
required: true,
description:
'The number to send the SMS from. Include country code. Example: 15551234567',
variables: true,
},
{
key: 'chooseAction',
name: 'Set up action',
arguments: [
{
label: 'From Number',
key: 'fromNumber',
type: 'string' as const,
required: true,
description:
'The number to send the SMS from. Include country code. Example: 15551234567',
variables: true,
},
{
label: 'To Number',
key: 'toNumber',
type: 'string' as const,
required: true,
description:
'The number to send the SMS to. Include country code. Example: 15551234567',
variables: true,
},
{
label: 'Message',
key: 'message',
type: 'string' as const,
required: true,
description: 'The message to send.',
variables: true,
},
],
label: 'To Number',
key: 'toNumber',
type: 'string' as const,
required: true,
description:
'The number to send the SMS to. Include country code. Example: 15551234567',
variables: true,
},
{
key: 'testStep',
name: 'Test action',
label: 'Message',
key: 'message',
type: 'string' as const,
required: true,
description: 'The message to send.',
variables: true,
},
],

View File

@@ -4,28 +4,14 @@ export default defineAction({
name: 'Create Tweet',
key: 'createTweet',
description: 'Create a tweet.',
substeps: [
arguments: [
{
key: 'chooseConnection',
name: 'Choose connection',
},
{
key: 'chooseAction',
name: 'Set up action',
arguments: [
{
label: 'Tweet body',
key: 'tweet',
type: 'string' as const,
required: true,
description: 'The content of your new tweet.',
variables: true,
},
],
},
{
key: 'testStep',
name: 'Test action',
label: 'Tweet body',
key: 'tweet',
type: 'string' as const,
required: true,
description: 'The content of your new tweet.',
variables: true,
},
],

View File

@@ -1,5 +1,5 @@
import { IAction } from '@automatisch/types';
import { IRawAction } from '@automatisch/types';
export default function defineAction(actionDefinition: IAction): IAction {
export default function defineAction(actionDefinition: IRawAction): IRawAction {
return actionDefinition;
}

View File

@@ -1,4 +1,10 @@
import { IApp, IRawTrigger, ITrigger } from '@automatisch/types';
import {
IAction,
IApp,
IRawAction,
IRawTrigger,
ITrigger,
} from '@automatisch/types';
import { omit, cloneDeep } from 'lodash';
async function getDefaultExport(path: string) {
@@ -9,39 +15,15 @@ function stripFunctions<C>(data: C): C {
return JSON.parse(JSON.stringify(data));
}
const chooseConnectionStep = {
key: 'chooseConnection',
name: 'Choose connection',
};
const testStep = {
key: 'testStep',
name: 'Test trigger',
};
const getApp = async (appKey: string, stripFuncs = true) => {
const appData: IApp = cloneDeep(await getDefaultExport(`../apps/${appKey}`));
appData.triggers = appData?.triggers?.map((trigger: IRawTrigger) => {
const computedTrigger: ITrigger = omit(trigger, ['arguments']);
return addStaticSubsteps('trigger', appData, trigger);
});
computedTrigger.substeps = [];
if (appData.supportsConnections) {
computedTrigger.substeps.push(chooseConnectionStep);
}
if (trigger.arguments) {
computedTrigger.substeps.push({
key: 'chooseTrigger',
name: 'Set up a trigger',
arguments: trigger.arguments,
});
}
computedTrigger.substeps.push(testStep);
return computedTrigger;
appData.actions = appData?.actions?.map((action: IRawAction) => {
return addStaticSubsteps('action', appData, action);
});
if (stripFuncs) {
@@ -51,4 +33,42 @@ const getApp = async (appKey: string, stripFuncs = true) => {
return appData;
};
const chooseConnectionStep = {
key: 'chooseConnection',
name: 'Choose connection',
};
const testStep = (stepType: 'trigger' | 'action') => {
return {
key: 'testStep',
name: stepType === 'trigger' ? 'Test trigger' : 'Test action',
};
};
const addStaticSubsteps = (
stepType: 'trigger' | 'action',
appData: IApp,
step: IRawTrigger | IRawAction
) => {
const computedStep: ITrigger | IAction = omit(step, ['arguments']);
computedStep.substeps = [];
if (appData.supportsConnections) {
computedStep.substeps.push(chooseConnectionStep);
}
if (step.arguments) {
computedStep.substeps.push({
key: 'chooseTrigger',
name: stepType === 'trigger' ? 'Set up a trigger' : 'Set up action',
arguments: step.arguments,
});
}
computedStep.substeps.push(testStep(stepType));
return computedStep;
};
export default getApp;

View File

@@ -232,14 +232,21 @@ export interface IActionItem {
raw: IJSONObject;
}
export interface IAction {
export interface IBaseAction {
name: string;
key: string;
description: string;
substeps: ISubstep[];
run($: IGlobalVariable): Promise<void>;
}
export interface IRawAction extends IBaseAction {
arguments?: IField[];
}
export interface IAction extends IBaseAction {
substeps?: ISubstep[];
}
export interface IAuthentication {
client: unknown;
verifyCredentials(): Promise<IJSONObject>;