Files
gitea-tea/cmd/pulls/stack/list.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

54 lines
1.4 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package stack
import (
stdctx "context"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/print"
"gitea.dev/tea/modules/task"
"github.com/urfave/cli/v3"
)
var stackFieldsFlag = flags.FieldsFlag(print.PullStackFields, []string{
"id", "title", "base", "state", "entries",
})
// CmdStackList represents a sub command to list pull request stacks
var CmdStackList = cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: "List pull request stacks of the repository",
Description: "List pull request stacks of the repository",
ArgsUsage: " ", // command does not accept arguments
Action: RunStackList,
Flags: append([]cli.Flag{stackFieldsFlag}, flags.AllDefaultFlags...),
}
// RunStackList lists pull request stacks of the repository
func RunStackList(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
}
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
return err
}
stacks, err := task.ListPullStacks(requestCtx, ctx.Login, ctx.Owner, ctx.Repo)
if err != nil {
return err
}
fields, err := stackFieldsFlag.GetValues(cmd)
if err != nil {
return err
}
return print.PullStacksList(stacks, ctx.Output, fields)
}