feat: 新增仓库转移快捷命令
This commit is contained in:
parent
52b7093846
commit
10d88360d9
|
|
@ -244,6 +244,15 @@ gitlink-cli repo +create -n my-project -d "Project description"
|
|||
|
||||
# Fork a repository
|
||||
gitlink-cli repo +fork --owner Gitlink --repo forgeplus
|
||||
|
||||
# List organizations that can receive a repository transfer
|
||||
gitlink-cli repo +transfer-orgs --owner Gitlink --repo forgeplus
|
||||
|
||||
# Preview a repository transfer without changing data
|
||||
gitlink-cli repo +transfer --owner Gitlink --repo forgeplus --target-owner my-org --dry-run
|
||||
|
||||
# Cancel a pending repository transfer
|
||||
gitlink-cli repo +transfer-cancel --owner Gitlink --repo forgeplus --dry-run
|
||||
```
|
||||
|
||||
### Webhook Management
|
||||
|
|
|
|||
|
|
@ -255,6 +255,15 @@ gitlink-cli repo +create -n my-project -d "项目描述"
|
|||
|
||||
# Fork 仓库
|
||||
gitlink-cli repo +fork --owner Gitlink --repo forgeplus
|
||||
|
||||
# 列出可接收仓库转移的组织
|
||||
gitlink-cli repo +transfer-orgs --owner Gitlink --repo forgeplus
|
||||
|
||||
# 预览仓库转移请求,不修改线上数据
|
||||
gitlink-cli repo +transfer --owner Gitlink --repo forgeplus --target-owner my-org --dry-run
|
||||
|
||||
# 取消待处理的仓库转移
|
||||
gitlink-cli repo +transfer-cancel --owner Gitlink --repo forgeplus --dry-run
|
||||
```
|
||||
|
||||
### Webhook 管理
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
# 仓库转移 Shortcut
|
||||
|
||||
本次变更为 `repo` 命令组补齐 GitLink 项目转移发起端能力:
|
||||
|
||||
- `repo +transfer-orgs`:列出当前仓库可转移到的组织。
|
||||
- `repo +transfer`:向目标用户或组织发起仓库转移申请。
|
||||
- `repo +transfer-cancel`:取消待处理的仓库转移申请。
|
||||
|
||||
这组命令覆盖仓库所有者侧的转移流程,和用户待办审批侧的接受/拒绝转移申请互补。维护者在迁移项目归属、把个人仓库移交给组织、或由 Agent 编排仓库治理流程时,不再需要手写 Raw API。
|
||||
|
||||
`repo +transfer` 和 `repo +transfer-cancel` 都支持 `--dry-run`,会输出将要请求的 method、path 和 payload,不修改线上数据,便于在执行高风险操作前确认目标仓库和目标所有者。
|
||||
|
||||
单元测试覆盖了 API method/path、转移 payload、缺少目标所有者校验,以及 dry-run 不触发远端请求;README、中文 README 和 `gitlink-repo` Skill 已同步补充示例。
|
||||
|
|
@ -228,5 +228,11 @@
|
|||
"success.config.set": "✓ {key} = {value}",
|
||||
"warning.auth.not_logged_in": "✗ Not logged in",
|
||||
"warning.auth.token_unverified": "✓ Token stored (but cannot verify: {message})",
|
||||
"warning.auth.user_unavailable": "✓ Token stored (user info unavailable)"
|
||||
"warning.auth.user_unavailable": "✓ Token stored (user info unavailable)",
|
||||
"cmd.repo.transfer_orgs.short": "List organizations that can receive this repository",
|
||||
"cmd.repo.transfer.short": "Transfer a repository to another owner",
|
||||
"cmd.repo.transfer_cancel.short": "Cancel a pending repository transfer",
|
||||
"flag.repo.target_owner": "Target user or organization login",
|
||||
"flag.repo.transfer_dry_run": "Preview the transfer request without changing repository ownership",
|
||||
"flag.repo.transfer_cancel_dry_run": "Preview the cancel request without changing repository transfer state"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -228,5 +228,11 @@
|
|||
"success.config.set": "✓ 已设置 {key} = {value}",
|
||||
"warning.auth.not_logged_in": "✗ 未登录",
|
||||
"warning.auth.token_unverified": "✓ Token 已保存(但无法验证:{message})",
|
||||
"warning.auth.user_unavailable": "✓ Token 已保存(用户信息不可用)"
|
||||
"warning.auth.user_unavailable": "✓ Token 已保存(用户信息不可用)",
|
||||
"cmd.repo.transfer_orgs.short": "列出可接收该仓库的组织",
|
||||
"cmd.repo.transfer.short": "将仓库转移给其他所有者",
|
||||
"cmd.repo.transfer_cancel.short": "取消待处理的仓库转移",
|
||||
"flag.repo.target_owner": "目标用户或组织登录名",
|
||||
"flag.repo.transfer_dry_run": "预览转移请求,不修改仓库所有者",
|
||||
"flag.repo.transfer_cancel_dry_run": "预览取消请求,不修改仓库转移状态"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -239,6 +239,82 @@ func Shortcuts(translators ...*i18n.Translator) []*common.Shortcut {
|
|||
return ctx.Output(env)
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
Name: "transfer-orgs",
|
||||
Description: tr.T("cmd.repo.transfer_orgs.short"),
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
env, err := ctx.CallAPI("GET", repoTransferPath(ctx, "organizations"), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.Output(env)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "transfer",
|
||||
Description: tr.T("cmd.repo.transfer.short"),
|
||||
Flags: []common.Flag{
|
||||
{Name: "target-owner", Usage: tr.T("flag.repo.target_owner"), Required: true},
|
||||
{Name: "dry-run", Usage: tr.T("flag.repo.transfer_dry_run"), Bool: true, Default: "false"},
|
||||
},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
targetOwner, err := ctx.RequireArg("target-owner")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
targetOwner = strings.TrimSpace(targetOwner)
|
||||
if targetOwner == "" {
|
||||
return fmt.Errorf("required flag --target-owner is missing")
|
||||
}
|
||||
payload := map[string]interface{}{"owner_name": targetOwner}
|
||||
path := repoTransferPath(ctx, "")
|
||||
if ctx.Arg("dry-run") == "true" {
|
||||
return ctx.OutputData(map[string]interface{}{
|
||||
"dry_run": true,
|
||||
"method": "POST",
|
||||
"path": path,
|
||||
"payload": payload,
|
||||
})
|
||||
}
|
||||
env, err := ctx.CallAPI("POST", path, payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.Output(env)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "transfer-cancel",
|
||||
Description: tr.T("cmd.repo.transfer_cancel.short"),
|
||||
Flags: []common.Flag{
|
||||
{Name: "dry-run", Usage: tr.T("flag.repo.transfer_cancel_dry_run"), Bool: true, Default: "false"},
|
||||
},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
path := repoTransferPath(ctx, "cancel")
|
||||
if ctx.Arg("dry-run") == "true" {
|
||||
return ctx.OutputData(map[string]interface{}{
|
||||
"dry_run": true,
|
||||
"method": "POST",
|
||||
"path": path,
|
||||
})
|
||||
}
|
||||
env, err := ctx.CallAPI("POST", path, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.Output(env)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "delete",
|
||||
Description: tr.T("cmd.repo.delete.short"),
|
||||
|
|
@ -256,6 +332,14 @@ func Shortcuts(translators ...*i18n.Translator) []*common.Shortcut {
|
|||
}
|
||||
}
|
||||
|
||||
func repoTransferPath(ctx *common.RuntimeContext, action string) string {
|
||||
base := ctx.RepoPath() + "/applied_transfer_projects"
|
||||
if action == "" {
|
||||
return base
|
||||
}
|
||||
return fmt.Sprintf("%s/%s", base, action)
|
||||
}
|
||||
|
||||
func shortcutTranslator(translators ...*i18n.Translator) *i18n.Translator {
|
||||
if len(translators) > 0 && translators[0] != nil {
|
||||
return translators[0]
|
||||
|
|
|
|||
|
|
@ -430,6 +430,102 @@ func TestRepoDelete(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRepoTransferOrgs(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
assertRequest(t, r, "GET", "/owner/repo/applied_transfer_projects/organizations.json")
|
||||
writeJSON(t, w, map[string]interface{}{
|
||||
"total_count": float64(1),
|
||||
"organizations": []interface{}{map[string]interface{}{"name": "target-org"}},
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
if err := runShortcut(t, server, "transfer-orgs", nil); err != nil {
|
||||
t.Fatalf("transfer-orgs failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoTransfer(t *testing.T) {
|
||||
var body map[string]interface{}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
assertRequest(t, r, "POST", "/owner/repo/applied_transfer_projects.json")
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
t.Fatalf("decode body: %v", err)
|
||||
}
|
||||
writeJSON(t, w, map[string]interface{}{"status": "common"})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
err := runShortcut(t, server, "transfer", map[string]string{"target-owner": " target-org "})
|
||||
if err != nil {
|
||||
t.Fatalf("transfer failed: %v", err)
|
||||
}
|
||||
assertEqual(t, body["owner_name"], "target-org")
|
||||
}
|
||||
|
||||
func TestRepoTransferDryRunDoesNotCallAPI(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
t.Fatalf("dry-run should not call API, got %s %s", r.Method, r.URL.Path)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
err := runShortcut(t, server, "transfer", map[string]string{
|
||||
"target-owner": "target-org",
|
||||
"dry-run": "true",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("transfer dry-run failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoTransferFailsWithoutTargetOwner(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
t.Fatal("no API call should be made")
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
err := runShortcut(t, server, "transfer", map[string]string{})
|
||||
if err == nil {
|
||||
t.Fatal("expected error for missing target owner")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoTransferRejectsBlankTargetOwner(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
t.Fatal("no API call should be made")
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
err := runShortcut(t, server, "transfer", map[string]string{"target-owner": " "})
|
||||
if err == nil {
|
||||
t.Fatal("expected error for blank target owner")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoTransferCancel(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
assertRequest(t, r, "POST", "/owner/repo/applied_transfer_projects/cancel.json")
|
||||
writeJSON(t, w, map[string]interface{}{"status": "canceled"})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
if err := runShortcut(t, server, "transfer-cancel", nil); err != nil {
|
||||
t.Fatalf("transfer-cancel failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoTransferCancelDryRunDoesNotCallAPI(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
t.Fatalf("dry-run should not call API, got %s %s", r.Method, r.URL.Path)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
err := runShortcut(t, server, "transfer-cancel", map[string]string{"dry-run": "true"})
|
||||
if err != nil {
|
||||
t.Fatalf("transfer-cancel dry-run failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepoCreate(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ metadata:
|
|||
| `repo +create` | 创建仓库 | 是 |
|
||||
| `repo +fork` | Fork 仓库 | 是 |
|
||||
| `repo +delete` | 删除仓库 | 是 |
|
||||
| `repo +transfer-orgs` | 列出可接收仓库转移的组织 | 是 |
|
||||
| `repo +transfer` | 发起仓库转移 | 是 |
|
||||
| `repo +transfer-cancel` | 取消待处理的仓库转移 | 是 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
|
|
@ -78,6 +81,18 @@ gitlink-cli repo +create --name my-project --description "项目描述"
|
|||
# Fork 仓库
|
||||
gitlink-cli repo +fork --owner Gitlink --repo forgeplus
|
||||
|
||||
# 查看仓库可转移到哪些组织
|
||||
gitlink-cli repo +transfer-orgs --owner Gitlink --repo forgeplus
|
||||
|
||||
# 预览仓库转移请求,不修改线上数据
|
||||
gitlink-cli repo +transfer --owner Gitlink --repo forgeplus --target-owner my-org --dry-run
|
||||
|
||||
# 确认后发起仓库转移
|
||||
gitlink-cli repo +transfer --owner Gitlink --repo forgeplus --target-owner my-org
|
||||
|
||||
# 取消待处理的仓库转移
|
||||
gitlink-cli repo +transfer-cancel --owner Gitlink --repo forgeplus --dry-run
|
||||
|
||||
# 删除仓库(⚠️ 危险操作)
|
||||
gitlink-cli repo +delete --owner myuser --repo old-project
|
||||
```
|
||||
|
|
@ -100,4 +115,6 @@ gitlink-cli api GET /:owner/:repo/raw/main/README.md
|
|||
## 注意事项
|
||||
|
||||
- `repo +delete` 是不可逆操作,执行前必须确认用户意图
|
||||
- `repo +transfer` 会改变仓库所有者,执行前先使用 `repo +transfer-orgs` 确认可转移目标,并用 `--dry-run` 预览请求
|
||||
- `repo +transfer-cancel` 只用于取消已发起且未处理的转移申请,建议先用 `--dry-run` 预览
|
||||
- 创建仓库默认为公开,使用 `--private true` 创建私有仓库
|
||||
|
|
|
|||
Loading…
Reference in New Issue