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:
bircni committed 2026-10-11 23:54:47 +02:00
1 parent c5cf6b9ed9
commit 7930f80865
13 files changed
+817 -302

No files matched your search

+23 -3
View File
@@ -6,6 +6,7 @@ package services
import (
"context"
"errors"
"net/url"
"slices"
"sort"
"time"
@@ -51,13 +52,32 @@ func (s Pulls) checkHead(ctx context.Context, n int64) (string, error) {
return pull.Head.Sha, nil
}
func checkFrom(sha string, status *gitea.Status) Check {
func checkFrom(sha, instance string, status *gitea.Status) Check {
return Check{
SHA: sha, ID: status.ID, Name: status.Context, State: string(status.State), Description: status.Description,
URL: status.TargetURL, CreatedAt: timestamp(status.Created), UpdatedAt: timestamp(status.Updated),
URL: absoluteURL(instance, status.TargetURL), CreatedAt: timestamp(status.Created), UpdatedAt: timestamp(status.Updated),
}
}
// absoluteURL resolves a link that Gitea gives relative to its root, such as the job links of
// Actions statuses, against the instance URL.
func absoluteURL(instance, link string) string {
base, err := url.Parse(instance)
if err != nil || link == "" {
return link
}
ref, err := url.Parse(link)
if err != nil {
return link
}
return base.ResolveReference(ref).String()
}
// CommitChecks returns the latest status of each check context of a commit.
func (s Pulls) CommitChecks(ctx context.Context, sha string) ([]Check, error) {
return s.checksForCommit(ctx, sha)
}
func (s Pulls) checksForCommit(ctx context.Context, sha string) ([]Check, error) {
statuses, err := listAll(func(page int) ([]*gitea.Status, error) {
return repoCall(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, name string) ([]*gitea.Status, *gitea.Response, error) {
@@ -71,7 +91,7 @@ func (s Pulls) checksForCommit(ctx context.Context, sha string) ([]Check, error)
for _, status := range statuses {
current, exists := latest[status.Context]
if !exists || status.ID > current.ID {
latest[status.Context] = checkFrom(sha, status)
latest[status.Context] = checkFrom(sha, s.Client.BaseURL, status)
}
}
result := make([]Check, 0, len(latest))