Update TemplateAction schema to include input and output

Co-authored-by: Ben Lambert <ben@blam.sh>
Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com>
Co-authored-by: Fredrik Adelöw <freben@users.noreply.github.com>
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2021-02-25 11:35:11 +01:00
parent b335415fa4
commit 664f336c42
9 changed files with 150 additions and 82 deletions
@@ -34,26 +34,28 @@ export function createFetchCookiecutterAction(options: {
return {
id: 'fetch:cookiecutter',
parameterSchema: {
type: 'object',
required: ['url'],
properties: {
url: {
title: 'Fetch URL',
description:
'Relative path or absolute URL pointing to the directory tree to fetch',
type: 'string',
},
targetPath: {
title: 'Target Path',
description:
'Target path within the working directory to download the contents to.',
type: 'string',
},
values: {
title: 'Template Values',
description: 'Values to pass on to cookiecutter for templating',
type: 'object',
schema: {
input: {
type: 'object',
required: ['url'],
properties: {
url: {
title: 'Fetch URL',
description:
'Relative path or absolute URL pointing to the directory tree to fetch',
type: 'string',
},
targetPath: {
title: 'Target Path',
description:
'Target path within the working directory to download the contents to.',
type: 'string',
},
values: {
title: 'Template Values',
description: 'Values to pass on to cookiecutter for templating',
type: 'object',
},
},
},
},
@@ -28,23 +28,26 @@ export function createFetchPlainAction(options: {
return {
id: 'fetch:plain',
parameterSchema: {
type: 'object',
required: ['url'],
properties: {
url: {
title: 'Fetch URL',
description:
'Relative path or absolute URL pointing to the directory tree to fetch',
type: 'string',
},
targetPath: {
title: 'Target Path',
description:
'Target path within the working directory to download the contents to.',
type: 'string',
schema: {
input: {
type: 'object',
required: ['url'],
properties: {
url: {
title: 'Fetch URL',
description:
'Relative path or absolute URL pointing to the directory tree to fetch',
type: 'string',
},
targetPath: {
title: 'Target Path',
description:
'Target path within the working directory to download the contents to.',
type: 'string',
},
},
},
output: {},
},
async handler(ctx) {
ctx.logger.info('Fetching plain content from remote URL');
@@ -32,17 +32,32 @@ export function createPublishAzureAction(options: {
return {
id: 'publish:azure',
parameterSchema: {
type: 'object',
required: ['repoUrl'],
properties: {
repoUrl: {
title: 'Repository Location',
type: 'string',
schema: {
input: {
type: 'object',
required: ['repoUrl'],
properties: {
repoUrl: {
title: 'Repository Location',
type: 'string',
},
description: {
title: 'Repository Description',
type: 'string',
},
},
description: {
title: 'Repository Description',
type: 'string',
},
output: {
type: 'object',
properties: {
remoteUrl: {
title: 'A URL to the repository with the provider',
type: 'string',
},
repoContentsUrl: {
title: 'A URL to the root of the repository',
type: 'string',
},
},
},
},
@@ -78,7 +93,7 @@ export function createPublishAzureAction(options: {
if (!returnedRepo) {
throw new InputError(
`Unable to create the repository with Organization ${organization}, Project ${owner} and Repo ${repo}.
`Unable to create the repository with Organization ${organization}, Project ${owner} and Repo ${repo}.
Please make sure you that both the Org and Project are typed corrected and exist.`,
);
}
@@ -154,17 +154,32 @@ export function createPublishBitbucketAction(options: {
return {
id: 'publish:bitbucket',
parameterSchema: {
type: 'object',
required: ['repoUrl'],
properties: {
repoUrl: {
title: 'Repository Location',
type: 'string',
schema: {
input: {
type: 'object',
required: ['repoUrl'],
properties: {
repoUrl: {
title: 'Repository Location',
type: 'string',
},
description: {
title: 'Repository Description',
type: 'string',
},
},
description: {
title: 'Repository Description',
type: 'string',
},
output: {
type: 'object',
properties: {
remoteUrl: {
title: 'A URL to the repository with the provider',
type: 'string',
},
repoContentsUrl: {
title: 'A URL to the root of the repository',
type: 'string',
},
},
},
},
@@ -43,21 +43,36 @@ export function createPublishGithubAction(options: {
return {
id: 'publish:github',
parameterSchema: {
type: 'object',
required: ['repoUrl'],
properties: {
repoUrl: {
title: 'Repository Location',
type: 'string',
schema: {
input: {
type: 'object',
required: ['repoUrl'],
properties: {
repoUrl: {
title: 'Repository Location',
type: 'string',
},
description: {
title: 'Repository Description',
type: 'string',
},
access: {
title: 'Repository Access',
type: 'string',
},
},
description: {
title: 'Repository Description',
type: 'string',
},
access: {
title: 'Additional Repository Access',
type: 'string',
},
output: {
type: 'object',
properties: {
remoteUrl: {
title: 'A URL to the repository with the provider',
type: 'string',
},
repoContentsUrl: {
title: 'A URL to the root of the repository',
type: 'string',
},
},
},
},
@@ -31,13 +31,28 @@ export function createPublishGitlabAction(options: {
return {
id: 'publish:gitlab',
parameterSchema: {
type: 'object',
required: ['repoUrl'],
properties: {
repoUrl: {
title: 'Repository Location',
type: 'string',
schema: {
input: {
type: 'object',
required: ['repoUrl'],
properties: {
repoUrl: {
title: 'Repository Location',
type: 'string',
},
},
},
output: {
type: 'object',
properties: {
remoteUrl: {
title: 'A URL to the repository with the provider',
type: 'string',
},
repoContentsUrl: {
title: 'A URL to the root of the repository',
type: 'string',
},
},
},
},
@@ -44,6 +44,9 @@ export type ActionContext<Parameters extends ParameterBase> = {
export type TemplateAction<Parameters extends ParameterBase> = {
id: string;
parameterSchema?: Schema;
schema?: {
input?: Schema;
output?: Schema;
};
handler: (ctx: ActionContext<Parameters>) => Promise<void>;
};
@@ -99,7 +99,7 @@ export class TaskWorker {
}
const parameters = JSON.parse(
JSON.stringify(step.parameters),
JSON.stringify(step.input),
(_key, value) => {
if (typeof value === 'string') {
return handlebars.compile(value, {
@@ -113,10 +113,10 @@ export class TaskWorker {
},
);
if (action.parameterSchema) {
if (action.schema?.input) {
const validateResult = validateJsonSchema(
parameters,
action.parameterSchema,
action.schema,
{ propertyName: 'parameters' },
);
if (!validateResult.valid) {
@@ -49,7 +49,7 @@ export type TaskSpec = {
id: string;
name: string;
action: string;
parameters?: JsonObject;
input?: JsonObject;
}>;
output: { [name: string]: string };
};