$npx -y skills add anhtester/codex-testing-kit --skill jira-integrationSkill tích hợp Jira/Xray — lấy requirements từ Jira, xác thực Xray, và đẩy kết quả test lên Xray Cloud/Server.
| 1 | # Jira & Xray Integration Skill |
| 2 | |
| 3 | ## Mô tả |
| 4 | |
| 5 | Skill này cung cấp khả năng tích hợp giữa Codex workspace với hệ thống Jira và Xray để: |
| 6 | |
| 7 | 1. **Lấy Requirements/User Stories** từ Jira → chuyển thành tài liệu yêu cầu chuẩn |
| 8 | 2. **Xác thực Xray** (Cloud hoặc Server/Data Center) |
| 9 | 3. **Đẩy kết quả test** (Playwright, JUnit, Allure) lên Xray Test Management |
| 10 | |
| 11 | --- |
| 12 | |
| 13 | ## Khi nào sử dụng |
| 14 | |
| 15 | Agent sử dụng skill này khi user yêu cầu: |
| 16 | |
| 17 | - Lấy requirement / user story từ Jira |
| 18 | - Kết nối / test connection đến Jira API |
| 19 | - Đẩy kết quả test lên Xray |
| 20 | - Import test results lên Jira |
| 21 | - Xác thực Xray token |
| 22 | - Tích hợp CI/CD với Jira |
| 23 | |
| 24 | Trigger keywords: |
| 25 | - "fetch jira", "lấy requirement từ jira", "get jira ticket" |
| 26 | - "import xray", "đẩy kết quả lên xray", "push test results" |
| 27 | - "test jira connection", "kiểm tra kết nối jira" |
| 28 | |
| 29 | --- |
| 30 | |
| 31 | ## Cấu trúc Scripts |
| 32 | |
| 33 | ``` |
| 34 | scripts/integrations/ |
| 35 | ├── jira/ |
| 36 | │ ├── jira_fetcher.js # Lấy Requirement/User Story từ Jira |
| 37 | │ ├── xray_auth.js # Xác thực và lấy Token Xray |
| 38 | │ ├── xray_importer.js # Import kết quả test lên Xray |
| 39 | │ └── utils.js # Hàm utility dùng chung |
| 40 | └── package.json # Dependencies (axios, dotenv) |
| 41 | ``` |
| 42 | |
| 43 | --- |
| 44 | |
| 45 | ## Điều kiện tiên quyết (Prerequisites) |
| 46 | |
| 47 | ### 1. Cài đặt dependencies |
| 48 | |
| 49 | ```bash |
| 50 | cd scripts/integrations |
| 51 | npm install |
| 52 | ``` |
| 53 | |
| 54 | ### 2. Cấu hình .env |
| 55 | |
| 56 | Copy `.env.example` thành `.env` ở thư mục gốc project: |
| 57 | |
| 58 | ```bash |
| 59 | cp .env.example .env |
| 60 | ``` |
| 61 | |
| 62 | Điền các thông tin bắt buộc: |
| 63 | |
| 64 | | Biến | Mô tả | Bắt buộc | |
| 65 | |------|--------|----------| |
| 66 | | `JIRA_BASE_URL` | URL Jira instance (VD: `https://domain.atlassian.net`) | ✅ | |
| 67 | | `JIRA_EMAIL` | Email tài khoản Jira (Cloud) | ✅ (Cloud) | |
| 68 | | `JIRA_API_TOKEN` | API Token (Cloud) | ✅ (Cloud) | |
| 69 | | `JIRA_PAT` | Personal Access Token (Server/DC) | ✅ (Server) | |
| 70 | | `JIRA_PROJECT_KEY` | Project key mặc định | Khuyến nghị | |
| 71 | | `XRAY_PLATFORM` | `cloud` hoặc `server` | Mặc định: cloud | |
| 72 | | `XRAY_CLIENT_ID` | Xray API Client ID | Khi dùng Xray Cloud | |
| 73 | | `XRAY_CLIENT_SECRET` | Xray API Client Secret | Khi dùng Xray Cloud | |
| 74 | |
| 75 | ### 3. Cách lấy Jira API Token (Cloud) |
| 76 | |
| 77 | 1. Đăng nhập vào [https://id.atlassian.com/manage-profile/security/api-tokens](https://id.atlassian.com/manage-profile/security/api-tokens) |
| 78 | 2. Nhấn **Create API token** |
| 79 | 3. Đặt label (ví dụ: "Codex Automation") |
| 80 | 4. Copy token → dán vào `JIRA_API_TOKEN` trong file `.env` |
| 81 | |
| 82 | ### 4. Cách lấy Xray Cloud API Key |
| 83 | |
| 84 | 1. Truy cập [https://app.getxray.app](https://app.getxray.app) → Settings → API Keys |
| 85 | 2. Hoặc trong Jira: Apps → Xray → Settings → API Keys |
| 86 | 3. Tạo API Key mới → Copy **Client ID** và **Client Secret** |
| 87 | |
| 88 | --- |
| 89 | |
| 90 | ## Hướng dẫn sử dụng |
| 91 | |
| 92 | ### Lấy 1 issue cụ thể |
| 93 | |
| 94 | ```bash |
| 95 | node scripts/integrations/jira/jira_fetcher.js --issue PROJ-123 |
| 96 | ``` |
| 97 | |
| 98 | ### Lấy issues theo project |
| 99 | |
| 100 | ```bash |
| 101 | node scripts/integrations/jira/jira_fetcher.js --project PROJ --type Story --max 20 |
| 102 | ``` |
| 103 | |
| 104 | ### Tìm theo JQL |
| 105 | |
| 106 | ```bash |
| 107 | node scripts/integrations/jira/jira_fetcher.js --jql "project = PROJ AND status = 'To Do'" |
| 108 | ``` |
| 109 | |
| 110 | ### Xuất thành Markdown requirement |
| 111 | |
| 112 | ```bash |
| 113 | node scripts/integrations/jira/jira_fetcher.js --issue PROJ-123 --format md |
| 114 | ``` |
| 115 | |
| 116 | ### Lấy children của Epic |
| 117 | |
| 118 | ```bash |
| 119 | node scripts/integrations/jira/jira_fetcher.js --epic PROJ-10 --format md |
| 120 | ``` |
| 121 | |
| 122 | ### Test Xray authentication |
| 123 | |
| 124 | ```bash |
| 125 | node scripts/integrations/jira/xray_auth.js |
| 126 | node scripts/integrations/jira/xray_auth.js --verify |
| 127 | ``` |
| 128 | |
| 129 | ### Import kết quả Playwright lên Xray |
| 130 | |
| 131 | ```bash |
| 132 | node scripts/integrations/jira/xray_importer.js --format playwright --file ./test-results.json --project PROJ |
| 133 | ``` |
| 134 | |
| 135 | ### Import JUnit XML lên Xray |
| 136 | |
| 137 | ```bash |
| 138 | node scripts/integrations/jira/xray_importer.js --format junit --file ./junit-results.xml --project PROJ |
| 139 | ``` |
| 140 | |
| 141 | --- |
| 142 | |
| 143 | ## Workflow liên quan |
| 144 | |
| 145 | | Workflow | Mô tả | |
| 146 | |----------|--------| |
| 147 | | `$fetch-jira-requirements` | Lấy requirements từ Jira ticket và lưu thành file | |
| 148 | | `$import-test-results-xray` | Đẩy kết quả test lên Xray | |
| 149 | |
| 150 | --- |
| 151 | |
| 152 | ## Lưu ý quan trọng |
| 153 | |
| 154 | - **Bảo mật**: KHÔNG bao giờ commit file `.env` lên Git. File `.gitignore` đã được cấu hình bỏ qua `.env`. |
| 155 | - **Rate Limiting**: Jira Cloud có giới hạn API calls. Script đã hỗ trợ phân trang (pagination) để tránh vượt limit. |
| 156 | - **Atlassian Document Format (ADF)**: Jira Cloud sử dụng ADF cho description. Script tự động chuyển đổi ADF → plain text. |
| 157 | - **Test Key Convention**: Khi import Playwright results, nên đặt test key trong title: `test('[PROJ-123] Login should work', ...)` để Xray mapping đúng test case. |
| 158 | |
| 159 | --- |
| 160 | |
| 161 | ## Troubleshooting |
| 162 | |
| 163 | | Lỗi | Nguyên nhân | Giải pháp | |
| 164 | |------|-------------|-----------| |
| 165 | | HTTP 401 | Token/password sai | Kiểm tra JIRA_API_TOKEN hoặc JIRA_PAT | |
| 166 | | HTTP 403 | Không có quyền | Kiểm tra permission trên Jira project | |
| 167 | | HTTP 404 | URL sai hoặc issue không tồn tại | Kiểm tra JIRA_BASE_URL và issue key | |
| 168 | | `ENOTFOUND` | DNS không resolve | Kiểm tra JIRA_BASE_URL có đúng domain không | |
| 169 | | `ECONNREFUSED` | Server không chạy | Kiểm tra Jira Server có online k |