fix: pr merge requires 'do' param, update skills docs with test findings
Code fixes: - pr +merge: add 'do' parameter (merge/rebase/squash) and --method flag to fix "请选择合并方式" error Skills documentation updates: - gitlink-pr: add complete PR workflow with create_file/update_file, document merge methods, PR status values, state filter behavior - gitlink-shared: update API notes table (release delete now works, create_file needs base64, update_file needs SHA), add file operations API section with create/update/delete examples - gitlink-release: update delete docs (now works with version_id) All 8 scenarios tested and passing (2026-04-04): auth/user ✅, repo ✅, branch ✅(delete=API bug), issue ✅, PR ✅, release ✅, search/org ✅, CI ✅(no config) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
798bc7d18f
commit
66beb075da
|
|
@ -91,13 +91,21 @@ func Shortcuts() []*common.Shortcut {
|
|||
Description: "Merge a pull request",
|
||||
Flags: []common.Flag{
|
||||
{Name: "id", Short: "i", Usage: "PR number", Required: true},
|
||||
{Name: "method", Short: "m", Usage: "Merge method: merge, rebase, squash", Default: "merge"},
|
||||
},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
id, _ := ctx.RequireArg("id")
|
||||
env, err := ctx.CallAPI("POST", fmt.Sprintf("%s/pulls/%s/pr_merge", ctx.RepoPath(), id), nil)
|
||||
method := ctx.Arg("method")
|
||||
if method == "" {
|
||||
method = "merge"
|
||||
}
|
||||
payload := map[string]interface{}{
|
||||
"do": method,
|
||||
}
|
||||
env, err := ctx.CallAPI("POST", fmt.Sprintf("%s/pulls/%s/pr_merge", ctx.RepoPath(), id), payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,25 +26,54 @@ description: "Pull Request 管理:创建、查看、合并、关闭 PR,查
|
|||
# 列出 PR
|
||||
gitlink-cli pr +list --owner Gitlink --repo forgeplus --state open
|
||||
|
||||
# 创建 PR
|
||||
# 创建 PR(源分支必须有实际代码变更)
|
||||
gitlink-cli pr +create --title "feat: 新增搜索功能" --head feature/search --base master --body "实现了全文搜索"
|
||||
|
||||
# 查看 PR 详情
|
||||
gitlink-cli pr +view --id 42
|
||||
# 查看 PR 详情(使用 pull_request_id)
|
||||
gitlink-cli pr +view --id 14200
|
||||
|
||||
# 合并 PR
|
||||
gitlink-cli pr +merge --id 42
|
||||
# 合并 PR(支持 merge/rebase/squash)
|
||||
gitlink-cli pr +merge --id 14200
|
||||
gitlink-cli pr +merge --id 14200 --method squash
|
||||
|
||||
# 关闭 PR(拒绝合并)
|
||||
gitlink-cli pr +close --id 42
|
||||
gitlink-cli pr +close --id 14200
|
||||
|
||||
# 查看变更文件
|
||||
gitlink-cli pr +files --id 42
|
||||
# 查看变更文件(含 diff 内容)
|
||||
gitlink-cli pr +files --id 14200
|
||||
```
|
||||
|
||||
## 创建 PR 的完整流程
|
||||
|
||||
PR 创建需要源分支有实际代码变更。完整流程:
|
||||
|
||||
```bash
|
||||
# 1. 创建分支
|
||||
gitlink-cli branch +create --name feature-branch --from master
|
||||
|
||||
# 2. 在分支上创建/修改文件(content 必须 base64 编码)
|
||||
gitlink-cli api POST /:owner/:repo/create_file --body '{
|
||||
"filepath": "new-file.md",
|
||||
"content": "<base64编码的内容>",
|
||||
"branch": "feature-branch",
|
||||
"message": "add new file"
|
||||
}'
|
||||
|
||||
# 3. 创建 PR
|
||||
gitlink-cli pr +create --title "feat: 新功能" --head feature-branch --base master
|
||||
```
|
||||
|
||||
## Raw API 补充
|
||||
|
||||
```bash
|
||||
# 创建文件(content 必须 base64 编码)
|
||||
gitlink-cli api POST /:owner/:repo/create_file --body '{"filepath":"file.md","content":"<base64>","branch":"dev","message":"add file"}'
|
||||
|
||||
# 更新文件(需要先通过 sub_entries 获取文件 SHA)
|
||||
gitlink-cli api GET /:owner/:repo/sub_entries --query 'filepath=file.md&ref=dev'
|
||||
# 从 entries.sha 获取 SHA,然后:
|
||||
gitlink-cli api PUT /:owner/:repo/update_file --body '{"filepath":"file.md","content":"<base64>","sha":"<sha>","branch":"dev","message":"update file"}'
|
||||
|
||||
# 检查是否可合并
|
||||
gitlink-cli api POST /:owner/:repo/pulls/check_can_merge --body '{"head":"dev","base":"main"}'
|
||||
|
||||
|
|
@ -60,5 +89,8 @@ gitlink-cli api GET /:owner/:repo/pulls/get_branches
|
|||
- GitLink 的默认分支通常是 `master`(非 `main`),创建 PR 时注意 `--base` 参数
|
||||
- 合并 PR 前建议先用 `pr +view` 确认状态
|
||||
- **PR 创建要求源分支与目标分支有实际代码差异**,否则返回"分支内容相同,无需创建合并请求"
|
||||
- PR 查看需要使用 `pull_request_id`(从 `pr +list` 返回),而非列表中的 `id` 字段
|
||||
- `pr +diff` 实际调用 `/pulls/:id/files` 端点,返回变更文件列表(非 unified diff)
|
||||
- PR 查看/合并/关闭需要使用 `pull_request_id`(从 `pr +create` 或 `pr +list` 返回)
|
||||
- `pr +merge` 默认使用 merge 方式,可通过 `--method` 指定 rebase 或 squash
|
||||
- `pr +diff` 实际调用 `/pulls/:id/files` 端点,返回变更文件列表和 diff 内容
|
||||
- `pr +list` 的 `--state` 参数(open/merged/closed)仅影响统计计数,API 返回的列表可能包含所有状态的 PR
|
||||
- PR 状态值:`pull_request_status` 0=open, 1=merged, 2=closed
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@ gitlink-cli release +list --owner myuser --repo myrepo --format json
|
|||
# 从返回的 releases 数组中取 version_id 字段
|
||||
gitlink-cli release +view --id <version_id>
|
||||
|
||||
# 删除发布(⚠️ 当前 GitLink API 有 Bug,可能返回"版本不存在")
|
||||
# 删除发布(使用 version_id)
|
||||
gitlink-cli release +delete --id <version_id>
|
||||
```
|
||||
|
||||
## API 注意事项
|
||||
|
||||
- **`release +view` 必须使用 `version_id`**(从 `release +list` 返回结果中获取),使用 tag_name 会返回 HTML 页面而非 JSON
|
||||
- **`release +delete` 当前不可用**,GitLink API 始终返回"版本不存在"(平台 Bug)
|
||||
- **`release +delete` 使用 `version_id`**,已验证可正常删除
|
||||
- Release 列表中的 `id` 字段可能为 null,应使用 `version_id` 字段
|
||||
|
|
|
|||
|
|
@ -97,12 +97,61 @@ gitlink-cli auth login
|
|||
| Issue 创建需要 `done_ratio` | 创建 Issue 时必须包含 `done_ratio: 0`,否则数据库报错 | `issue +create` 已内置处理 |
|
||||
| Issue 更新需要 `subject` | 任何 Issue 更新(包括只改状态)都必须带上 `subject` 字段 | `issue +close` 已内置处理,Raw API 需手动处理 |
|
||||
| Release 查看需要 `version_id` | `release +view` 必须用 `version_id`(从 `release +list` 获取),不能用 tag_name | tag_name 会返回 HTML 页面 |
|
||||
| Release 删除需要 `version_id` | `release +delete -i <version_id>` 正常工作 | 已验证通过 |
|
||||
| 分支操作需要 `/v1/` 前缀 | 分支的 create/delete/list 端点使用 `/v1/:owner/:repo/branches` | 已内置处理 |
|
||||
| Branch 删除 API 不可用 | `DELETE /v1/:owner/:repo/branches/:name` 始终返回"分支不存在" | GitLink 平台 Bug,暂时无法通过 API 删除分支 |
|
||||
| Release 删除 API 不可用 | `DELETE /:owner/:repo/releases/:id` 返回"版本不存在" | GitLink 平台 Bug |
|
||||
| Create File API 异常 | `POST /:owner/:repo/create_file` 在新分支上也返回"文件已存在" | GitLink 平台 Bug |
|
||||
| Create File 需要 base64 | `POST /:owner/:repo/create_file` 的 `content` 字段必须 base64 编码 | 不编码会返回"文件已存在"错误 |
|
||||
| Update File 需要 SHA | `PUT /:owner/:repo/update_file` 需要 `sha` 参数,通过 `sub_entries` 接口获取 | 见下方文件操作说明 |
|
||||
| PR 合并需要 `do` 参数 | `pr +merge` 需传 `do` 字段指定合并方式(merge/rebase/squash) | `pr +merge` 已内置处理 |
|
||||
| PR 列表 state 过滤 | `--state` 参数仅影响统计计数,返回列表可能包含所有状态 | 需通过 `pull_request_status` 字段客户端过滤:0=open, 1=merged, 2=closed |
|
||||
| PR 创建需要代码差异 | 分支内容必须与目标分支不同,否则拒绝创建 | 需要先在分支上有实际提交 |
|
||||
|
||||
## 文件操作 API
|
||||
|
||||
通过 Raw API 在分支上创建或修改文件(PR 工作流的前置操作):
|
||||
|
||||
### 创建文件
|
||||
|
||||
```bash
|
||||
# content 必须 base64 编码
|
||||
CONTENT=$(echo -n "文件内容" | base64)
|
||||
gitlink-cli api POST /:owner/:repo/create_file --body '{
|
||||
"filepath": "path/to/file.md",
|
||||
"content": "<base64编码>",
|
||||
"branch": "feature-branch",
|
||||
"message": "add new file"
|
||||
}'
|
||||
```
|
||||
|
||||
### 更新文件
|
||||
|
||||
```bash
|
||||
# Step 1: 获取文件 SHA
|
||||
gitlink-cli api GET /:owner/:repo/sub_entries --query 'filepath=path/to/file.md&ref=branch-name'
|
||||
# 从返回的 entries.sha 获取 SHA 值
|
||||
|
||||
# Step 2: 更新文件(content 必须 base64 编码)
|
||||
gitlink-cli api PUT /:owner/:repo/update_file --body '{
|
||||
"filepath": "path/to/file.md",
|
||||
"content": "<base64编码>",
|
||||
"sha": "<从sub_entries获取的sha>",
|
||||
"branch": "feature-branch",
|
||||
"message": "update file"
|
||||
}'
|
||||
```
|
||||
|
||||
### 删除文件
|
||||
|
||||
```bash
|
||||
# 需要文件 SHA
|
||||
gitlink-cli api DELETE /:owner/:repo/delete_file --body '{
|
||||
"filepath": "path/to/file.md",
|
||||
"sha": "<sha>",
|
||||
"branch": "master",
|
||||
"message": "delete file"
|
||||
}'
|
||||
```
|
||||
|
||||
## 分支约定
|
||||
|
||||
GitLink 和 GitHub 使用不同的主分支名称:
|
||||
|
|
|
|||
Loading…
Reference in New Issue