Files
gitea-tea/cmd/pulls/stack/restack.go
Lunny Xiao ba167a7352 feat(pulls): add tea pr stack list|show|push|restack|merge
Adds a CLI client for the Gitea EE pull request stack API
(GET/POST /repos/{owner}/{repo}/stacks[/{id}[/entries|/restack|/merge]]):

- modules/stack holds the Stack/Entry/MergeResult types shared between
  the API client and its output formatting, avoiding an import cycle
  between modules/task and modules/print.
- modules/task/pull_stack.go implements the HTTP calls on top of
  modules/api.Client, which gains a context-aware DoContext method.
- modules/print/pull_stack.go formats stack listings (table/json/...)
  and a single stack's ordered entries.
- cmd/pulls/stack adds the list, show, push, restack and merge
  subcommands, wired in as 'tea pr stack' via cmd/pulls.go, following
  the repo/login flag routing used by the rest of the pulls commands.

Assisted-by: Codet:GPT-5-Codex
2026-09-24 23:24:26 -07:00

53 lines
1.3 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package stack
import (
stdctx "context"
"fmt"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/task"
"gitea.dev/tea/modules/utils"
"github.com/urfave/cli/v3"
)
// CmdStackRestack represents a sub command to queue a stack restack
var CmdStackRestack = cli.Command{
Name: "restack",
Usage: "Queue a pull request stack restack",
Description: "Retarget every open pull request above a merged one in the stack onto its parent's new base",
ArgsUsage: "<stack id>",
Action: RunStackRestack,
Flags: flags.AllDefaultFlags,
}
// RunStackRestack queues a restack of a pull request stack
func RunStackRestack(requestCtx stdctx.Context, cmd *cli.Command) error {
if cmd.Args().Len() != 1 {
return fmt.Errorf("stack id is required")
}
id, err := utils.ArgToIndex(cmd.Args().First())
if err != nil {
return err
}
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
}
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
return err
}
if err := task.RestackPullStack(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, id); err != nil {
return err
}
fmt.Fprintf(ctx.Writer, "restack for stack #%d queued\n", id)
return nil
}