feat(branch): add +all and +set-default
- branch +all: full branch-name list via GET /branches/all (AllListService), no paging — handy for scripting and completion. - branch +set-default: switch the repository default branch via PATCH /branches/update_default_branch (manager permission), which the CLI previously had no way to do. Production-verified on gitlink.org.cn (full name list returned; default branch update status 0). 2 unit tests, README examples, bilingual i18n keys. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
c09645da62
commit
f0e72d8a6c
|
|
@ -446,6 +446,10 @@ gitlink-cli branch +create --name feature/new-feature
|
|||
# Delete a branch
|
||||
gitlink-cli branch +delete --name feature/old-feature
|
||||
|
||||
# All branch names at once (no paging) and default-branch switch
|
||||
gitlink-cli branch +all --owner myname --repo myrepo
|
||||
gitlink-cli branch +set-default --owner myname --repo myrepo -n develop
|
||||
|
||||
# Protect a branch
|
||||
gitlink-cli branch +protect --name main
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@
|
|||
"cmd.auth.logout.short": "Logout from GitLink",
|
||||
"cmd.auth.short": "Authentication commands",
|
||||
"cmd.auth.status.short": "Show authentication status",
|
||||
"cmd.branch.all.short": "List all branch names (no paging)",
|
||||
"cmd.branch.create.short": "Create a branch",
|
||||
"cmd.branch.delete.short": "Delete a branch",
|
||||
"cmd.branch.list.short": "List branches",
|
||||
"cmd.branch.protect.short": "Set branch protection",
|
||||
"cmd.branch.set_default.short": "Set the repository default branch",
|
||||
"cmd.branch.short": "Branch operations",
|
||||
"cmd.branch.unprotect.short": "Remove branch protection",
|
||||
"cmd.ci.builds.short": "List CI builds",
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@
|
|||
"cmd.auth.logout.short": "退出 GitLink 登录",
|
||||
"cmd.auth.short": "认证命令",
|
||||
"cmd.auth.status.short": "显示认证状态",
|
||||
"cmd.branch.all.short": "列出全部分支名(不分页)",
|
||||
"cmd.branch.create.short": "创建分支",
|
||||
"cmd.branch.delete.short": "删除分支",
|
||||
"cmd.branch.list.short": "列出分支",
|
||||
"cmd.branch.protect.short": "设置分支保护",
|
||||
"cmd.branch.set_default.short": "设置仓库默认分支",
|
||||
"cmd.branch.short": "分支操作",
|
||||
"cmd.branch.unprotect.short": "移除分支保护",
|
||||
"cmd.ci.builds.short": "列出 CI 构建",
|
||||
|
|
|
|||
|
|
@ -80,6 +80,42 @@ func Shortcuts(translators ...*i18n.Translator) []*common.Shortcut {
|
|||
return ctx.Output(env)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "all",
|
||||
Description: tr.T("cmd.branch.all.short"),
|
||||
Flags: []common.Flag{},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
env, err := ctx.CallAPI("GET", "/v1"+ctx.RepoPath()+"/branches/all", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.Output(env)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "set-default",
|
||||
Description: tr.T("cmd.branch.set_default.short"),
|
||||
Flags: []common.Flag{
|
||||
{Name: "name", Short: "n", Usage: tr.T("flag.branch.name"), Required: true},
|
||||
},
|
||||
Run: func(ctx *common.RuntimeContext) error {
|
||||
if err := ctx.ResolveOwnerRepo(); err != nil {
|
||||
return err
|
||||
}
|
||||
name, err := ctx.RequireArg("name")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
env, err := ctx.CallAPI("PATCH", "/v1"+ctx.RepoPath()+"/branches/update_default_branch", map[string]interface{}{"name": name})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.Output(env)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "protect",
|
||||
Description: tr.T("cmd.branch.protect.short"),
|
||||
|
|
|
|||
|
|
@ -216,3 +216,38 @@ func TestBranchUnprotectHTTPError(t *testing.T) {
|
|||
t.Fatal("expected error for HTTP 500")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBranchAllUsesAllEndpoint(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "GET" || r.URL.Path != "/v1/owner/repo/branches/all.json" {
|
||||
t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
writeJSON(w, []interface{}{map[string]interface{}{"name": "master"}})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
if err := runShortcut(t, server, "all", nil); err != nil {
|
||||
t.Fatalf("all failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBranchSetDefaultPatchesName(t *testing.T) {
|
||||
var payload map[string]interface{}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "PATCH" || r.URL.Path != "/v1/owner/repo/branches/update_default_branch.json" {
|
||||
t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
||||
t.Fatalf("decode payload: %v", err)
|
||||
}
|
||||
writeJSON(w, map[string]interface{}{"status": float64(0), "message": "success"})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
if err := runShortcut(t, server, "set-default", map[string]string{"name": "develop"}); err != nil {
|
||||
t.Fatalf("set-default failed: %v", err)
|
||||
}
|
||||
if payload["name"] != "develop" {
|
||||
t.Fatalf("expected name=develop, got %v", payload["name"])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue