Untitled

mail@pastecode.io avatar
unknown
typescript
a year ago
1.2 kB
1
Indexable
Never
import _ from 'lodash';

import { fromPipeDream } from '@automation/components/pipedream';
import { typeFor, valueAs } from '@automation/helpers/value';
import { PDFunctionInputs } from '@automation/api-types';

const path = 'bitbucket/actions/create-snippet-comment/create-snippet-comment.js';

export const definition = fromPipeDream(
	path,
	{
		id: 'action.bitbucket.create-snippet-comment',
		icon: 'https://i.hizliresim.com/5cg3sym.png',
		auth: 'oauth',
		apiAction: 'noScope',
		desc: 'Creates a new snippet comment. [See docs here](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-snippets/#api-snippets-workspace-encoded-id-comments-post)',
		keywords: ['snippet', 'snippet comment', 'create snippet comment', 'comment'],
		outputs: [
			{
				name: 'comment',
				type: typeFor('Text'),
			},
		],
	},
	async (inputs, actualRun) => {
		const rawInputs = _.mapValues(inputs, (v) => v.value) as PDFunctionInputs;

		if (!rawInputs.htmlContent && !rawInputs.rawContent && !rawInputs.markupContent)
			throw new Error('Need to provide at least one content type');

		const response = await actualRun(rawInputs);

		return {
			name: 'Result',
			outputs: {
				comment: valueAs(typeFor('Text'), response),
			},
		};
	},
);