mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-05 21:38: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
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package print
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"gitea.dev/tea/modules/stack"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPullStacksListJSON(t *testing.T) {
|
|
stacks := []*stack.Stack{
|
|
{
|
|
ID: 1, Title: "feat: base", BaseBranch: "main", State: "open", AutoRestack: true,
|
|
Entries: []stack.Entry{{PullID: 10}, {PullID: 11}},
|
|
},
|
|
}
|
|
|
|
buf := &bytes.Buffer{}
|
|
tbl := tableFromItems(
|
|
PullStackFields,
|
|
[]printable{&printablePullStack{stacks[0]}},
|
|
true,
|
|
)
|
|
require.NoError(t, tbl.fprint(buf, "json"))
|
|
|
|
var result []map[string]string
|
|
require.NoError(t, json.Unmarshal(buf.Bytes(), &result))
|
|
require.Len(t, result, 1)
|
|
assert.Equal(t, "1", result[0]["id"])
|
|
assert.Equal(t, "feat: base", result[0]["title"])
|
|
assert.Equal(t, "main", result[0]["base"])
|
|
assert.Equal(t, "open", result[0]["state"])
|
|
assert.Equal(t, "true", result[0]["auto-restack"])
|
|
assert.Equal(t, "2", result[0]["entries"])
|
|
}
|
|
|
|
func TestPullStackDetailShowsEntries(t *testing.T) {
|
|
s := &stack.Stack{
|
|
ID: 3, Title: "feat: base", BaseBranch: "main", State: "open", AutoRestack: true,
|
|
Entries: []stack.Entry{
|
|
{PullID: 10, Position: 0, State: "merged"},
|
|
{PullID: 11, ParentPullID: 10, Position: 1, State: "open"},
|
|
},
|
|
}
|
|
|
|
out := captureStdout(t, func() {
|
|
PullStackDetail(s)
|
|
})
|
|
|
|
assert.Contains(t, out, "feat: base")
|
|
assert.Contains(t, out, "main")
|
|
assert.Contains(t, out, "#10")
|
|
assert.Contains(t, out, "#11")
|
|
}
|