Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.1 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { youtrackAuth } from '../auth';
import { issueDropdown, youtrackApiCall } from '../common';
import { applyCommandActionOutputSchema } from '../output-schemas';

export const applyCommandAction = createAction({
  auth: youtrackAuth,
  name: 'apply_command',
  classification: 'WRITE',
  outputSchema: applyCommandActionOutputSchema,
  displayName: 'Apply Command',
  description: 'Applies a YouTrack command to an issue (e.g. change state, assign, set sprint).',
  audience: 'both',
  aiMetadata: { description: 'Apply a free-text YouTrack command to an issue (e.g. "State Fixed", "assignee jane.doe", "Priority Critical") to change its state, assignment, fields, or sprint in one step, optionally with a comment and silent (no-notification) mode. Use for workflow transitions expressed as commands. Mutating; idempotency depends on the command — setting a state or field is idempotent, while appending a comment is not.', idempotent: false },
  props: {
    issue: issueDropdown,
    command: Property.ShortText({
      displayName: 'Command',
      description: 'YouTrack command. Examples: State Fixed | assignee jane.doe | Priority Critical | for me Critical',
      required: true,
    }),
    comment: Property.LongText({ displayName: 'Comment', description: 'Optional comment.', required: false }),
    silent: Property.Checkbox({ displayName: 'Apply silently?', description: 'No notifications if enabled.', required: false, defaultValue: false }),
  },
  async run(context) {
    const { baseUrl, apiToken } = context.auth.props;
    const body: Record<string, unknown> = { query: context.propsValue.command, issues: [{ id: context.propsValue.issue }] };
    if (context.propsValue.comment) body['comment'] = context.propsValue.comment;
    if (context.propsValue.silent) body['silent'] = true;
    await youtrackApiCall({
      baseUrl,
      token: apiToken,
      method: HttpMethod.POST,
      path: '/commands',
      body,
    });
    return { success: true, command: context.propsValue.command };
  },
});