mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
issue list renders through the shared table: a context line, ID TITLE LABELS [STATE] [KIND] AUTHOR UPDATED with relative times on a terminal, the ID colored by state and linked, and a stable tab-separated column set when piped; empty results say so on stderr. It gains -s -L -l -a -A -m -S -w, @me, comma-separated label and milestone filters, and --web. issue view, edit, close and reopen accept #N, OWNER/REPO#N and issue URLs. Mutations report "✓ Created/Edited/Closed issue alice/x#5 (title)" on a terminal; issue create prints the new issue's URL on stdout (also as issue new), and close and reopen skip issues already in that state with a ! line and take -c/--comment. issue create and edit gain the gh short flags and singular --add-label, --remove-label, --add-assignee and --remove-assignee (the plural names still work), and create gains --web. The interactive create form asks for the title and body, then "What's next?" (submit, add metadata or cancel), without a confirmation after it; the edit form names the issue it edits. Every issue command has help text with examples and completes its flags and issue numbers. Signed-off-by: bircni <bircni@icloud.com>
109 lines
3.9 KiB
Go
109 lines
3.9 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package app
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestParseRunTime(t *testing.T) {
|
|
now := time.Date(2028, 2, 1, 12, 0, 0, 0, time.UTC)
|
|
plus2 := time.FixedZone("UTC+2", 2*60*60)
|
|
for _, tc := range []struct {
|
|
input string
|
|
expected time.Time
|
|
}{
|
|
{"24h", now.Add(-24 * time.Hour)},
|
|
{"0s", now},
|
|
{"2028-01-01", time.Date(2028, 1, 1, 0, 0, 0, 0, plus2)},
|
|
{"2028-01-01T00:30:00+02:00", time.Date(2027, 12, 31, 22, 30, 0, 0, time.UTC)},
|
|
{"2028-01-01 08:00", time.Date(2028, 1, 1, 8, 0, 0, 0, plus2)},
|
|
} {
|
|
result, err := parseRunTime(tc.input, now.In(plus2))
|
|
require.NoError(t, err)
|
|
require.True(t, result.Equal(tc.expected), tc.input)
|
|
}
|
|
for _, input := range []string{"", "-24h", "not-a-date", "2028-02-30"} {
|
|
_, err := parseRunTime(input, now)
|
|
require.Error(t, err, input)
|
|
}
|
|
}
|
|
|
|
func TestParseTimeRangeRejectsOnlyInvertedBounds(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
since, until string
|
|
wantErr bool
|
|
}{
|
|
{"2026-10-01", "2026-10-02", false},
|
|
{"2026-10-01", "2026-10-01", false},
|
|
{"2026-10-02", "2026-10-01", true},
|
|
} {
|
|
cmd := &cobra.Command{}
|
|
var bounds timeRange
|
|
bounds.register(cmd, "since", "", "until", "")
|
|
require.NoError(t, cmd.Flags().Parse([]string{"--since=" + tc.since, "--until=" + tc.until}))
|
|
_, _, err := bounds.parse(time.Now())
|
|
require.Equal(t, tc.wantErr, err != nil, tc.since+".."+tc.until)
|
|
}
|
|
}
|
|
|
|
func TestNumberAcceptsHashPrefix(t *testing.T) {
|
|
for raw, want := range map[string]int64{"12": 12, "#12": 12} {
|
|
n, err := number(raw)
|
|
require.NoError(t, err, raw)
|
|
require.Equal(t, want, n, raw)
|
|
}
|
|
for _, raw := range []string{"#", "##1", "0", "#-1", "1#", "abc"} {
|
|
_, err := number(raw)
|
|
require.ErrorContains(t, err, "invalid resource number", raw)
|
|
}
|
|
}
|
|
|
|
func TestUsageArgumentsSplitTopLevelGroups(t *testing.T) {
|
|
for use, want := range map[string][]string{
|
|
"list": nil,
|
|
"list [flags]": nil,
|
|
"view <number>": {"<number>"},
|
|
"view [number]": {"[number]"},
|
|
"close <number>...": {"<number>..."},
|
|
"clone <repository> [directory]": {"<repository>", "[directory]"},
|
|
"diff [<number> | <url> | <branch>]": {"[<number> | <url> | <branch>]"},
|
|
"download <tag> <asset-id> [flags]": {"<tag>", "<asset-id>"},
|
|
"upload <tag> <file>... [flags]": {"<tag>", "<file>..."},
|
|
} {
|
|
require.Equal(t, want, usageArguments(use), use)
|
|
}
|
|
}
|
|
|
|
func TestArgumentErrorsShowTheUsageLine(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
args []string
|
|
want string
|
|
}{
|
|
{[]string{"issue", "view"}, "missing issue number\nUsage: tea issue view {<number> | <url>} [flags]\nRun 'tea issue view --help' for examples."},
|
|
{[]string{"issue", "view", "1", "2"}, "too many arguments\nUsage: tea issue view {<number> | <url>} [flags]"},
|
|
{[]string{"issue", "list", "extra"}, "unexpected argument \"extra\"\nUsage: tea issue list [flags]"},
|
|
{[]string{"pr", "checkout"}, "missing pull request number\nUsage: tea pr checkout {<number> | <url> | <branch>} [flags]"},
|
|
{[]string{"run", "view"}, "missing run ID\nUsage: tea run view [<run-id>] [flags]"},
|
|
{[]string{"release", "asset", "edit", "v1"}, "missing asset\nUsage: tea release asset edit <tag> <asset> [flags]"},
|
|
{[]string{"repo", "clone"}, "missing repository\nUsage: tea repo clone <repository> [<directory>] [-- <gitflags>...] [flags]"},
|
|
} {
|
|
requireUsageBeforeRequests(t, tc.want, tc.args...)
|
|
}
|
|
}
|
|
|
|
func TestLimitAcceptsShorthandUpToOneThousand(t *testing.T) {
|
|
var limit, page int
|
|
cmd := &cobra.Command{Use: "list"}
|
|
pageFlags(cmd, &limit, &page)
|
|
require.Equal(t, 30, limit)
|
|
require.NoError(t, cmd.Flags().Parse([]string{"-L", "1000"}))
|
|
require.Equal(t, 1000, limit)
|
|
require.ErrorContains(t, cmd.Flags().Parse([]string{"-L", "1001"}), "must be 1..1000")
|
|
}
|