// 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", "") }