已开启
feat: assign newly created issues to current user #37
pantong创建于 8月6日
feat: assign newly created issues to current user #37
已开启
共 2 个文件变更+71-6
| @@ -41,7 +41,7 @@ npx skills add https://gitcode.com/cann-agent/skills.git -a opencode | |||
| 41 | | 技能 | 描述 | | 41 | | 技能 | 描述 | |
| 42 | |----------------------------------------------------|--------------------------| | 42 | |----------------------------------------------------|--------------------------| |
| 43 | | [gitcode-pr](skills/gitcode-pr/) | 创建pr(按模板填充描述),提交代码行内检视意见 | | 43 | | [gitcode-pr](skills/gitcode-pr/) | 创建pr(按模板填充描述),提交代码行内检视意见 | |
| 44 | -| [gitcode-issue](skills/gitcode-issue/) | 读取issue及评论, 回复issue | | 44 | +| [gitcode-issue](skills/gitcode-issue/) | 创建issue(默认指派当前用户),读取及回复issue | |
| 45 | | [gitcode-pipeline](skills/gitcode-pipeline/) | 触发ci,监控ci结果,修复编译及llt执行错误,提交代码后重新触发ci | | 45 | | [gitcode-pipeline](skills/gitcode-pipeline/) | 触发ci,监控ci结果,修复编译及llt执行错误,提交代码后重新触发ci | |
| 46 | 46 | ||
| 47 | ## 许可证 | 47 | ## 许可证 |
| @@ -1,19 +1,20 @@ | |||
| 1 | --- | 1 | --- |
| 2 | name: gitcode-issue | 2 | name: gitcode-issue |
| 3 | -description: '读取 GitCode issue 详情和评论。当用户提到 GitCode issue 时必须使用此技能。 | 3 | +description: '创建或读取 GitCode issue 详情和评论。当用户提到 GitCode issue 时必须使用此技能。 |
| 4 | 4 | ||
| 5 | **必须触发此 skill 的场景**: | 5 | **必须触发此 skill 的场景**: |
| 6 | +- 创建 issue:新建issue、创建issue、提issue、生成issue、关联issue | ||
| 6 | - 查看/读取 issue:查看issue、看看issue、读取issue、打开issue、issue详情、issue是什么 | 7 | - 查看/读取 issue:查看issue、看看issue、读取issue、打开issue、issue详情、issue是什么 |
| 7 | - GitCode URL:gitcode.com/**/issues/**、issue链接 | 8 | - GitCode URL:gitcode.com/**/issues/**、issue链接 |
| 8 | - 直接说编号:issue 123、#123、问题123 | 9 | - 直接说编号:issue 123、#123、问题123 |
| 9 | - 查看评论:issue评论、评论内容 | 10 | - 查看评论:issue评论、评论内容 |
| 10 | 11 | ||
| 11 | -**重要**:不要使用 WebFetch 或 curl,内容通过 JavaScript 动态加载。使用 GitCode API 获取。' | 12 | +**重要**:不要使用 WebFetch 读取页面,内容通过 JavaScript 动态加载。使用 GitCode API 获取。' |
| 12 | --- | 13 | --- |
| 13 | 14 | ||
| 14 | -# GitCode Issue 读取器 | 15 | +# GitCode Issue 工具 |
| 15 | 16 | ||
| 16 | -此技能提供 GitCode API 集成,用于读取和分析 GitCode 项目中的 issues。 | 17 | +此技能提供 GitCode API 集成,用于创建、读取和分析 GitCode 项目中的 issues。 |
| 17 | 18 | ||
| 18 | ## 快速开始 | 19 | ## 快速开始 |
| 19 | **第一步**:看环境变量 GITCODE_API_TOKEN 是否存在,如果不存在执行第二步,如果存在,执行第三步 | 20 | **第一步**:看环境变量 GITCODE_API_TOKEN 是否存在,如果不存在执行第二步,如果存在,执行第三步 |
| @@ -22,7 +23,8 @@ description: '读取 GitCode issue 详情和评论。当用户提到 GitCode iss | |||
| 22 | 获取令牌步骤: | 23 | 获取令牌步骤: |
| 23 | 1. 登录 [GitCode](https://gitcode.com) | 24 | 1. 登录 [GitCode](https://gitcode.com) |
| 24 | 2. 点击头像 → 设置 → 访问令牌 | 25 | 2. 点击头像 → 设置 → 访问令牌 |
| 25 | -3. 创建新令牌,选择 `read_repository` 权限 | 26 | +3. 创建新令牌。读取 Issue 至少需要 `read_repository`;创建或修改 Issue 还需要 `read_api`、 |
| 27 | + `write_repository` 或完整 `api` 权限(以 GitCode 页面实际提供的权限项为准) | ||
| 26 | 4. 复制并安全保存你的令牌 | 28 | 4. 复制并安全保存你的令牌 |
| 27 | 5. 建议保存在 ~/.bashrc中, export GITCODE_API_TOKEN="your_token_here" | 29 | 5. 建议保存在 ~/.bashrc中, export GITCODE_API_TOKEN="your_token_here" |
| 28 | 30 | ||
| @@ -39,10 +41,73 @@ GitCode API 需要私有令牌才能访问: | |||
| 39 | - 将 `YOUR_TOKEN` 替换为你的实际访问令牌 | 41 | - 将 `YOUR_TOKEN` 替换为你的实际访问令牌 |
| 40 | 42 | ||
| 41 | ### API 端点 | 43 | ### API 端点 |
| 44 | +- **当前用户**:`GET /api/v5/user` | ||
| 45 | +- **创建 Issue**:`POST /api/v5/repos/{owner}/{repo}/issues` | ||
| 42 | - **单个 Issue**:`GET /api/v5/repos/{owner}/{repo}/issues/{number}` | 46 | - **单个 Issue**:`GET /api/v5/repos/{owner}/{repo}/issues/{number}` |
| 43 | - **Issue 列表**:`GET /api/v5/repos/{owner}/{repo}/issues` | 47 | - **Issue 列表**:`GET /api/v5/repos/{owner}/{repo}/issues` |
| 44 | - **Issue 评论**:`GET /api/v5/repos/{owner}/{repo}/issues/{number}/comments` | 48 | - **Issue 评论**:`GET /api/v5/repos/{owner}/{repo}/issues/{number}/comments` |
| 45 | 49 | ||
| 50 | +## 创建 Issue | ||
| 51 | + | ||
| 52 | +### 1. 读取仓库模板 | ||
| 53 | + | ||
| 54 | +创建前必须读取仓库 `.gitcode/ISSUE_TEMPLATE/` 下与需求类型匹配的模板,并按模板字段生成标题和正文。 | ||
| 55 | +不要保留模板中的提示文本。常见模板类型包括 bug、requirement、documentation 和 question。 | ||
| 56 | + | ||
| 57 | +### 2. 获取当前 token 用户 | ||
| 58 | + | ||
| 59 | +新建 Issue 默认指派给当前 token 用户。不要硬编码用户名,通过 API 获取: | ||
| 60 | + | ||
| 61 | +```bash | ||
| 62 | +CURRENT_USER=$(curl -sS --fail-with-body \ | ||
| 63 | + -H "private-token: $GITCODE_API_TOKEN" \ | ||
| 64 | + "https://gitcode.com/api/v5/user" | jq -r '.login') | ||
| 65 | +test -n "$CURRENT_USER" && test "$CURRENT_USER" != "null" | ||
| 66 | +``` | ||
| 67 | + | ||
| 68 | +### 3. 创建并默认指派给自己 | ||
| 69 | + | ||
| 70 | +GitCode 的 Issue 创建接口使用表单参数。创建请求必须携带 `assignee`,值为上一步获取的当前用户名: | ||
| 71 | + | ||
| 72 | +```bash | ||
| 73 | +curl -sS --fail-with-body -X POST \ | ||
| 74 | + -H "private-token: $GITCODE_API_TOKEN" \ | ||
| 75 | + "https://gitcode.com/api/v5/repos/${owner}/${repo}/issues" \ | ||
| 76 | + --data-urlencode "title=${ISSUE_TITLE}" \ | ||
| 77 | + --data-urlencode "body=${ISSUE_BODY}" \ | ||
| 78 | + --data-urlencode "labels=${ISSUE_LABELS}" \ | ||
| 79 | + --data-urlencode "assignee=${CURRENT_USER}" | ||
| 80 | +``` | ||
| 81 | + | ||
| 82 | +除非用户明确指定其他人,否则不得省略默认 assignee。若用户指定其他 assignee,以用户要求为准。 | ||
| 83 | + | ||
| 84 | +### 4. 创建后校验 assignee | ||
| 85 | + | ||
| 86 | +不能只依赖创建或更新接口的 HTTP 状态。GitCode 可能已经完成指派,但返回非 2xx 响应。创建后必须重新读取 Issue, | ||
| 87 | +以最终资源状态为准: | ||
| 88 | + | ||
| 89 | +```bash | ||
| 90 | +ISSUE_JSON=$(curl -sS --fail-with-body \ | ||
| 91 | + -H "private-token: $GITCODE_API_TOKEN" \ | ||
| 92 | + "https://gitcode.com/api/v5/repos/${owner}/${repo}/issues/${ISSUE_NUMBER}") | ||
| 93 | + | ||
| 94 | +jq -e --arg login "$CURRENT_USER" \ | ||
| 95 | + '.assignees // [] | any(.login == $login)' <<<"$ISSUE_JSON" | ||
| 96 | +``` | ||
| 97 | + | ||
| 98 | +如果校验失败,使用单值 `assignee` 参数补做更新,然后再次 GET 校验: | ||
| 99 | + | ||
| 100 | +```bash | ||
| 101 | +curl -sS -X PATCH \ | ||
| 102 | + -H "private-token: $GITCODE_API_TOKEN" \ | ||
| 103 | + "https://gitcode.com/api/v5/repos/${owner}/${repo}/issues/${ISSUE_NUMBER}" \ | ||
| 104 | + --data-urlencode "assignee=${CURRENT_USER}" || true | ||
| 105 | + | ||
| 106 | +# PATCH 的响应不能作为最终结论,必须重新 GET 并检查 assignees[].login。 | ||
| 107 | +``` | ||
| 108 | + | ||
| 109 | +如果最终仍未指派,明确报告仓库角色或 Issue 指派权限不足,不得声称创建流程已完整完成。 | ||
| 110 | + | ||
| 46 | ### 响应格式 | 111 | ### 响应格式 |
| 47 | Issues API 返回包含以下关键字段的 JSON: | 112 | Issues API 返回包含以下关键字段的 JSON: |
| 48 | - `number`:Issue ID | 113 | - `number`:Issue ID |