mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
fix: reconcile the pull request stream
Share one shortSHA helper, keep Markdown raw in view tests through the markdown preference, and drop rawWindow now that pull request lists use the paged helpers. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
5 files changed
+11
-25
No files matched your search
@@ -121,7 +121,7 @@ func TestChecksSummaryAndExitCodes(t *testing.T) {
|
|||||||
}))
|
}))
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
deps, out, diagnostics := serverDeps(t, server.URL)
|
deps, out, diagnostics := serverDeps(t, server.URL)
|
||||||
plainTTY(&deps, server.URL)
|
plainTTY(t, &deps, server.URL)
|
||||||
err := Execute(context.Background(), deps, []string{"pr", "checks", "8", "-R", "alice/x"})
|
err := Execute(context.Background(), deps, []string{"pr", "checks", "8", "-R", "alice/x"})
|
||||||
require.Equal(t, tc.code, clierr.ExitCode(err))
|
require.Equal(t, tc.code, clierr.ExitCode(err))
|
||||||
if tc.code != 0 {
|
if tc.code != 0 {
|
||||||
|
|||||||
@@ -13,9 +13,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// plainTTY makes deps render for a terminal without color or markdown, so views compare as text.
|
// plainTTY makes deps render for a terminal without color or markdown, so views compare as text.
|
||||||
func plainTTY(deps *Dependencies, serverURL string) {
|
func plainTTY(t *testing.T, deps *Dependencies, serverURL string) {
|
||||||
|
t.Helper()
|
||||||
deps.Streams.OutTTY = true
|
deps.Streams.OutTTY = true
|
||||||
deps.Getenv = serverEnv(serverURL, map[string]string{"NO_COLOR": "1", "TEA_MARKDOWN": "raw"})
|
deps.Getenv = serverEnv(serverURL, map[string]string{"NO_COLOR": "1"})
|
||||||
|
rawMarkdown(t, *deps)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDiscussionViews(t *testing.T) {
|
func TestDiscussionViews(t *testing.T) {
|
||||||
@@ -40,7 +42,7 @@ func TestDiscussionViews(t *testing.T) {
|
|||||||
require.Equal(t, "title:\tCrash[2J\nstate:\topen\nauthor:\tbob\nlabels:\tbug\nassignees:\talice\nmilestone:\t\ndue:\t\nref:\t\nblocked by:\t\nblocks:\t\ncomments:\t1\nnumber:\t3\nurl:\thttps://example.org/i/3\n--\nSteps:\n]52;c;aGk=run\n"+
|
require.Equal(t, "title:\tCrash[2J\nstate:\topen\nauthor:\tbob\nlabels:\tbug\nassignees:\talice\nmilestone:\t\ndue:\t\nref:\t\nblocked by:\t\nblocks:\t\ncomments:\t1\nnumber:\t3\nurl:\thttps://example.org/i/3\n--\nSteps:\n]52;c;aGk=run\n"+
|
||||||
"--\nauthor:\tcarol\ncreated_at:\t2026-01-02T00:00:00Z\nid:\t79\n--\nConfirmed[31m\n\tok\n", out.String())
|
"--\nauthor:\tcarol\ncreated_at:\t2026-01-02T00:00:00Z\nid:\t79\n--\nConfirmed[31m\n\tok\n", out.String())
|
||||||
out.Reset()
|
out.Reset()
|
||||||
plainTTY(&deps, server.URL)
|
plainTTY(t, &deps, server.URL)
|
||||||
require.NoError(t, Execute(context.Background(), deps, []string{"issue", "view", "3", "-R", "alice/project"}))
|
require.NoError(t, Execute(context.Background(), deps, []string{"issue", "view", "3", "-R", "alice/project"}))
|
||||||
require.Equal(t, "Crash[2J #3\nOpen • bob opened about 3 days ago • 1 comment\nLabels: bug\nAssignees: alice\n\nSteps:\n]52;c;aGk=run\n\n"+
|
require.Equal(t, "Crash[2J #3\nOpen • bob opened about 3 days ago • 1 comment\nLabels: bug\nAssignees: alice\n\nSteps:\n]52;c;aGk=run\n\n"+
|
||||||
"1 comment — use --comments to view them\n\nView this issue on Gitea: https://example.org/i/3\n", out.String())
|
"1 comment — use --comments to view them\n\nView this issue on Gitea: https://example.org/i/3\n", out.String())
|
||||||
@@ -75,7 +77,7 @@ func TestIssueViewDependencies(t *testing.T) {
|
|||||||
defer server.Close()
|
defer server.Close()
|
||||||
deps, out, _ := serverDeps(t, server.URL)
|
deps, out, _ := serverDeps(t, server.URL)
|
||||||
deps.Now = func() time.Time { return time.Date(2026, 1, 4, 0, 0, 0, 0, time.UTC) }
|
deps.Now = func() time.Time { return time.Date(2026, 1, 4, 0, 0, 0, 0, time.UTC) }
|
||||||
plainTTY(&deps, server.URL)
|
plainTTY(t, &deps, server.URL)
|
||||||
args := []string{"issue", "view", "3", "-R", "alice/project"}
|
args := []string{"issue", "view", "3", "-R", "alice/project"}
|
||||||
require.NoError(t, Execute(context.Background(), deps, args))
|
require.NoError(t, Execute(context.Background(), deps, args))
|
||||||
require.Equal(t, "Crash #3\nOpen • bob opened about 1 day ago • 0 comments\nDue: Dec 24, 2026 (in about 11 months)\nRef: main\nBlocked by: #1, bob/lib#5, hidden\nBlocks: #9\n\nNo description provided\n\nView this issue on Gitea: https://example.org/i/3\n", out.String())
|
require.Equal(t, "Crash #3\nOpen • bob opened about 1 day ago • 0 comments\nDue: Dec 24, 2026 (in about 11 months)\nRef: main\nBlocked by: #1, bob/lib#5, hidden\nBlocks: #9\n\nNo description provided\n\nView this issue on Gitea: https://example.org/i/3\n", out.String())
|
||||||
@@ -130,7 +132,7 @@ func TestPullViewCommentsIncludeReviews(t *testing.T) {
|
|||||||
"--\nauthor:\tdave\ncreated_at:\t2026-01-03T00:00:00Z\nreview:\tAPPROVED\n--\n\n"+
|
"--\nauthor:\tdave\ncreated_at:\t2026-01-03T00:00:00Z\nreview:\tAPPROVED\n--\n\n"+
|
||||||
"--\nauthor:\talice\ncreated_at:\t2026-01-03T06:00:00Z\nreview:\tAPPROVED\n--\nGreat\n", out.String())
|
"--\nauthor:\talice\ncreated_at:\t2026-01-03T06:00:00Z\nreview:\tAPPROVED\n--\nGreat\n", out.String())
|
||||||
out.Reset()
|
out.Reset()
|
||||||
plainTTY(&deps, server.URL)
|
plainTTY(t, &deps, server.URL)
|
||||||
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "view", "4", "-R", "alice/project", "--comments"}))
|
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "view", "4", "-R", "alice/project", "--comments"}))
|
||||||
require.Equal(t, "Fix #4\nOpen • bob wants to merge into main from fix • about 3 days ago • 1 comment\nReviewers: alice (Approved), dave (Approved)\nMergeable: yes\n\nNo description provided\n\n"+
|
require.Equal(t, "Fix #4\nOpen • bob wants to merge into main from fix • about 3 days ago • 1 comment\nReviewers: alice (Approved), dave (Approved)\nMergeable: yes\n\nNo description provided\n\n"+
|
||||||
"alice requested changes • about 2 days ago\nPlease rename\n\n"+
|
"alice requested changes • about 2 days ago\nPlease rename\n\n"+
|
||||||
@@ -178,7 +180,7 @@ func TestPullViewStates(t *testing.T) {
|
|||||||
defer server.Close()
|
defer server.Close()
|
||||||
deps, out, _ := serverDeps(t, server.URL)
|
deps, out, _ := serverDeps(t, server.URL)
|
||||||
deps.Now = func() time.Time { return time.Date(2026, 1, 4, 0, 0, 0, 0, time.UTC) }
|
deps.Now = func() time.Time { return time.Date(2026, 1, 4, 0, 0, 0, 0, time.UTC) }
|
||||||
plainTTY(&deps, server.URL)
|
plainTTY(t, &deps, server.URL)
|
||||||
number := map[string]string{"draft": "15"}[tc.name]
|
number := map[string]string{"draft": "15"}[tc.name]
|
||||||
if number == "" {
|
if number == "" {
|
||||||
number = "17"
|
number = "17"
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func TestPullListTable(t *testing.T) {
|
|||||||
require.Equal(t, "17\tImprove greeting\tbob:bob/greeting\topen\tbob\t2026-10-11T10:00:00Z\n15\tWIP: experiment\texperiment\tdraft\talice\t2026-10-11T09:00:00Z\n", out.String())
|
require.Equal(t, "17\tImprove greeting\tbob:bob/greeting\topen\tbob\t2026-10-11T10:00:00Z\n15\tWIP: experiment\texperiment\tdraft\talice\t2026-10-11T09:00:00Z\n", out.String())
|
||||||
|
|
||||||
out.Reset()
|
out.Reset()
|
||||||
plainTTY(&deps, server.URL)
|
plainTTY(t, &deps, server.URL)
|
||||||
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "list", "-R", "alice/project"}))
|
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "list", "-R", "alice/project"}))
|
||||||
require.Equal(t, `Showing 2 of 2 open pull requests in alice/project
|
require.Equal(t, `Showing 2 of 2 open pull requests in alice/project
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func TestPullStatusShowsTheCurrentBranch(t *testing.T) {
|
|||||||
}))
|
}))
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
deps, out, _ := serverDeps(t, server.URL)
|
deps, out, _ := serverDeps(t, server.URL)
|
||||||
plainTTY(&deps, server.URL)
|
plainTTY(t, &deps, server.URL)
|
||||||
deps.Getenv = serverEnv(server.URL, map[string]string{"NO_COLOR": "1", "TEA_REPO": "alice/project"})
|
deps.Getenv = serverEnv(server.URL, map[string]string{"NO_COLOR": "1", "TEA_REPO": "alice/project"})
|
||||||
deps.Git = &fakeGit{results: map[string]string{"symbolic-ref --short HEAD": "feat/one", "config --get branch.feat/one.tea-pr": "1"}}
|
deps.Git = &fakeGit{results: map[string]string{"symbolic-ref --short HEAD": "feat/one", "config --get branch.feat/one.tea-pr": "1"}}
|
||||||
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "status"}))
|
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "status"}))
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"gitea.dev/tea/internal/transport"
|
"gitea.dev/tea/internal/transport"
|
||||||
)
|
)
|
||||||
@@ -39,20 +37,6 @@ func sendJSON(ctx context.Context, client *transport.Client, method, endpoint st
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// rawWindow is listWindow over a raw JSON collection endpoint; it sets limit and page on query.
|
|
||||||
func rawWindow[T any](ctx context.Context, client *transport.Client, endpoint string, query url.Values, limit, page int) ([]T, bool, error) {
|
|
||||||
if query == nil {
|
|
||||||
query = url.Values{}
|
|
||||||
}
|
|
||||||
return listWindow(limit, page, func(limit, page int) ([]T, http.Header, error) {
|
|
||||||
query.Set("limit", strconv.Itoa(limit))
|
|
||||||
query.Set("page", strconv.Itoa(page))
|
|
||||||
var response []T
|
|
||||||
headers, err := rawJSON(ctx, client, http.MethodGet, endpoint+"?"+query.Encode(), nil, &response)
|
|
||||||
return response, headers, err
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func rawJSON(ctx context.Context, client *transport.Client, method, endpoint string, body io.Reader, out any) (http.Header, error) {
|
func rawJSON(ctx context.Context, client *transport.Client, method, endpoint string, body io.Reader, out any) (http.Header, error) {
|
||||||
resp, err := client.Do(ctx, method, endpoint, body, nil)
|
resp, err := client.Do(ctx, method, endpoint, body, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user