mirror of
https://gitea.com/gitea/tea.git
synced 2026-03-13 09:13:30 +01:00
feat(repos): add repo edit subcommand (#928)
## Summary - Add `tea repo edit` subcommand to update repository properties via the Gitea API - Support flags: `--name`, `--description`/`--desc`, `--website`, `--private`, `--template`, `--archived`, `--default-branch` - Boolean-like flags use string type to distinguish "not set" from "false", following the pattern in `releases/edit.go` ## Test plan - [x] `go build ./...` passes - [x] `go vet ./...` passes - [x] `tea repo edit --help` shows all flags correctly - [x] Manual test: `tea repo edit --private true` on a test repo - [x] Manual test: `tea repo edit --name new-name --description "new desc"` on a test repo Reviewed-on: https://gitea.com/gitea/tea/pulls/928 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com> Co-committed-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
@@ -32,6 +32,7 @@ var CmdRepos = cli.Command{
|
|||||||
&repos.CmdRepoFork,
|
&repos.CmdRepoFork,
|
||||||
&repos.CmdRepoMigrate,
|
&repos.CmdRepoMigrate,
|
||||||
&repos.CmdRepoRm,
|
&repos.CmdRepoRm,
|
||||||
|
&repos.CmdRepoEdit,
|
||||||
},
|
},
|
||||||
Flags: repos.CmdReposListFlags,
|
Flags: repos.CmdReposListFlags,
|
||||||
}
|
}
|
||||||
|
|||||||
106
cmd/repos/edit.go
Normal file
106
cmd/repos/edit.go
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package repos
|
||||||
|
|
||||||
|
import (
|
||||||
|
stdctx "context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"code.gitea.io/tea/cmd/flags"
|
||||||
|
"code.gitea.io/tea/modules/context"
|
||||||
|
"code.gitea.io/tea/modules/print"
|
||||||
|
|
||||||
|
"code.gitea.io/sdk/gitea"
|
||||||
|
"github.com/urfave/cli/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CmdRepoEdit represents a sub command of repos to edit one
|
||||||
|
var CmdRepoEdit = cli.Command{
|
||||||
|
Name: "edit",
|
||||||
|
Aliases: []string{"e"},
|
||||||
|
Usage: "Edit repository properties",
|
||||||
|
Description: "Edit repository properties",
|
||||||
|
ArgsUsage: " ", // command does not accept arguments
|
||||||
|
Action: runRepoEdit,
|
||||||
|
Flags: append([]cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "name",
|
||||||
|
Usage: "New name of the repository",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "description",
|
||||||
|
Aliases: []string{"desc"},
|
||||||
|
Usage: "New description of the repository",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "website",
|
||||||
|
Usage: "New website URL of the repository",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "private",
|
||||||
|
Usage: "Set private [true/false]",
|
||||||
|
DefaultText: "true",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "template",
|
||||||
|
Usage: "Set template [true/false]",
|
||||||
|
DefaultText: "true",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "archived",
|
||||||
|
Usage: "Set archived [true/false]",
|
||||||
|
DefaultText: "true",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "default-branch",
|
||||||
|
Usage: "Set default branch",
|
||||||
|
},
|
||||||
|
}, flags.AllDefaultFlags...),
|
||||||
|
}
|
||||||
|
|
||||||
|
func runRepoEdit(_ stdctx.Context, cmd *cli.Command) error {
|
||||||
|
ctx := context.InitCommand(cmd)
|
||||||
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||||
|
client := ctx.Login.Client()
|
||||||
|
|
||||||
|
opts := gitea.EditRepoOption{}
|
||||||
|
|
||||||
|
if ctx.IsSet("name") {
|
||||||
|
val := ctx.String("name")
|
||||||
|
opts.Name = &val
|
||||||
|
}
|
||||||
|
if ctx.IsSet("description") {
|
||||||
|
val := ctx.String("description")
|
||||||
|
opts.Description = &val
|
||||||
|
}
|
||||||
|
if ctx.IsSet("website") {
|
||||||
|
val := ctx.String("website")
|
||||||
|
opts.Website = &val
|
||||||
|
}
|
||||||
|
if ctx.IsSet("default-branch") {
|
||||||
|
val := ctx.String("default-branch")
|
||||||
|
opts.DefaultBranch = &val
|
||||||
|
}
|
||||||
|
if ctx.IsSet("private") {
|
||||||
|
opts.Private = gitea.OptionalBool(strings.ToLower(ctx.String("private"))[:1] == "t")
|
||||||
|
}
|
||||||
|
if ctx.IsSet("template") {
|
||||||
|
opts.Template = gitea.OptionalBool(strings.ToLower(ctx.String("template"))[:1] == "t")
|
||||||
|
}
|
||||||
|
if ctx.IsSet("archived") {
|
||||||
|
opts.Archived = gitea.OptionalBool(strings.ToLower(ctx.String("archived"))[:1] == "t")
|
||||||
|
}
|
||||||
|
|
||||||
|
repo, _, err := client.EditRepo(ctx.Owner, ctx.Repo, opts)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
topics, _, err := client.ListRepoTopics(repo.Owner.UserName, repo.Name, gitea.ListRepoTopicsOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
print.RepoDetails(repo, topics)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
26
docs/CLI.md
26
docs/CLI.md
@@ -1199,6 +1199,32 @@ Delete an existing repository
|
|||||||
|
|
||||||
**--owner, -O**="": owner of the repo
|
**--owner, -O**="": owner of the repo
|
||||||
|
|
||||||
|
### edit, e
|
||||||
|
|
||||||
|
Edit repository properties
|
||||||
|
|
||||||
|
**--archived**="": Set archived [true/false]
|
||||||
|
|
||||||
|
**--default-branch**="": Set default branch
|
||||||
|
|
||||||
|
**--description, --desc**="": New description of the repository
|
||||||
|
|
||||||
|
**--login, -l**="": Use a different Gitea Login. Optional
|
||||||
|
|
||||||
|
**--name**="": New name of the repository
|
||||||
|
|
||||||
|
**--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json)
|
||||||
|
|
||||||
|
**--private**="": Set private [true/false]
|
||||||
|
|
||||||
|
**--remote, -R**="": Discover Gitea login from remote. Optional
|
||||||
|
|
||||||
|
**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional
|
||||||
|
|
||||||
|
**--template**="": Set template [true/false]
|
||||||
|
|
||||||
|
**--website**="": New website URL of the repository
|
||||||
|
|
||||||
## branches, branch, b
|
## branches, branch, b
|
||||||
|
|
||||||
Consult branches
|
Consult branches
|
||||||
|
|||||||
Reference in New Issue
Block a user