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

1.9 KB
Raw Blame
import { createAction } from '@activepieces/pieces-framework';
import { linearAuth } from '../../..';
import { props } from '../../common/props';
import { linearGraphql } from '../../common/graphql';
import { LinearIssueNode, linearMappers } from '../../common/mappers';
import { GET_ISSUE_QUERY } from '../../common/queries';
import { issueOutputSchema } from '../../output-schemas';

export const linearGetIssue = createAction({
  auth: linearAuth,
  name: 'linear_get_issue',
  classification: 'READ',
  displayName: 'Get Issue',
  description: 'Get an issue by its key, such as ENG-123, or its ID.',
  audience: 'human',
  aiMetadata: {
    description:
      'Fetches one Linear issue by its UUID or its human identifier such as ENG-123, returning status, team, assignee, project, cycle, parent and labels. Use when a flow already holds an issue reference (from Slack, email or GitHub) and needs its current details; use Search Issues to find issues by text. Read-only and idempotent. labels_complete is false when Linear did not return every label page; label_ids and label_names then hold only the labels read.',
    idempotent: true,
  },
  props: {
    issue_id: props.issue_reference(),
  },
  outputSchema: issueOutputSchema,
  async run({ auth, propsValue }) {
    const id = propsValue.issue_id.trim();
    if (!linearGraphql.isUuid(id) && !linearGraphql.isIssueIdentifier(id)) {
      throw new Error(`"${id}" is not an issue UUID or an identifier like ENG-123.`);
    }
    const data = await linearGraphql.request<{ issue: LinearIssueNode | null }>({
      auth,
      query: GET_ISSUE_QUERY,
      variables: { id: linearGraphql.isUuid(id) ? id : id.toUpperCase() },
    });
    if (!data.issue) {
      throw new Error(`No Linear issue found for ${id}.`);
    }
    return linearMappers.flattenIssue(await linearGraphql.withAllIssueLabels({ auth, issue: data.issue }));
  },
});