From a531faa626a14a6a27134c526165d43dabbe749c Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 12 Mar 2026 03:06:44 +0000 Subject: [PATCH] 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 Co-authored-by: Bo-Yi Wu Co-committed-by: Bo-Yi Wu --- cmd/repos.go | 1 + cmd/repos/edit.go | 106 ++++++++++++++++++++++++++++++++++++++++++++++ docs/CLI.md | 26 ++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 cmd/repos/edit.go diff --git a/cmd/repos.go b/cmd/repos.go index 2ab1ab7..a192191 100644 --- a/cmd/repos.go +++ b/cmd/repos.go @@ -32,6 +32,7 @@ var CmdRepos = cli.Command{ &repos.CmdRepoFork, &repos.CmdRepoMigrate, &repos.CmdRepoRm, + &repos.CmdRepoEdit, }, Flags: repos.CmdReposListFlags, } diff --git a/cmd/repos/edit.go b/cmd/repos/edit.go new file mode 100644 index 0000000..aa7d4bc --- /dev/null +++ b/cmd/repos/edit.go @@ -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 +} diff --git a/docs/CLI.md b/docs/CLI.md index f79580f..9ede576 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -1199,6 +1199,32 @@ Delete an existing repository **--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 Consult branches