mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-06 05:48:13 +02:00
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
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package stack
|
|
|
|
import (
|
|
stdctx "context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"gitea.dev/tea/cmd/flags"
|
|
"gitea.dev/tea/modules/context"
|
|
"gitea.dev/tea/modules/print"
|
|
"gitea.dev/tea/modules/task"
|
|
"gitea.dev/tea/modules/utils"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// CmdStackShow represents a sub command to show a pull request stack
|
|
var CmdStackShow = cli.Command{
|
|
Name: "show",
|
|
Aliases: []string{"get"},
|
|
Usage: "Show a pull request stack",
|
|
Description: "Show a pull request stack, its base branch and its ordered pull requests",
|
|
ArgsUsage: "<stack id>",
|
|
Action: RunStackShow,
|
|
Flags: flags.AllDefaultFlags,
|
|
}
|
|
|
|
// RunStackShow shows a pull request stack
|
|
func RunStackShow(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
|
|
}
|
|
|
|
s, err := task.GetPullStack(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if ctx.String("output") == "json" {
|
|
encoder := json.NewEncoder(ctx.Writer)
|
|
encoder.SetIndent("", "\t")
|
|
return encoder.Encode(s)
|
|
}
|
|
|
|
print.PullStackDetail(s)
|
|
return nil
|
|
}
|