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
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package stack
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"gitea.dev/tea/modules/config"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestStackPush(t *testing.T) {
|
|
config.SetConfigForTesting(config.LocalConfig{
|
|
Logins: []config.Login{{
|
|
Name: "testLogin",
|
|
URL: "https://gitea.example.com",
|
|
Token: "test-token",
|
|
User: "testUser",
|
|
Default: true,
|
|
}},
|
|
})
|
|
t.Cleanup(func() {
|
|
config.SetConfigForTesting(config.LocalConfig{})
|
|
})
|
|
|
|
tests := []struct {
|
|
name string
|
|
args []string
|
|
errContains string
|
|
}{
|
|
{
|
|
name: "no arguments",
|
|
args: []string{},
|
|
errContains: "parent index and child index are required",
|
|
},
|
|
{
|
|
name: "missing child index",
|
|
args: []string{"1"},
|
|
errContains: "parent index and child index are required",
|
|
},
|
|
{
|
|
name: "non-numeric parent index",
|
|
args: []string{"abc", "2"},
|
|
errContains: "",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
cmd := CmdStackPush
|
|
args := append([]string{"push"}, tt.args...)
|
|
args = append(args, "--login", "testLogin", "--repo", "user/repo")
|
|
err := cmd.Run(context.Background(), args)
|
|
assert.Error(t, err)
|
|
if tt.errContains != "" {
|
|
assert.Contains(t, err.Error(), tt.errContains)
|
|
}
|
|
})
|
|
}
|
|
}
|