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

+53 -8
View File
@@ -4,10 +4,12 @@
package services
import (
"cmp"
"context"
"errors"
"fmt"
"net/http"
"slices"
"sort"
"strings"
@@ -105,7 +107,7 @@ func (s Reviews) List(ctx context.Context, n int64, limit, page int) ([]Review,
// Pending returns the reviews that login started on pull request n and has not submitted yet.
func (s Reviews) Pending(ctx context.Context, n int64, login string) ([]Review, error) {
reviews, err := listAll(func(page int) ([]Review, error) { return s.List(ctx, n, 100, page) })
reviews, err := s.All(ctx, n)
if err != nil {
return nil, err
}
@@ -208,14 +210,57 @@ func (s Reviews) Comments(ctx context.Context, n, reviewID int64, limit, page in
return pageOf(results, limit, page)
}
// Thread returns every review and every inline review comment of a pull request.
func (s Reviews) Thread(ctx context.Context, n int64) ([]Review, []ReviewComment, error) {
reviews, err := listAll(func(page int) ([]Review, error) { return s.List(ctx, n, 100, page) })
if err != nil {
return nil, nil, err
// All returns every review of a pull request, including requests for a review.
func (s Reviews) All(ctx context.Context, n int64) ([]Review, error) {
return listAll(func(page int) ([]Review, error) { return s.List(ctx, n, 100, page) })
}
// Inline returns the inline comments of the given reviews of pull request n.
func (s Reviews) Inline(ctx context.Context, n int64, reviews []Review) ([]ReviewComment, error) {
return s.reviewComments(ctx, n, reviews, true)
}
// LatestReviews returns each reviewer's latest review, in the order of their first review. Pending
// reviews, which only their author sees, are left out; a later request for a review replaces a review.
func LatestReviews(reviews []Review) []Review {
reviews = slices.Clone(reviews)
slices.SortStableFunc(reviews, func(x, y Review) int { return cmp.Compare(x.ID, y.ID) })
at := map[string]int{}
var latest []Review
for _, review := range reviews {
if review.Author == "" || review.State == string(gitea.ReviewStatePending) {
continue
}
if i, ok := at[review.Author]; ok {
latest[i] = review
continue
}
at[review.Author] = len(latest)
latest = append(latest, review)
}
comments, err := s.reviewComments(ctx, n, reviews, true)
return reviews, comments, err
return latest
}
// ReviewDecision summarizes the latest reviews like gh: changes_requested when a reviewer's latest
// review requests changes, else approved when one approves, else review_required while reviews
// are requested, else "". Dismissed reviews do not count.
func ReviewDecision(latest []Review, requested bool) string {
decision := ""
for _, review := range latest {
switch {
case review.Dismissed:
case review.State == string(gitea.ReviewStateRequestChanges):
return "changes_requested"
case review.State == string(gitea.ReviewStateApproved):
decision = "approved"
case review.State == string(gitea.ReviewStateRequestReview):
requested = true
}
}
if decision == "" && requested {
return "review_required"
}
return decision
}
func (s Reviews) reviewComments(ctx context.Context, n int64, reviews []Review, skipEmpty bool) ([]ReviewComment, error) {