mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
feat(pr): list pull requests in a table and render issue and pr views as views
tea pr list prints a header, a "Showing N of M" line and the ID, TITLE,
BRANCH, STATE, AUTHOR and CREATED columns on a terminal, fit to its
width, and tab-separated rows when piped. Fork heads read
OWNER:BRANCH, drafts and merged pull requests have their own state,
and STATE appears on a terminal only when --state is not open. New
filters: --state merged, -d/--draft, -H/--head, -a/--assignee,
-S/--search and -w/--web, plus the gh shorthands -s, -A, -B, -l and
-m; --milestone takes a title or an ID, and @me works for --author and
--assignee. An empty list says so on stderr. draft, merged_at and
merged_by are exported in JSON, and reviewers, reviewer_teams and
merged_by, which Gitea's list leaves out, are read when --json names
them.
issue view and pr view render through terminal.View. Pull requests
show Draft and Merged badges, "alice merged into main from fix" with
the merge time, each reviewer's latest state ("bob (Approved), carol
(Requested)"), a checks summary pointing at tea pr checks, and why a
pull request cannot be merged. --comments includes reviews without a
body ("dave approved these changes") and comment IDs. Issues show
their due date and ref, and both kinds hint at --comments when there
are comments. pr view accepts #N, URLs and branch names, and its JSON
adds review_decision. Check links are absolute.
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
13 files changed
+817
-302
No files matched your search
@@ -6,7 +6,10 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -21,3 +24,80 @@ func TestPullListExplicitState(t *testing.T) {
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "list", "--state=closed", "-R", "alice/project", "--json"}))
|
||||
require.JSONEq(t, `[]`, out.String())
|
||||
}
|
||||
|
||||
// pullListServer lists the pull requests of alice/project: #17 from bob's fork, #15 a draft, #14
|
||||
// merged and #16 closed, with the total count Gitea reports.
|
||||
func pullListServer(t *testing.T, states *[]string) *http.Server {
|
||||
t.Helper()
|
||||
pulls := map[string]string{
|
||||
"open": `[{"number":17,"title":"Improve greeting","state":"open","user":{"login":"bob"},"created_at":"2026-10-11T10:00:00Z","head":{"ref":"bob/greeting","repo":{"full_name":"bob/project"}},"html_url":"http://gitea/alice/project/pulls/17"},
|
||||
{"number":15,"title":"WIP: experiment","state":"open","draft":true,"user":{"login":"alice"},"created_at":"2026-10-11T09:00:00Z","head":{"ref":"experiment","repo":{"full_name":"alice/project"}}}]`,
|
||||
"closed": `[{"number":16,"title":"Add usage guide","state":"closed","user":{"login":"alice"},"head":{"ref":"docs/guide"}},
|
||||
{"number":14,"title":"Fix README typo","state":"closed","merged":true,"user":{"login":"alice"},"head":{"ref":"fix/typo"}}]`,
|
||||
}
|
||||
return &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
state := r.URL.Query().Get("state")
|
||||
*states = append(*states, state)
|
||||
if r.URL.Query().Get("page") != "1" {
|
||||
_, _ = w.Write([]byte(`[]`))
|
||||
return
|
||||
}
|
||||
w.Header().Set("X-Total-Count", "2")
|
||||
_, _ = w.Write([]byte(pulls[state]))
|
||||
})}
|
||||
}
|
||||
|
||||
func TestPullListTable(t *testing.T) {
|
||||
var states []string
|
||||
server := newAuthenticatedServer(pullListServer(t, &states).Handler)
|
||||
defer server.Close()
|
||||
deps, out, diagnostics := serverDeps(t, server.URL)
|
||||
deps.Now = func() time.Time { return time.Date(2026, 10, 11, 12, 0, 0, 0, time.UTC) }
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "list", "-R", "alice/project"}))
|
||||
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()
|
||||
plainTTY(&deps, server.URL)
|
||||
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
|
||||
|
||||
ID TITLE BRANCH AUTHOR CREATED
|
||||
#17 Improve greeting bob:bob/greeting bob about 2 hours ago
|
||||
#15 WIP: experiment experiment alice about 3 hours ago
|
||||
`, stripLinks(out.String()))
|
||||
|
||||
out.Reset()
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "list", "-R", "alice/project", "--state", "merged"}))
|
||||
require.Equal(t, "Showing 1 of 1 merged pull requests in alice/project\n\nID TITLE BRANCH STATE AUTHOR CREATED\n#14 Fix README typo fix/typo merged alice\n", stripLinks(out.String()))
|
||||
|
||||
out.Reset()
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "list", "-R", "alice/project", "-d"}))
|
||||
require.True(t, strings.HasPrefix(stripLinks(out.String()), "Showing 1 of 1 open pull requests in alice/project\n\nID TITLE BRANCH AUTHOR CREATED\n#15 WIP: experiment"), out.String())
|
||||
|
||||
out.Reset()
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "list", "-R", "alice/project", "-H", "alice:greeting"}))
|
||||
require.Empty(t, out.String())
|
||||
require.Equal(t, "no open pull requests match your filters in alice/project\n", diagnostics.String())
|
||||
require.Equal(t, []string{"open", "closed", "open"}, slices.Compact(states))
|
||||
}
|
||||
|
||||
func TestPullListFillsReviewersWhenSelected(t *testing.T) {
|
||||
views := 0
|
||||
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/api/v1/repos/alice/project/pulls/13" {
|
||||
views++
|
||||
_, _ = w.Write([]byte(`{"number":13,"requested_reviewers":[{"login":"bob"}]}`))
|
||||
return
|
||||
}
|
||||
_, _ = w.Write([]byte(`[{"number":13,"requested_reviewers":[]}]`))
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, out, _ := serverDeps(t, server.URL)
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "list", "-R", "alice/project", "--json", "number,draft"}))
|
||||
require.JSONEq(t, `[{"number":13,"draft":false}]`, out.String())
|
||||
require.Zero(t, views)
|
||||
out.Reset()
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"pr", "list", "-R", "alice/project", "--json", "number,reviewers"}))
|
||||
require.JSONEq(t, `[{"number":13,"reviewers":["bob"]}]`, out.String())
|
||||
require.Equal(t, 1, views)
|
||||
}
|
||||
Reference in new issue
Block a user