利用AI Skills通过ID获取Jira Issue的内容,输出格式化的文档和下载附件

Jira Ticket Generator Skill 使用指南

本 Skill 旨在帮助您快速获取 Jira 票据详情,并将其保存为本地 Markdown 文件,方便记录和归档。

:rocket: 快速开始

1. 环境配置 (认证信息自动化)

本 Skill 具备 认证信息自动发现 功能。它会按照以下优先级自动加载凭据,无需您每次手动输入:

  1. .env 文件:检查项目根目录或当前目录下的 .env 文件。

  2. .jira_config 文件:检查项目根目录下的 .jira_config 配置文件。

  3. 系统环境变量:查找以 JIRA_ 开头的环境变量。

配置示例 (.env.jira_config):

您可以参考 Skill 目录下的 .env.example 文件进行配置。


JIRA_BASE_URL=https://your-company.atlassian.net

JIRA_API_TOKEN=your_personal_access_token_here

  • JIRA_BASE_URL: 您的 Jira 实例地址。

  • JIRA_API_TOKEN: 您的 Jira 个人访问令牌。

  • JIRA_USERNAME: (可选) 如果使用 Basic Auth,可能需要提供用户名/邮箱。

2. 基本用法

您可以通过自然语言指令来调用此 Skill。

示例指令:

  • “获取 Jira 票据 PROJ-123 的内容”

  • “下载 PROJ-456 并保存为 Markdown”

  • “查看票据 BUG-789 的状态和描述”

3. 使用自定义模板

本 Skill 会按照以下顺序寻找模板:

  1. 显式指定:在指令中指定路径,例如 使用 template.md 获取 DMC25FD-70110

  2. 内置模板:Skill 目录下自带一个默认模板 .trae/skills/jira-ticket-generator/template.md

  3. 内建回退:如果上述均不可用,将使用内建的最简 Markdown 模板。

您可以随时修改 Skill 目录下的 template.md 来调整默认输出格式。

方法 A:在指令中指定

“使用 template.md 模板获取 PROJ-123”

方法 B:直接提供模板内容

"获取 PROJ-123,并按照以下格式保存:

:memo: 模板变量参考

在自定义模板中,您可以使用以下变量(使用 {{变量名}} 格式):

| key | 票据 ID |

| summary | 票据标题/摘要 |

| description | 详细描述 |

:hammer_and_wrench: 故障排除

  • 401 Unauthorized: 请检查您的 JIRA_API_TOKEN 是否有效,或者是否过期。

  • 404 Not Found: 请检查 JIRA_BASE_URL 是否正确,以及票据 ID 是否存在。

  • Template Error: 如果生成的 Markdown 格式乱了,请检查模板中的变量名称是否正确。

:light_bulb: 高级技巧

  • 批量获取: 您可以尝试一次性请求多个票据,例如 “获取 PROJ-1, PROJ-2, PROJ-3”。

  • 自动归档: 结合文件操作,您可以让 AI 将生成的票据自动放入特定的文件夹,例如 “获取 PROJ-123 并保存到 docs/issues/ 目录下”。

Skill.md【可在本地创建导入trae】

---
name: "jira-fetcher"
description: "Fetches Jira ticket content using Playwright via MCP, and generates a local markdown file based on a user-provided template. Invoke when user wants to download or save a Jira ticket."
---

# Jira Fetcher Skill (AI-Native & Analysis Edition)

This skill allows you to fetch Jira ticket details using Playwright via MCP, translate them to Chinese, organize them into a dedicated directory, and **provide an AI-powered bug analysis**.

## Usage Instructions

### 1. Gather Information & Fetch Data
- **Credential Discovery (Automated)**:
    - First, check for an `.env` file in the current or parent directories.
    - If not found, look for a `.jira_config` file.
    - If neither exists, check system environment variables starting with `JIRA_`.
    - Only ask the user if all the above methods fail.
- **ID & Token**: Extract `Jira Ticket ID`, `Base URL` (e.g., `JIRA_BASE_URL`), and `Token` (e.g., `JIRA_API_TOKEN`).
- **Fetch**: Use `Playwright_get` to retrieve the ticket JSON.
- **Analyze Template**:
    1.  Check if the user specified a template path in their instruction.
    2.  If not, check for `template.md` in the current skill's directory (`.trae/skills/jira-ticket-generator/template.md`).
    3.  If neither exists, use the default fallback template defined below.
    4.  Read the template and identify all `{{placeholder}}` variables.

### 2. AI Processing (Brain Work)
**Crucial: Perform these steps internally BEFORE calling any file tools.**
1.  **Map Variables**: Extract `key`, `summary`, `description`, `status`, etc., from the JSON.
2.  **Translate to Chinese**: Always translate `summary`, `description`, and `comments` into Chinese.
3.  **AI Bug Analysis**:
    *   **Analyze**: Based on the description and comments, use your internal knowledge to analyze the bug.
    *   **Hypothesize**: Provide possible causes (e.g., race conditions, missing callbacks, state synchronization issues).
    *   **Suggest**: Provide a step-by-step analysis and troubleshooting plan.
    *   **Insert**: Place this analysis into the `## 解析` (Analysis) section of the template.
4.  **Format Content**: Replace `{{placeholder}}` in the template with the translated/extracted values.
5.  **Handle Attachments List**: Generate a Markdown list of links to local attachment files.

### 3. File & Directory Creation (Native Tools)
- **Directory**: Use `mkdir <TICKET_ID>`.
- **Write File**: Use the `Write` tool to save the processed Markdown content to `<TICKET_ID>/<TICKET_ID>.md`.

### 4. Download Attachments (Minimal Shell)
- If attachments exist:
    - Use single `curl` or `Invoke-WebRequest` commands to download each file into the directory.
    - Example: `curl -H "Authorization: Bearer <TOKEN>" <URL> -o <TICKET_ID>/<FILENAME>`

### 5. Summary
Confirm the completion with a brief summary of what was fetched, translated, analyzed, and downloaded.

## Default Template (Fallback)
```markdown
# [{{key}}] {{summary}}

| 属性 | 内容 |
| :--- | :--- |
| **状态** | {{status}} |
| **链接** | [{{key}}]({{link}}) |

## 描述
{{description}}

## 附件
{{attachments_list}}

## 解析
{{comments}}

### AI 辅助分析
{{ai_analysis}}

## 对策


2 个赞

收藏了学习学习

2 个赞