mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-05 21:38:13 +02:00
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
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package print
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gitea.dev/tea/modules/stack"
|
||||
)
|
||||
|
||||
// PullStackFields are all available fields to print with PullStacksList()
|
||||
var PullStackFields = []string{
|
||||
"id",
|
||||
"title",
|
||||
"base",
|
||||
"state",
|
||||
"auto-restack",
|
||||
"entries",
|
||||
}
|
||||
|
||||
// PullStacksList prints a listing of pull request stacks
|
||||
func PullStacksList(stacks []*stack.Stack, output string, fields []string) error {
|
||||
printables := make([]printable, len(stacks))
|
||||
for i, s := range stacks {
|
||||
printables[i] = &printablePullStack{s}
|
||||
}
|
||||
t := tableFromItems(fields, printables, isMachineReadable(output))
|
||||
return t.print(output)
|
||||
}
|
||||
|
||||
type printablePullStack struct {
|
||||
*stack.Stack
|
||||
}
|
||||
|
||||
func (x printablePullStack) FormatField(field string, machineReadable bool) string {
|
||||
switch field {
|
||||
case "id":
|
||||
return fmt.Sprintf("%d", x.ID)
|
||||
case "title":
|
||||
return x.Title
|
||||
case "base":
|
||||
return x.BaseBranch
|
||||
case "state":
|
||||
return x.State
|
||||
case "auto-restack":
|
||||
return formatBoolean(x.AutoRestack, !machineReadable)
|
||||
case "entries":
|
||||
return fmt.Sprintf("%d", len(x.Entries))
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// PullStackDetail prints a pull request stack, bottom entry first, rendered to stdout
|
||||
func PullStackDetail(s *stack.Stack) {
|
||||
out := fmt.Sprintf(
|
||||
"# Stack #%d: %s (%s)\nbase: **%s**\tauto-restack: %s\n\n",
|
||||
s.ID, s.Title, s.State, s.BaseBranch, formatBoolean(s.AutoRestack, true),
|
||||
)
|
||||
|
||||
for _, entry := range s.Entries {
|
||||
if entry.ParentPullID == 0 {
|
||||
out += fmt.Sprintf("- #%d (%s)\n", entry.PullID, entry.State)
|
||||
} else {
|
||||
out += fmt.Sprintf("- #%d <- #%d (%s)\n", entry.PullID, entry.ParentPullID, entry.State)
|
||||
}
|
||||
}
|
||||
|
||||
outputMarkdown(strings.TrimRight(out, "\n")+"\n", "")
|
||||
}
|
||||
Reference in New Issue
Block a user