feat(web): use the linked pull request row layout on the pull requests page (#12536)

Co-authored-by: Claude Fable 5.1 <[email protected]>
This commit is contained in:
mariaandClaude Fable 5.1 authored and GitHub committed 2026-09-20 22:20:13 -03:00
1 parent 58f89818e3
commit 411da2a735
11 files changed
+720 -357

No files matched your search

@@ -97,6 +97,40 @@ describe("pull request list decoding", () => {
]);
});
it("takes the verdict from the latest reviews when GitHub summarizes none, as for a bot's approval", () => {
const batch = expectSuccess(
decodePullRequestListJson(
listJson([
{
reviewDecision: null,
latestReviews: [{ author: { login: "macroscopeapp" }, state: "APPROVED" }],
},
{
reviewDecision: "REVIEW_REQUIRED",
latestReviews: [
{ author: { login: "octocat" }, state: "APPROVED" },
{ author: { login: "hubot" }, state: "CHANGES_REQUESTED" },
],
},
{
reviewDecision: "APPROVED",
latestReviews: [{ author: { login: "hubot" }, state: "CHANGES_REQUESTED" }],
},
{
reviewDecision: null,
latestReviews: [{ author: { login: "octocat" }, state: "COMMENTED" }],
},
]),
),
);
expect(batch.items.map((entry) => entry.reviewDecision)).toEqual([
"approved",
"changes-requested",
"approved",
null,
]);
});
it("rolls the head commit's checks up to the one word a row has space for", () => {
const batch = expectSuccess(
decodePullRequestListJson(
@@ -68,6 +68,12 @@ const RawReviewRequestSchema = Schema.Struct({
name: Schema.optional(Schema.NullOr(Schema.String)),
});
/** One reviewer's most recent review: the state is all the verdict needs, the author is for who. */
const RawLatestReviewSchema = Schema.Struct({
author: Schema.optional(Schema.NullOr(RawActorSchema)),
state: Schema.optional(Schema.NullOr(Schema.String)),
});
const RawCheckSchema = Schema.Struct({
__typename: Schema.optional(Schema.String),
name: Schema.optional(Schema.NullOr(Schema.String)),
@@ -106,6 +112,7 @@ const RawListItemSchema = Schema.Struct({
updatedAt: Schema.String,
mergedAt: Schema.optional(Schema.NullOr(Schema.String)),
reviewRequests: Schema.optional(Schema.Array(RawReviewRequestSchema)),
latestReviews: Schema.optional(Schema.NullOr(Schema.Array(RawLatestReviewSchema))),
labels: Schema.optional(Schema.Array(RawLabelSchema)),
/**
* Every check of the head commit, which is the only rollup `gh pr list --json` can give: there
@@ -143,6 +150,9 @@ const RawSearchItemSchema = Schema.Struct({
isDraft: Schema.optional(Schema.Boolean),
mergeable: Schema.optional(Schema.NullOr(Schema.String)),
reviewDecision: Schema.optional(Schema.NullOr(Schema.String)),
latestReviews: Schema.optional(
Schema.NullOr(Schema.Struct({ nodes: Schema.Array(Schema.NullOr(RawLatestReviewSchema)) })),
),
createdAt: Schema.String,
updatedAt: Schema.String,
mergedAt: Schema.optional(Schema.NullOr(Schema.String)),
@@ -514,13 +524,7 @@ const RawReviewThreadsSchema = Schema.Struct({
),
),
latestReviews: Schema.optional(
Schema.NullOr(
Schema.Struct({
nodes: Schema.Array(
Schema.Struct({ author: Schema.optional(Schema.NullOr(RawActorSchema)) }),
),
}),
),
Schema.NullOr(Schema.Struct({ nodes: Schema.Array(RawLatestReviewSchema) })),
),
reviewDismissals: Schema.optional(
Schema.NullOr(
@@ -698,7 +702,7 @@ export function decodeActorAvatarsJson(
}
export const PULL_REQUEST_LIST_JSON_FIELDS =
"number,title,url,author,headRefName,baseRefName,state,isDraft,mergeable,reviewDecision,additions,deletions,createdAt,updatedAt,mergedAt,reviewRequests,labels,statusCheckRollup";
"number,title,url,author,headRefName,baseRefName,state,isDraft,mergeable,reviewDecision,additions,deletions,createdAt,updatedAt,mergedAt,reviewRequests,latestReviews,labels,statusCheckRollup";
export const PULL_REQUEST_DETAIL_JSON_FIELDS = `${PULL_REQUEST_LIST_JSON_FIELDS},body,changedFiles,closedAt,isCrossRepository,headRepositoryOwner,headRefOid,autoMergeRequest`;
@@ -817,6 +821,7 @@ export function pullRequestSearchGraphQlQuery(rows: number, includeStacks = fals
isDraft
mergeable
reviewDecision
latestReviews(first: 20) { nodes { state author { login } } }
createdAt
updatedAt
mergedAt
@@ -891,7 +896,7 @@ export const REVIEW_THREADS_GRAPHQL_QUERY = `query($owner: String!, $name: Strin
}
}
latestReviews(first: 50) {
nodes { author { __typename login avatarUrl } }
nodes { state author { __typename login avatarUrl } }
}
reviewDismissals: timelineItems(itemTypes: [REVIEW_DISMISSED_EVENT], first: ${GRAPHQL_PAGE_SIZE}) {
pageInfo { hasNextPage endCursor }
@@ -1325,6 +1330,35 @@ function toMergeMethod(value: string | null | undefined): PullRequestMergeMethod
}
}
/**
* GitHub's own `reviewDecision` counts only reviews that satisfy the branch rules, so an
* approval from an app (a review bot) or from anyone without the required permission leaves it
* empty. The reviewers still said something, and a row should show it: when GitHub reports no
* verdict, the latest review per reviewer decides, changes requested outranking approval.
*/
function toReviewDecisionWithReviews(
value: string | null | undefined,
// `gh pr list` hands the reviews as an array; the GraphQL reads hand a connection.
latestReviews:
| ReadonlyArray<Schema.Schema.Type<typeof RawLatestReviewSchema>>
| { readonly nodes: ReadonlyArray<Schema.Schema.Type<typeof RawLatestReviewSchema>> }
| null
| undefined,
): PullRequestReviewDecision | null {
const summarized = toReviewDecision(value);
if (summarized === "approved" || summarized === "changes-requested") return summarized;
const reviews =
latestReviews === null || latestReviews === undefined
? []
: "nodes" in latestReviews
? latestReviews.nodes
: latestReviews;
const states = new Set(reviews.map((review) => review.state?.trim().toUpperCase() ?? ""));
if (states.has("CHANGES_REQUESTED")) return "changes-requested";
if (states.has("APPROVED")) return "approved";
return summarized;
}
function toReviewDecision(value: string | null | undefined): PullRequestReviewDecision | null {
switch (value?.trim().toUpperCase()) {
case "APPROVED":
@@ -1558,7 +1592,7 @@ function toListItem(raw: Schema.Schema.Type<typeof RawListItemSchema>): GitHubPu
state: toState(raw),
isDraft: raw.isDraft ?? false,
mergeability: toMergeability(raw.mergeable),
reviewDecision: toReviewDecision(raw.reviewDecision),
reviewDecision: toReviewDecisionWithReviews(raw.reviewDecision, raw.latestReviews),
additions: raw.additions ?? 0,
deletions: raw.deletions ?? 0,
createdAt: raw.createdAt,
@@ -1681,6 +1715,9 @@ export function decodePullRequestSearchJson(
items.push({
...toListItem({
...node,
latestReviews: (node.latestReviews?.nodes ?? []).flatMap((review) =>
review === null ? [] : [review],
),
reviewRequests: (node.reviewRequests?.nodes ?? []).flatMap((request) => {
const login = trimmed(request?.requestedReviewer?.login);
return login === null ? [] : [{ login }];