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
70 lines
1.9 KiB
Go
70 lines
1.9 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/print"
|
|
pullstack "gitea.dev/tea/modules/stack"
|
|
"gitea.dev/tea/modules/task"
|
|
"gitea.dev/tea/modules/utils"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// CmdStackPush represents a sub command to link a pull request onto a stack
|
|
var CmdStackPush = cli.Command{
|
|
Name: "push",
|
|
Usage: "Link a pull request onto a stack",
|
|
Description: "Link a child pull request onto its parent, creating a new stack or extending an existing one with --stack",
|
|
ArgsUsage: "<parent index> <child index>",
|
|
Action: RunStackPush,
|
|
Flags: append([]cli.Flag{
|
|
&cli.Int64Flag{
|
|
Name: "stack",
|
|
Usage: "id of an existing stack to append the pull requests to, instead of creating a new stack",
|
|
},
|
|
}, flags.AllDefaultFlags...),
|
|
}
|
|
|
|
// RunStackPush links a parent and a child pull request into a stack
|
|
func RunStackPush(requestCtx stdctx.Context, cmd *cli.Command) error {
|
|
if cmd.Args().Len() != 2 {
|
|
return fmt.Errorf("parent index and child index are required")
|
|
}
|
|
parentIndex, err := utils.ArgToIndex(cmd.Args().Get(0))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
childIndex, err := utils.ArgToIndex(cmd.Args().Get(1))
|
|
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
|
|
}
|
|
|
|
var s *pullstack.Stack
|
|
if stackID := cmd.Int64("stack"); stackID != 0 {
|
|
s, err = task.AddPullStackEntry(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, stackID, parentIndex, childIndex)
|
|
} else {
|
|
s, err = task.CreatePullStack(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, parentIndex, childIndex)
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
print.PullStackDetail(s)
|
|
return nil
|
|
}
|