feat(pr): merge with the repository's defaults, ready, gh flags and ✓ lines for pr mutations

pr merge takes the method from the repository's default merge style
instead of always merging (D22), accepts gh's --merge, --squash and
--rebase next to -s/--method, refuses methods the repository disables,
and adds -d/--delete-branch (defaulting to the repository setting),
--auto, -t, -b, -F and -e. On a terminal it asks for the method and
branch deletion with the defaults preselected, without a picker when
the current branch has a pull request. It reports "✓ Squashed and
merged pull request alice/x#3 (title)", the deleted remote branch, and
switches off and deletes the local head branch; --json returns the
merged pull request. Merged, closed and draft pull requests are
reported before anything is asked. -s without a value points at
--squash.

pr checkout names the local branch after the head branch when that
name is free or already at the head, falling back to OWNER/BRANCH for
forks and pr/NUMBER (D13), fetches and switches quietly, reports
"✓ Checked out #1 into feat/one", and has the alias co. pr clean
reports what it deleted and that a remote branch was already gone.

pr create asks for the title and body, then "What's next?": submit,
submit as a draft, add metadata or change the branches, without the
AGit question up front or a final confirmation. It pushes an unpushed
head with --set-upstream --quiet ("✓ Pushed feat/one to origin"),
prints "✓ Created pull request alice/x#9 (title)" and the URL, and
adds --fill, --web, the alias new, the gh shorthands, and milestones
by title.

New tea pr ready [--undo]. pr close and reopen take -c/--comment,
close takes -d/--delete-branch, and both say when the pull request
already is in that state. pr edit reports "✓ Edited", takes the
singular gh reviewer flags (the plurals still work), milestones by
title and --remove-milestone. pr diff is colored and paged on a
terminal and byte-exact when piped, with --name-only, --color and
--web. Every pull request argument accepts #N, URLs and branch names
and defaults to the current branch's pull request.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-11 23:55:11 +02:00
1 parent 2c5e005bcf
commit 4895aa089d
28 files changed
+1169 -504

No files matched your search

+21 -23
View File
@@ -13,17 +13,14 @@ import (
"gitea.dev/tea/internal/git"
"gitea.dev/tea/internal/services"
"gitea.dev/tea/internal/settings"
"gitea.dev/tea/internal/terminal"
"github.com/spf13/cobra"
)
func (a *application) pullCleanCommand() *cobra.Command {
var ignoreSHA bool
cmd := &cobra.Command{Use: "clean <number>", Short: "Delete local and remote feature branches for a closed pull request", Args: argsExact(1), RunE: func(cmd *cobra.Command, args []string) error {
n, err := number(args[0])
if err != nil {
return err
}
target, err := a.resolve(cmd.Context(), true)
cmd := &cobra.Command{Use: "clean [<number> | <url> | <branch>]", Short: "Delete the branches of a merged or closed pull request", Annotations: pullArgumentsAnnotation(map[string]string{"tea.confirm": "true"}), Args: usageArgs(cobra.MaximumNArgs(1)), RunE: func(cmd *cobra.Command, args []string) error {
target, n, err := a.pullSelector(cmd, args)
if err != nil {
return err
}
@@ -87,14 +84,15 @@ func (a *application) pullCleanCommand() *cobra.Command {
return err
}
}
description := fmt.Sprintf("Delete local branch %q for pull request %s#%d", localBranch, target.Repo, n)
if ignoreSHA {
description += " (matched by name; local commits not in the pull request are lost)"
}
description := fmt.Sprintf("Delete local branch %s of %s", localBranch, refLabel(target.Repo, n, pull.Title))
if deleteRemote {
description += fmt.Sprintf(" and remote branch %q", remote+"/"+pull.Head)
description += fmt.Sprintf(" and remote branch %s/%s", remote, pull.Head)
}
if err := a.confirm(cmd, description); err != nil {
prompt := description + "?"
if ignoreSHA {
prompt += " Local commits that are not in the pull request are lost."
}
if err := a.confirmAction(cmd, terminal.Confirmation{Prompt: prompt, NonTTY: strings.ToLower(description[:1]) + description[1:]}); err != nil {
return err
}
result, err := git.CleanPull(cmd.Context(), a.deps.Git, git.CleanOptions{
@@ -108,21 +106,21 @@ func (a *application) pullCleanCommand() *cobra.Command {
if a.options.json != "" {
return a.writeJSON(cmd, result)
}
_, err = fmt.Fprintf(cmd.OutOrStdout(), "Deleted local branch %s\n", result.LocalBranch)
if err != nil {
return err
}
if result.RemoteDeleted {
_, err = fmt.Fprintf(cmd.OutOrStdout(), "Deleted remote branch %s/%s\n", result.Remote, result.RemoteBranch)
return err
}
if result.RemoteSkipped {
_, err = fmt.Fprintf(cmd.ErrOrStderr(), "%s\n", result.RemoteSkipReason)
return err
a.done(cmd, "Deleted local branch %s", result.LocalBranch)
switch {
case result.RemoteDeleted:
a.done(cmd, "Deleted remote branch %s/%s", result.Remote, result.RemoteBranch)
case pull.HeadRemoteDeleted:
a.warn(cmd, "Remote branch %s was already deleted", pull.Head)
case !pull.HeadCanPush:
a.warn(cmd, "Kept remote branch %s: you cannot push to %s", pull.Head, pull.HeadRepo)
}
return nil
}}
cmd.Flags().BoolVar(&ignoreSHA, "ignore-sha", false, "Find the local branch by name instead of commit hash")
cmd.ValidArgsFunction = a.completePulls("closed")
cmd.Example = `# After #13 was merged, delete its branch locally and on Gitea
$ tea pr clean 13`
return cmd
}