fix(pull-requests): missing features & better behaviour (#9188)
Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
1 parent
4ba39a6f40
commit
443b4ebfe8
34 files changed
+2241
-205
No files matched your search
@@ -65,7 +65,7 @@ function ChecksBody({ checks }: { checks: ReadonlyArray<PullRequestCheck> }) {
|
||||
<TooltipPopup side="top">{check.description ?? check.name}</TooltipPopup>
|
||||
</Tooltip>
|
||||
<span className="shrink-0 text-muted-foreground">
|
||||
{pullRequestCheckStatusLabel(check.status)}
|
||||
{pullRequestCheckStatusLabel(check)}
|
||||
</span>
|
||||
{check.url === null ? null : (
|
||||
<button
|
||||
@@ -112,6 +112,7 @@ export function PullRequestChecksPopover({
|
||||
not valid inside one. The click is stopped here so opening the checks does not also
|
||||
select the row it sits on. */}
|
||||
<PopoverTrigger
|
||||
nativeButton={false}
|
||||
render={
|
||||
<span
|
||||
role="button"
|
||||
|
||||
@@ -33,7 +33,9 @@ import {
|
||||
MoreHorizontalIcon,
|
||||
PanelRightIcon,
|
||||
PencilIcon,
|
||||
PlayIcon,
|
||||
RefreshCwIcon,
|
||||
RotateCcwIcon,
|
||||
ServerIcon,
|
||||
TriangleAlertIcon,
|
||||
} from "lucide-react";
|
||||
@@ -118,6 +120,7 @@ import {
|
||||
pullRequestFindingKey,
|
||||
pullRequestHandoffLabels,
|
||||
readableFailure,
|
||||
resolvePullRequestPrimaryControl,
|
||||
resolveBaseFreshness,
|
||||
type PullRequestFinding,
|
||||
shouldRefreshPullRequestActivity,
|
||||
@@ -154,6 +157,8 @@ const ACTION_SUCCESS_LABELS: Record<PullRequestAction, string> = {
|
||||
"enable-auto-merge":
|
||||
"Auto-merge turned on — merges as soon as this is ready, sooner if it already is",
|
||||
"disable-auto-merge": "Auto-merge turned off",
|
||||
revert: "Revert pull request opened",
|
||||
"approve-workflows": "Workflows approved",
|
||||
};
|
||||
|
||||
const MERGE_METHOD_LABELS: Record<PullRequestMergeMethod, string> = {
|
||||
@@ -172,6 +177,8 @@ const ACTION_FAILURE_LABELS: Record<PullRequestAction, string> = {
|
||||
"update-branch": "Could not update this branch",
|
||||
"enable-auto-merge": "Could not turn on auto-merge",
|
||||
"disable-auto-merge": "Could not turn off auto-merge",
|
||||
revert: "Could not open a revert pull request",
|
||||
"approve-workflows": "Could not approve workflows",
|
||||
};
|
||||
|
||||
/** What to try, for the times the host says only that it refused. */
|
||||
@@ -193,6 +200,10 @@ const ACTION_FAILURE_HINTS: Record<PullRequestAction, string> = {
|
||||
"The host refused it. Check that this repository allows auto-merge, that you have write access, and that there is something left for it to wait on.",
|
||||
"disable-auto-merge":
|
||||
"The host refused it. Check that you have write access, and that the merge has not already happened.",
|
||||
revert:
|
||||
"The host refused it. Check that you have write access and that this pull request was merged on the host.",
|
||||
"approve-workflows":
|
||||
"The host refused it. Check that you have Actions write access and that these workflow runs are still awaiting approval.",
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -518,10 +529,18 @@ export function PullRequestDetailPanel({
|
||||
compensationRef.current = null;
|
||||
if (scroller) scroller.scrollTop = Math.max(0, scroller.scrollTop + delta);
|
||||
}, [condensed]);
|
||||
const [mergeMethod, setMergeMethod] = useState<PullRequestMergeMethod>("merge");
|
||||
const [mergeMethodSelection, setMergeMethodSelection] = useState<{
|
||||
readonly pullRequestKey: string;
|
||||
readonly method: PullRequestMergeMethod;
|
||||
}>(() => ({ pullRequestKey, method: "merge" }));
|
||||
const mergeMethod =
|
||||
mergeMethodSelection.pullRequestKey === pullRequestKey ? mergeMethodSelection.method : "merge";
|
||||
const setMergeMethod = (method: PullRequestMergeMethod) => {
|
||||
setMergeMethodSelection({ pullRequestKey, method });
|
||||
};
|
||||
const [confirmation, setConfirmation] = useState<{
|
||||
readonly open: boolean;
|
||||
readonly action: "merge" | "close" | "enable-auto-merge";
|
||||
readonly action: "merge" | "close" | "enable-auto-merge" | "revert" | "approve-workflows";
|
||||
}>({ open: false, action: "merge" });
|
||||
const confirmAction = confirmation.action;
|
||||
// Which handoff is preparing, keyed so a per-finding button can say "Preparing..." on itself
|
||||
@@ -558,6 +577,9 @@ export function PullRequestDetailPanel({
|
||||
},
|
||||
[activity, coreDetail],
|
||||
);
|
||||
useEffect(() => {
|
||||
if (detail?.autoMergeMethod !== undefined) setMergeMethod(detail.autoMergeMethod);
|
||||
}, [detail?.autoMergeMethod, pullRequestKey]);
|
||||
const repositoryUrl = detail === null ? null : changeRequestRepositoryUrl(detail.url);
|
||||
const checkoutCommand = detail
|
||||
? pullRequestCheckoutCommand(
|
||||
@@ -636,6 +658,7 @@ export function PullRequestDetailPanel({
|
||||
void refreshFromHost();
|
||||
}, [forcedRefreshToken, refreshFromHost]);
|
||||
const runAction = useAtomCommand(pullRequestEnvironment.runAction, { reportFailure: false });
|
||||
const postComment = useAtomCommand(pullRequestEnvironment.comment, { reportFailure: false });
|
||||
// Which action is in flight, not merely that one is: every control here is disabled while any
|
||||
// of them runs, but only the button that was pressed may say what it is doing.
|
||||
const [pendingAction, setPendingAction] = useState<PullRequestAction | null>(null);
|
||||
@@ -689,13 +712,11 @@ export function PullRequestDetailPanel({
|
||||
cwd: acting?.workspaceRoot ?? detail?.workspaceRoot ?? null,
|
||||
});
|
||||
|
||||
const perform = async (
|
||||
const finishAction = async (
|
||||
action: PullRequestAction,
|
||||
method?: PullRequestMergeMethod,
|
||||
updateMethod?: PullRequestUpdateMethod,
|
||||
) => {
|
||||
if (pendingAction !== null) return;
|
||||
setPendingAction(action);
|
||||
const result = await runAction({
|
||||
environmentId,
|
||||
input: {
|
||||
@@ -723,7 +744,7 @@ export function PullRequestDetailPanel({
|
||||
title: ACTION_FAILURE_LABELS[action],
|
||||
description: readableFailure(failure, hint),
|
||||
});
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
toastManager.add({ type: "success", title: ACTION_SUCCESS_LABELS[action] });
|
||||
// A branch update moves the head commit, which leaves the diff atom pointed at a comparison
|
||||
@@ -737,6 +758,36 @@ export function PullRequestDetailPanel({
|
||||
refreshDetail();
|
||||
}
|
||||
onActed?.();
|
||||
return true;
|
||||
};
|
||||
|
||||
const perform = async (
|
||||
action: PullRequestAction,
|
||||
method?: PullRequestMergeMethod,
|
||||
updateMethod?: PullRequestUpdateMethod,
|
||||
) => {
|
||||
if (pendingAction !== null) return false;
|
||||
setPendingAction(action);
|
||||
return finishAction(action, method, updateMethod);
|
||||
};
|
||||
|
||||
const performCommentAction = async (body: string, action: "close" | "reopen") => {
|
||||
if (pendingAction !== null) return { commentPosted: false };
|
||||
setPendingAction(action);
|
||||
const commentResult = await postComment({
|
||||
environmentId,
|
||||
input: { ...reference, body },
|
||||
});
|
||||
if (commentResult._tag === "Failure") {
|
||||
setPendingAction(null);
|
||||
toastManager.add({ type: "error", title: "Could not post the comment" });
|
||||
return { commentPosted: false };
|
||||
}
|
||||
const actionSucceeded = await finishAction(action);
|
||||
// The comment is durable even if the state change was refused, so make it visible while the
|
||||
// shared action failure explains why the pull request stayed where it was.
|
||||
if (!actionSucceeded) refreshDetail();
|
||||
return { commentPosted: true };
|
||||
};
|
||||
|
||||
const saveTitle = async (next: string) => {
|
||||
@@ -1094,10 +1145,17 @@ export function PullRequestDetailPanel({
|
||||
? mergeMethod
|
||||
: (allowedMergeMethods[0] ?? "merge");
|
||||
const selectedMergeMethodLabel = MERGE_METHOD_LABELS[selectedMergeMethod];
|
||||
const pendingAutoMergeLabel = `Auto-merge (${selectedMergeMethodLabel.toLowerCase()})`;
|
||||
const conflicting = detail?.state === "open" && detail.mergeability === "conflicting";
|
||||
// Only an outright yes arms it. A host that reports nothing has not said the merge is already
|
||||
// spoken for, and an off switch for something that may not be on says the wrong thing twice.
|
||||
const autoMergeArmed = detail?.state === "open" && detail.autoMergeEnabled === true;
|
||||
const armedMergeMethod = detail?.autoMergeMethod;
|
||||
const armedAutoMergeLabel = armedMergeMethod
|
||||
? `Auto-merge (${MERGE_METHOD_LABELS[armedMergeMethod].toLowerCase()})`
|
||||
: "Auto-merge";
|
||||
const workflowApprovalsRequired =
|
||||
detail?.state === "open" ? (detail.workflowApprovalsRequired ?? 0) : 0;
|
||||
// Out of date with the base, and still cleanly mergeable — the one pairing an update button
|
||||
// exists for. Null everywhere else, including hosts that cannot compare at all.
|
||||
const freshness = detail === null ? null : resolveBaseFreshness(detail);
|
||||
@@ -1118,20 +1176,22 @@ export function PullRequestDetailPanel({
|
||||
const can = (action: PullRequestAction) =>
|
||||
detail?.capabilities.actions.includes(action) === true &&
|
||||
detail.viewerPermissions.actions.includes(action);
|
||||
// One live action holds the slot. Conflicts take priority because every other completion action
|
||||
// depends on resolving them first, even for a reader who cannot merge on the host themselves.
|
||||
const primaryAction =
|
||||
detail === null || detail.state !== "open"
|
||||
? null
|
||||
: conflicting
|
||||
? "resolve"
|
||||
: detail.isDraft && can("ready")
|
||||
? "ready"
|
||||
: !can("merge")
|
||||
? null
|
||||
: allowedMergeMethods.length > 0
|
||||
? "merge"
|
||||
: null;
|
||||
const checksState = detail ? pullRequestChecksState(detail.checks) : null;
|
||||
// The merge state remains in one stable slot from waiting through completion. Conflicts take
|
||||
// the slot while they need a person; the armed badge remains beside them so that state is not lost.
|
||||
const primaryAction = detail
|
||||
? resolvePullRequestPrimaryControl({
|
||||
state: detail.state,
|
||||
isDraft: detail.isDraft,
|
||||
mergeability: detail.mergeability,
|
||||
checksState,
|
||||
autoMergeEnabled: detail.autoMergeEnabled,
|
||||
hasMergeMethod: allowedMergeMethods.length > 0,
|
||||
canMerge: can("merge"),
|
||||
canMarkReady: can("ready"),
|
||||
canEnableAutoMerge: can("enable-auto-merge"),
|
||||
})
|
||||
: null;
|
||||
// What the menu's action group holds. Named once so the separators around it are drawn from
|
||||
// the same answer as its contents, rather than on the assumption that it has any.
|
||||
const showsDraftToggle =
|
||||
@@ -1142,10 +1202,18 @@ export function PullRequestDetailPanel({
|
||||
detail?.state === "open" &&
|
||||
((autoMergeArmed && can("disable-auto-merge")) ||
|
||||
(!autoMergeArmed &&
|
||||
primaryAction !== "enable-auto-merge" &&
|
||||
!detail.isDraft &&
|
||||
!conflicting &&
|
||||
can("enable-auto-merge") &&
|
||||
allowedMergeMethods.length > 0));
|
||||
const showsMergeNow =
|
||||
detail?.state === "open" &&
|
||||
(primaryAction === "enable-auto-merge" || primaryAction === "auto-merge-armed") &&
|
||||
can("merge") &&
|
||||
!detail.isDraft &&
|
||||
!conflicting &&
|
||||
allowedMergeMethods.length > 0;
|
||||
const showsMergeMethods =
|
||||
detail?.state === "open" &&
|
||||
can("merge") &&
|
||||
@@ -1158,7 +1226,6 @@ export function PullRequestDetailPanel({
|
||||
? resolvePullRequestState({ state: detail.state, isDraft: detail.isDraft })
|
||||
: null;
|
||||
const checksSummary = detail ? summarizePullRequestChecks(detail.checks) : null;
|
||||
const checksState = detail ? pullRequestChecksState(detail.checks) : null;
|
||||
// Approvals that still stand, and only those. A superseded one is dimmed beside the reviewer
|
||||
// who gave it, so counting it here would have the header assert in a number what the row next
|
||||
// to it has just qualified.
|
||||
@@ -1335,18 +1402,28 @@ export function PullRequestDetailPanel({
|
||||
</MenuPopup>
|
||||
</Menu>
|
||||
) : null}
|
||||
{workflowApprovalsRequired > 0 && can("approve-workflows") ? (
|
||||
<Button
|
||||
size="xs"
|
||||
variant="warning-outline"
|
||||
disabled={actionPending}
|
||||
onClick={() => setConfirmation({ open: true, action: "approve-workflows" })}
|
||||
>
|
||||
<PlayIcon className="size-3.5" />
|
||||
{pendingAction === "approve-workflows"
|
||||
? "Approving..."
|
||||
: "Approve workflows to run"}
|
||||
</Button>
|
||||
) : null}
|
||||
{/* Said where the Merge button is, because it is the answer to why nobody has
|
||||
pressed it: the merge is already asked for, and the host is holding it. */}
|
||||
{autoMergeArmed ? (
|
||||
{autoMergeArmed && primaryAction !== "auto-merge-armed" ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Badge
|
||||
variant="info"
|
||||
className="h-5 shrink-0 gap-1 rounded px-1.5 text-[10px]"
|
||||
>
|
||||
<GitMergeIcon aria-hidden className="size-3" />
|
||||
Auto-merge
|
||||
<Badge size="control" variant="info">
|
||||
<GitMergeIcon aria-hidden className="size-3.5" />
|
||||
{armedAutoMergeLabel}
|
||||
</Badge>
|
||||
}
|
||||
/>
|
||||
@@ -1369,6 +1446,29 @@ export function PullRequestDetailPanel({
|
||||
<Button size="xs" disabled={actionPending} onClick={() => void perform("ready")}>
|
||||
Ready for review
|
||||
</Button>
|
||||
) : primaryAction === "enable-auto-merge" ? (
|
||||
<Button
|
||||
size="xs"
|
||||
disabled={actionPending}
|
||||
onClick={() => setConfirmation({ open: true, action: "enable-auto-merge" })}
|
||||
>
|
||||
<GitMergeIcon className="size-3.5" />
|
||||
{pendingAction === "enable-auto-merge" ? "Enabling..." : pendingAutoMergeLabel}
|
||||
</Button>
|
||||
) : primaryAction === "auto-merge-armed" ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Badge size="control" variant="info">
|
||||
<GitMergeIcon className="size-3.5" />
|
||||
{armedAutoMergeLabel}
|
||||
</Badge>
|
||||
}
|
||||
/>
|
||||
<TooltipPopup side="top">
|
||||
The host will merge this on its own once its requirements are met
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
) : primaryAction === "merge" ? (
|
||||
<Button
|
||||
size="xs"
|
||||
@@ -1377,6 +1477,12 @@ export function PullRequestDetailPanel({
|
||||
>
|
||||
{pendingAction === "merge" ? "Merging..." : selectedMergeMethodLabel}
|
||||
</Button>
|
||||
) : (primaryAction === "merged" || primaryAction === "closed") &&
|
||||
statePresentation !== null ? (
|
||||
<Badge size="control" variant="outline" className={statePresentation.toneClassName}>
|
||||
<statePresentation.Icon className="size-3.5" />
|
||||
{statePresentation.label}
|
||||
</Badge>
|
||||
) : null}
|
||||
<Menu>
|
||||
<MenuTrigger
|
||||
@@ -1447,11 +1553,18 @@ export function PullRequestDetailPanel({
|
||||
{detail.isDraft ? "Ready for review" : "Convert to draft"}
|
||||
</MenuItem>
|
||||
) : null}
|
||||
{/* The same merge, left with the host to carry out once the things it
|
||||
waits on are done. It is offered beside the merge rather than instead
|
||||
of it, because the reader who can wait and the reader who cannot are
|
||||
the same person on different days — and a conflicting branch is neither,
|
||||
since nothing the host waits for will clear it. */}
|
||||
{showsMergeNow ? (
|
||||
<MenuItem
|
||||
disabled={actionPending}
|
||||
onClick={() => setConfirmation({ open: true, action: "merge" })}
|
||||
>
|
||||
<GitMergeIcon className="size-3.5" />
|
||||
Merge now
|
||||
</MenuItem>
|
||||
) : null}
|
||||
{/* The same merge, left with the host to carry out once its requirements
|
||||
pass. A conflicting branch cannot be armed because nothing the host
|
||||
waits for will clear the conflict. */}
|
||||
{autoMergeArmed && can("disable-auto-merge") ? (
|
||||
<MenuItem
|
||||
disabled={actionPending}
|
||||
@@ -1460,11 +1573,7 @@ export function PullRequestDetailPanel({
|
||||
<GitMergeIcon className="size-3.5" />
|
||||
Disable auto-merge
|
||||
</MenuItem>
|
||||
) : !autoMergeArmed &&
|
||||
!detail.isDraft &&
|
||||
!conflicting &&
|
||||
can("enable-auto-merge") &&
|
||||
allowedMergeMethods.length > 0 ? (
|
||||
) : showsAutoMerge ? (
|
||||
<MenuItem
|
||||
disabled={actionPending}
|
||||
onClick={() =>
|
||||
@@ -1485,7 +1594,9 @@ export function PullRequestDetailPanel({
|
||||
{/* Only below the draft control. A host with no draft of its own, or
|
||||
a draft whose control is already the header button, would leave
|
||||
this against the separator that opened the group. */}
|
||||
{showsDraftToggle ? <MenuSeparator /> : null}
|
||||
{showsDraftToggle || showsMergeNow || showsAutoMerge ? (
|
||||
<MenuSeparator />
|
||||
) : null}
|
||||
<MenuRadioGroup
|
||||
value={selectedMergeMethod}
|
||||
onValueChange={(method) =>
|
||||
@@ -1507,7 +1618,7 @@ export function PullRequestDetailPanel({
|
||||
) : null}
|
||||
{pullRequestActionMenuHasGroup(
|
||||
showsDraftToggle,
|
||||
showsAutoMerge,
|
||||
showsAutoMerge || showsMergeNow,
|
||||
showsMergeMethods,
|
||||
) ? (
|
||||
<MenuSeparator />
|
||||
@@ -1542,6 +1653,17 @@ export function PullRequestDetailPanel({
|
||||
Reopen pull request
|
||||
</MenuItem>
|
||||
</>
|
||||
) : detail.state === "merged" && can("revert") ? (
|
||||
<>
|
||||
<MenuSeparator />
|
||||
<MenuItem
|
||||
disabled={actionPending}
|
||||
onClick={() => setConfirmation({ open: true, action: "revert" })}
|
||||
>
|
||||
<RotateCcwIcon className="size-3.5" />
|
||||
Revert changes
|
||||
</MenuItem>
|
||||
</>
|
||||
) : null}
|
||||
</MenuPopup>
|
||||
</Menu>
|
||||
@@ -1987,6 +2109,8 @@ export function PullRequestDetailPanel({
|
||||
fixFindingLabel={handoffLabels.fixFinding}
|
||||
fixCheckLabel={handoffLabels.fixCheck}
|
||||
onFixFinding={startFixFinding}
|
||||
actionPending={actionPending}
|
||||
onCommentAction={performCommentAction}
|
||||
onRefresh={refreshDetail}
|
||||
/>
|
||||
</div>
|
||||
@@ -2049,7 +2173,11 @@ export function PullRequestDetailPanel({
|
||||
? "Merge pull request?"
|
||||
: confirmAction === "enable-auto-merge"
|
||||
? "Enable auto-merge?"
|
||||
: "Close pull request?"}
|
||||
: confirmAction === "revert"
|
||||
? "Revert these changes?"
|
||||
: confirmAction === "approve-workflows"
|
||||
? "Approve workflows to run?"
|
||||
: "Close pull request?"}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{confirmAction === "merge"
|
||||
@@ -2059,7 +2187,11 @@ export function PullRequestDetailPanel({
|
||||
// may be immediately — there is no telling from here whether anything is
|
||||
// still outstanding.
|
||||
`This merges #${reference.number} using ${selectedMergeMethod} as soon as the host considers it ready, which may be immediately.`
|
||||
: `This closes #${reference.number} without merging it.`}
|
||||
: confirmAction === "revert"
|
||||
? `This opens a new pull request that reverses the changes merged by #${reference.number}.`
|
||||
: confirmAction === "approve-workflows"
|
||||
? `This allows ${workflowApprovalsRequired} ${workflowApprovalsRequired === 1 ? "workflow" : "workflows"} from #${reference.number} to run. Review the code and workflow changes first.`
|
||||
: `This closes #${reference.number} without merging it.`}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
@@ -2076,6 +2208,8 @@ export function PullRequestDetailPanel({
|
||||
if (action === "merge") void perform("merge", selectedMergeMethod);
|
||||
if (action === "enable-auto-merge")
|
||||
void perform("enable-auto-merge", selectedMergeMethod);
|
||||
if (action === "revert") void perform("revert");
|
||||
if (action === "approve-workflows") void perform("approve-workflows");
|
||||
if (action === "close") void perform("close");
|
||||
}}
|
||||
>
|
||||
@@ -2083,7 +2217,11 @@ export function PullRequestDetailPanel({
|
||||
? selectedMergeMethodLabel
|
||||
: confirmAction === "enable-auto-merge"
|
||||
? "Enable auto-merge"
|
||||
: "Close"}
|
||||
: confirmAction === "revert"
|
||||
? "Create revert PR"
|
||||
: confirmAction === "approve-workflows"
|
||||
? "Approve and run"
|
||||
: "Close"}
|
||||
</Button>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogPopup>
|
||||
|
||||
@@ -524,7 +524,7 @@ export function PullRequestFiltersMenu({
|
||||
<ListFilterIcon className="size-4" />
|
||||
<span>Filters</span>
|
||||
{filterCount > 0 ? (
|
||||
<span className="rounded-full bg-primary/10 px-1.5 text-xs text-primary tabular-nums">
|
||||
<span className="rounded-full bg-muted px-1.5 text-xs text-muted-foreground tabular-nums">
|
||||
{filterCount}
|
||||
</span>
|
||||
) : null}
|
||||
|
||||
@@ -9,9 +9,11 @@ import {
|
||||
ArrowDownUpIcon,
|
||||
ChevronDownIcon,
|
||||
ChevronRightIcon,
|
||||
GitPullRequestClosedIcon,
|
||||
HammerIcon,
|
||||
MessageSquareIcon,
|
||||
PencilIcon,
|
||||
RotateCcwIcon,
|
||||
SendIcon,
|
||||
TagIcon,
|
||||
UsersIcon,
|
||||
@@ -308,20 +310,43 @@ function Section({
|
||||
function CommentComposer({
|
||||
environmentId,
|
||||
detail,
|
||||
actionPending,
|
||||
onCommentAction,
|
||||
onCommented,
|
||||
}: {
|
||||
environmentId: EnvironmentId;
|
||||
detail: PullRequestDetailView;
|
||||
actionPending: boolean;
|
||||
onCommentAction: (
|
||||
body: string,
|
||||
action: "close" | "reopen",
|
||||
) => Promise<{ readonly commentPosted: boolean }>;
|
||||
onCommented: () => void;
|
||||
}) {
|
||||
const [body, setBody] = useState("");
|
||||
const [posting, setPosting] = useState(false);
|
||||
const [submitting, setSubmitting] = useState<"comment" | "close" | "reopen" | null>(null);
|
||||
const postComment = useAtomCommand(pullRequestEnvironment.comment, { reportFailure: false });
|
||||
const followUpAction =
|
||||
detail.state === "open" &&
|
||||
detail.capabilities.actions.includes("close") &&
|
||||
detail.viewerPermissions.actions.includes("close")
|
||||
? ("close" as const)
|
||||
: detail.state === "closed" &&
|
||||
detail.capabilities.actions.includes("reopen") &&
|
||||
detail.viewerPermissions.actions.includes("reopen")
|
||||
? ("reopen" as const)
|
||||
: null;
|
||||
|
||||
const submit = async () => {
|
||||
const submit = async (action: "comment" | "close" | "reopen") => {
|
||||
const trimmed = body.trim();
|
||||
if (trimmed.length === 0 || posting) return;
|
||||
setPosting(true);
|
||||
if (trimmed.length === 0 || submitting !== null || actionPending) return;
|
||||
setSubmitting(action);
|
||||
if (action !== "comment") {
|
||||
const result = await onCommentAction(trimmed, action);
|
||||
if (result.commentPosted) setBody("");
|
||||
setSubmitting(null);
|
||||
return;
|
||||
}
|
||||
const result = await postComment({
|
||||
environmentId,
|
||||
input: {
|
||||
@@ -331,12 +356,13 @@ function CommentComposer({
|
||||
body: trimmed,
|
||||
},
|
||||
});
|
||||
setPosting(false);
|
||||
if (result._tag === "Failure") {
|
||||
setSubmitting(null);
|
||||
toastManager.add({ type: "error", title: "Could not post the comment" });
|
||||
return;
|
||||
}
|
||||
setBody("");
|
||||
setSubmitting(null);
|
||||
onCommented();
|
||||
};
|
||||
|
||||
@@ -345,22 +371,43 @@ function CommentComposer({
|
||||
<Textarea
|
||||
// Locked while posting: the body is cleared on success, which would otherwise throw
|
||||
// away a new draft typed while the request was still in flight.
|
||||
disabled={posting}
|
||||
disabled={submitting !== null || actionPending}
|
||||
value={body}
|
||||
rows={3}
|
||||
placeholder="Leave a comment"
|
||||
aria-label="Comment on this pull request"
|
||||
onChange={(event) => setBody(event.target.value)}
|
||||
/>
|
||||
<div className="flex justify-end">
|
||||
<div className="flex justify-end gap-2">
|
||||
{followUpAction === null ? null : (
|
||||
<Button
|
||||
size="xs"
|
||||
variant={followUpAction === "close" ? "destructive-outline" : "outline"}
|
||||
disabled={body.trim().length === 0 || submitting !== null || actionPending}
|
||||
onClick={() => void submit(followUpAction)}
|
||||
>
|
||||
{followUpAction === "close" ? (
|
||||
<GitPullRequestClosedIcon className="size-3.5" />
|
||||
) : (
|
||||
<RotateCcwIcon className="size-3.5" />
|
||||
)}
|
||||
{submitting === followUpAction
|
||||
? followUpAction === "close"
|
||||
? "Closing..."
|
||||
: "Reopening..."
|
||||
: followUpAction === "close"
|
||||
? "Close with comment"
|
||||
: "Reopen with comment"}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
size="xs"
|
||||
variant="outline"
|
||||
disabled={body.trim().length === 0 || posting}
|
||||
onClick={() => void submit()}
|
||||
disabled={body.trim().length === 0 || submitting !== null || actionPending}
|
||||
onClick={() => void submit("comment")}
|
||||
>
|
||||
<SendIcon className="size-3.5" />
|
||||
{posting ? "Posting..." : "Comment"}
|
||||
{submitting === "comment" ? "Posting..." : "Comment"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -383,6 +430,8 @@ export function PullRequestSummaryTab({
|
||||
fixFindingLabel = "Fix in a thread",
|
||||
fixCheckLabel = "Fix",
|
||||
onFixFinding,
|
||||
actionPending,
|
||||
onCommentAction,
|
||||
onRefresh,
|
||||
}: {
|
||||
environmentId: EnvironmentId;
|
||||
@@ -395,6 +444,11 @@ export function PullRequestSummaryTab({
|
||||
fixFindingLabel?: string;
|
||||
fixCheckLabel?: string;
|
||||
onFixFinding?: (finding: PullRequestFinding) => void;
|
||||
actionPending: boolean;
|
||||
onCommentAction: (
|
||||
body: string,
|
||||
action: "close" | "reopen",
|
||||
) => Promise<{ readonly commentPosted: boolean }>;
|
||||
onRefresh: () => void;
|
||||
}) {
|
||||
// Keyed by the pull request, so opening another one starts at the end of its conversation
|
||||
@@ -718,7 +772,7 @@ export function PullRequestSummaryTab({
|
||||
<PullRequestCheckStatusIcon status={check.status} />
|
||||
<span className="min-w-0 flex-1 truncate">{check.name}</span>
|
||||
<span className="shrink-0 text-muted-foreground">
|
||||
{pullRequestCheckStatusLabel(check.status)}
|
||||
{pullRequestCheckStatusLabel(check)}
|
||||
</span>
|
||||
</button>
|
||||
{/* Only where there is something to fix. A passing check has no failure to
|
||||
@@ -919,6 +973,8 @@ export function PullRequestSummaryTab({
|
||||
key={`${environmentId}:${detail.projectId}/${detail.repository}#${detail.number}`}
|
||||
environmentId={environmentId}
|
||||
detail={detail}
|
||||
actionPending={actionPending}
|
||||
onCommentAction={onCommentAction}
|
||||
onCommented={onRefresh}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
@@ -5,10 +5,17 @@ import { describe, expect, it } from "vite-plus/test";
|
||||
import { PullRequestChecksPopover } from "./PullRequestChecksPopover";
|
||||
import type { EnvironmentPullRequestEntry } from "./pullRequestList.logic";
|
||||
import { PullRequestRow } from "./PullRequestRow";
|
||||
import { pullRequestChecksState } from "./pullRequestPresentation";
|
||||
import {
|
||||
pullRequestChecksState,
|
||||
pullRequestCheckStatusLabel,
|
||||
summarizePullRequestChecks,
|
||||
} from "./pullRequestPresentation";
|
||||
|
||||
function check(status: PullRequestCheck["status"]): PullRequestCheck {
|
||||
return { name: `check-${status}`, status, description: null, url: null };
|
||||
function check(
|
||||
status: PullRequestCheck["status"],
|
||||
overrides: Partial<PullRequestCheck> = {},
|
||||
): PullRequestCheck {
|
||||
return { name: `check-${status}`, status, description: null, url: null, ...overrides };
|
||||
}
|
||||
|
||||
describe("pullRequestChecksState", () => {
|
||||
@@ -18,11 +25,31 @@ describe("pullRequestChecksState", () => {
|
||||
);
|
||||
expect(pullRequestChecksState([check("success"), check("cancelled")])).toBe("failing");
|
||||
expect(pullRequestChecksState([check("success"), check("pending")])).toBe("pending");
|
||||
expect(pullRequestChecksState([check("success"), check("action-required")])).toBe("pending");
|
||||
expect(pullRequestChecksState([check("success")])).toBe("passing");
|
||||
// Skipped and neutral are neither a pass nor a failure, so they are no verdict at all.
|
||||
expect(pullRequestChecksState([check("skipped"), check("neutral")])).toBe(null);
|
||||
expect(pullRequestChecksState([])).toBe(null);
|
||||
});
|
||||
|
||||
it("names workflow approval instead of claiming every check passed", () => {
|
||||
const workflow = check("action-required", {
|
||||
url: "https://github.com/acme/web/actions/runs/42/job/7",
|
||||
});
|
||||
const manualGate = check("action-required", { url: "https://example.com/manual-gate" });
|
||||
expect(pullRequestCheckStatusLabel(workflow)).toBe("Awaiting approval");
|
||||
expect(pullRequestCheckStatusLabel(manualGate)).toBe("Awaiting action");
|
||||
expect(summarizePullRequestChecks([check("success"), workflow])).toBe(
|
||||
"1 workflow awaiting approval",
|
||||
);
|
||||
expect(summarizePullRequestChecks([check("failure"), workflow])).toBe("1 of 2 failing");
|
||||
expect(summarizePullRequestChecks([check("success"), manualGate])).toBe(
|
||||
"1 check awaiting action",
|
||||
);
|
||||
expect(summarizePullRequestChecks([workflow, manualGate])).toBe(
|
||||
"1 workflow and 1 check awaiting action",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
/** Every element of the tree the row returned, so a nested indicator can be looked for. */
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
pullRequestHandoffLabels,
|
||||
pullRequestReviewOutcome,
|
||||
readableFailure,
|
||||
resolvePullRequestPrimaryControl,
|
||||
shouldRefreshPullRequestActivity,
|
||||
resolveBaseFreshness,
|
||||
buildPullRequestTimeline,
|
||||
@@ -146,6 +147,54 @@ describe("pull request action menu", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("pull request primary control", () => {
|
||||
const open = {
|
||||
state: "open" as const,
|
||||
isDraft: false,
|
||||
mergeability: "mergeable" as const,
|
||||
checksState: "passing" as const,
|
||||
autoMergeEnabled: false,
|
||||
hasMergeMethod: true,
|
||||
canMerge: true,
|
||||
canMarkReady: true,
|
||||
canEnableAutoMerge: true,
|
||||
};
|
||||
|
||||
it("moves pending and failing checks to auto-merge", () => {
|
||||
expect(resolvePullRequestPrimaryControl({ ...open, checksState: "pending" })).toBe(
|
||||
"enable-auto-merge",
|
||||
);
|
||||
expect(resolvePullRequestPrimaryControl({ ...open, checksState: "failing" })).toBe(
|
||||
"enable-auto-merge",
|
||||
);
|
||||
});
|
||||
|
||||
it("does not offer auto-merge while the host state is unknown", () => {
|
||||
expect(
|
||||
resolvePullRequestPrimaryControl({
|
||||
...open,
|
||||
checksState: "pending",
|
||||
autoMergeEnabled: undefined,
|
||||
}),
|
||||
).toBe("merge");
|
||||
});
|
||||
|
||||
it("keeps armed and terminal states in the merge button slot", () => {
|
||||
expect(resolvePullRequestPrimaryControl({ ...open, autoMergeEnabled: true })).toBe(
|
||||
"auto-merge-armed",
|
||||
);
|
||||
expect(resolvePullRequestPrimaryControl({ ...open, state: "merged" })).toBe("merged");
|
||||
expect(resolvePullRequestPrimaryControl({ ...open, state: "closed" })).toBe("closed");
|
||||
});
|
||||
|
||||
it("keeps conflicts and drafts actionable before merge", () => {
|
||||
expect(resolvePullRequestPrimaryControl({ ...open, mergeability: "conflicting" })).toBe(
|
||||
"resolve",
|
||||
);
|
||||
expect(resolvePullRequestPrimaryControl({ ...open, isDraft: true })).toBe("ready");
|
||||
});
|
||||
});
|
||||
|
||||
describe("pull request state description", () => {
|
||||
it("keeps draft and conflicts orthogonal to the terminal states", () => {
|
||||
expect(describePullRequestState("open", true)).toBe("Draft");
|
||||
@@ -1243,7 +1292,9 @@ describe("which actions need the host read again after they run", () => {
|
||||
// Imported from the contract rather than hand-listed, so a new PullRequestAction fails this
|
||||
// test until somebody decides which side of the diff it belongs on.
|
||||
expect(PullRequestAction.literals.map(pullRequestActionNeedsHostRefresh)).toEqual(
|
||||
PullRequestAction.literals.map((action) => action === "update-branch"),
|
||||
PullRequestAction.literals.map(
|
||||
(action) => action === "update-branch" || action === "approve-workflows",
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1260,6 +1311,7 @@ describe("which actions need the host read again after they run", () => {
|
||||
"enable-auto-merge",
|
||||
"disable-auto-merge",
|
||||
"merge",
|
||||
"revert",
|
||||
] as const) {
|
||||
expect(pullRequestActionNeedsHostRefresh(action)).toBe(false);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import type {
|
||||
PullRequestActor,
|
||||
PullRequestBaseComparison,
|
||||
PullRequestCheck,
|
||||
PullRequestChecksState,
|
||||
PullRequestComment,
|
||||
PullRequestCommit,
|
||||
PullRequestDetailView,
|
||||
@@ -20,6 +21,45 @@ import { inferReviewCommentFenceLanguage, type ReviewCommentContext } from "~/re
|
||||
const safeShellArgument = /^[A-Za-z0-9._/@+=,-]+$/;
|
||||
const bitbucketRepositoryName = /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;
|
||||
|
||||
export type PullRequestPrimaryControl =
|
||||
| "resolve"
|
||||
| "ready"
|
||||
| "merge"
|
||||
| "enable-auto-merge"
|
||||
| "auto-merge-armed"
|
||||
| "merged"
|
||||
| "closed"
|
||||
| null;
|
||||
|
||||
/** The one merge-area state shown in the header, including terminal and deferred states. */
|
||||
export function resolvePullRequestPrimaryControl(input: {
|
||||
readonly state: PullRequestState;
|
||||
readonly isDraft: boolean;
|
||||
readonly mergeability: PullRequestMergeability;
|
||||
readonly checksState: PullRequestChecksState | null;
|
||||
readonly autoMergeEnabled: boolean | undefined;
|
||||
readonly hasMergeMethod: boolean;
|
||||
readonly canMerge: boolean;
|
||||
readonly canMarkReady: boolean;
|
||||
readonly canEnableAutoMerge: boolean;
|
||||
}): PullRequestPrimaryControl {
|
||||
if (input.state === "merged") return "merged";
|
||||
if (input.state === "closed") return "closed";
|
||||
if (input.mergeability === "conflicting") return "resolve";
|
||||
if (input.isDraft) return input.canMarkReady ? "ready" : null;
|
||||
if (input.autoMergeEnabled) return "auto-merge-armed";
|
||||
if (!input.hasMergeMethod) return null;
|
||||
if (
|
||||
input.autoMergeEnabled === false &&
|
||||
input.checksState !== null &&
|
||||
input.checksState !== "passing" &&
|
||||
input.canEnableAutoMerge
|
||||
) {
|
||||
return "enable-auto-merge";
|
||||
}
|
||||
return input.canMerge ? "merge" : null;
|
||||
}
|
||||
|
||||
export function pullRequestCheckoutCommand(
|
||||
provider: SourceControlProviderKind,
|
||||
number: number,
|
||||
@@ -949,11 +989,9 @@ export function resolveBaseFreshness(detail: {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a completed action leaves the diff atom pointed at a comparison that no longer exists,
|
||||
* the same staleness the manual refresh button fixes. Only `update-branch` moves the head commit;
|
||||
* a merge moves the branch too, but it also closes the pull request, where the diff is no longer
|
||||
* what anyone is looking at. Written as a `Record` so a new `PullRequestAction` fails to compile
|
||||
* here until somebody decides which side of the diff it belongs on.
|
||||
* Whether a completed action needs the uncached host read rather than the cheaper detail refresh.
|
||||
* Updating a branch moves the diff's head. Approving workflows changes data GitHub omits from the
|
||||
* normal pull-request detail. Written as a `Record` so every new action makes that choice here.
|
||||
*/
|
||||
const ACTION_NEEDS_HOST_REFRESH: Record<PullRequestAction, boolean> = {
|
||||
"update-branch": true,
|
||||
@@ -964,6 +1002,8 @@ const ACTION_NEEDS_HOST_REFRESH: Record<PullRequestAction, boolean> = {
|
||||
reopen: false,
|
||||
"enable-auto-merge": false,
|
||||
"disable-auto-merge": false,
|
||||
revert: false,
|
||||
"approve-workflows": true,
|
||||
};
|
||||
|
||||
export function pullRequestActionNeedsHostRefresh(action: PullRequestAction): boolean {
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
readPullRequestListSnapshot,
|
||||
writePullRequestListSnapshot,
|
||||
rankPullRequestMatches,
|
||||
rankPullRequestsByMergeReadiness,
|
||||
scorePullRequestMatch,
|
||||
retainVisiblePullRequestStatsBatches,
|
||||
withDiffStat,
|
||||
@@ -29,6 +30,11 @@ import {
|
||||
resolveSelectedEnvironmentId,
|
||||
type EnvironmentPullRequestEntry,
|
||||
} from "./pullRequestList.logic";
|
||||
import {
|
||||
pullRequestListPreferences,
|
||||
readPullRequestListPreferences,
|
||||
writePullRequestListPreferences,
|
||||
} from "./pullRequestListPreferences";
|
||||
|
||||
const VIEWERS = { "github.com": "Bilal" } as const;
|
||||
const NO_VIEWERS = {} as const;
|
||||
@@ -656,6 +662,99 @@ describe("ranking what a search found", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("default merge-readiness ranking", () => {
|
||||
it("puts ready work first, finished work after open work, and every conflict last", () => {
|
||||
const conflict = entry({
|
||||
number: 1,
|
||||
mergeability: "conflicting",
|
||||
checksState: "passing",
|
||||
reviewDecision: "approved",
|
||||
updatedAt: "2026-09-01T00:00:00Z",
|
||||
});
|
||||
const other = entry({
|
||||
number: 2,
|
||||
checksState: "pending",
|
||||
updatedAt: "2026-08-01T00:00:00Z",
|
||||
});
|
||||
const green = entry({
|
||||
number: 3,
|
||||
checksState: "passing",
|
||||
reviewDecision: "review-required",
|
||||
updatedAt: "2026-07-01T00:00:00Z",
|
||||
});
|
||||
const approved = entry({
|
||||
number: 4,
|
||||
checksState: "passing",
|
||||
reviewDecision: "approved",
|
||||
updatedAt: "2026-06-01T00:00:00Z",
|
||||
});
|
||||
const draft = entry({
|
||||
number: 5,
|
||||
isDraft: true,
|
||||
checksState: "passing",
|
||||
reviewDecision: "approved",
|
||||
updatedAt: "2026-09-02T00:00:00Z",
|
||||
});
|
||||
const finished = entry({
|
||||
number: 6,
|
||||
state: "merged",
|
||||
checksState: "passing",
|
||||
reviewDecision: "approved",
|
||||
updatedAt: "2026-09-03T00:00:00Z",
|
||||
});
|
||||
|
||||
expect(
|
||||
rankPullRequestsByMergeReadiness([conflict, other, green, approved, draft, finished]).map(
|
||||
(row) => row.number,
|
||||
),
|
||||
).toEqual([4, 3, 5, 2, 6, 1]);
|
||||
});
|
||||
|
||||
it("uses recency inside one readiness tier", () => {
|
||||
const older = entry({ number: 1, checksState: "passing" });
|
||||
const newer = entry({
|
||||
number: 2,
|
||||
checksState: "passing",
|
||||
updatedAt: "2026-08-01T00:00:00Z",
|
||||
});
|
||||
|
||||
expect(rankPullRequestsByMergeReadiness([older, newer]).map((row) => row.number)).toEqual([
|
||||
2, 1,
|
||||
]);
|
||||
});
|
||||
|
||||
it("puts the smallest measured change first inside a readiness tier", () => {
|
||||
const larger = entry({
|
||||
number: 1,
|
||||
checksState: "passing",
|
||||
reviewDecision: "approved",
|
||||
additions: 40,
|
||||
deletions: 10,
|
||||
updatedAt: "2026-09-01T00:00:00Z",
|
||||
});
|
||||
const smaller = entry({
|
||||
number: 2,
|
||||
checksState: "passing",
|
||||
reviewDecision: "approved",
|
||||
additions: 3,
|
||||
deletions: 2,
|
||||
updatedAt: "2026-08-01T00:00:00Z",
|
||||
});
|
||||
const unknown = entry({
|
||||
number: 3,
|
||||
checksState: "passing",
|
||||
reviewDecision: "approved",
|
||||
additions: 0,
|
||||
deletions: 0,
|
||||
updatedAt: "2026-09-02T00:00:00Z",
|
||||
});
|
||||
|
||||
expect(
|
||||
rankPullRequestsByMergeReadiness([larger, unknown, smaller]).map((row) => row.number),
|
||||
).toEqual([2, 1, 3]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("line counts that arrive after the rows", () => {
|
||||
const stats = new Map([["env-1 project-1 7", { additions: 42, deletions: 3 }]]);
|
||||
|
||||
@@ -858,6 +957,74 @@ describe("the list snapshot across a reload", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("remembered pull request list controls", () => {
|
||||
const makeStorage = () => {
|
||||
const held = new Map<string, string>();
|
||||
return {
|
||||
getItem: (key: string) => held.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => void held.set(key, value),
|
||||
};
|
||||
};
|
||||
|
||||
it("restores every filter and the selected sort", () => {
|
||||
const storage = makeStorage();
|
||||
const preferences = {
|
||||
involvement: "reviewing",
|
||||
state: "merged",
|
||||
environmentId: "env-1" as EnvironmentId,
|
||||
projectId: "project-1" as ProjectId,
|
||||
host: "github.com",
|
||||
q: "workflow",
|
||||
draft: "hide",
|
||||
review: "approved",
|
||||
checks: "passing",
|
||||
author: "octocat",
|
||||
labels: ["bug", "priority"],
|
||||
sort: "largest",
|
||||
} as const;
|
||||
|
||||
writePullRequestListPreferences(preferences, storage);
|
||||
expect(readPullRequestListPreferences(storage)).toEqual(preferences);
|
||||
});
|
||||
|
||||
it("omits the default sort from storage", () => {
|
||||
expect(
|
||||
pullRequestListPreferences({
|
||||
involvement: "all",
|
||||
state: "open",
|
||||
sort: "ready",
|
||||
}),
|
||||
).toEqual({ involvement: "all", state: "open" });
|
||||
});
|
||||
|
||||
it("keeps an explicit recency sort", () => {
|
||||
expect(
|
||||
pullRequestListPreferences({ involvement: "all", state: "open", sort: "updated" }),
|
||||
).toEqual({ involvement: "all", state: "open", sort: "updated" });
|
||||
});
|
||||
|
||||
it("falls back to the default controls when storage is corrupt", () => {
|
||||
const storage = makeStorage();
|
||||
storage.setItem("t3.pullRequests.preferences", "{not json");
|
||||
expect(readPullRequestListPreferences(storage)).toEqual({ involvement: "all", state: "open" });
|
||||
});
|
||||
|
||||
it("falls back when browser policy denies storage", () => {
|
||||
const denied = {
|
||||
getItem: () => {
|
||||
throw new Error("storage denied");
|
||||
},
|
||||
setItem: () => {
|
||||
throw new Error("storage denied");
|
||||
},
|
||||
};
|
||||
expect(readPullRequestListPreferences(denied)).toEqual({ involvement: "all", state: "open" });
|
||||
expect(() =>
|
||||
writePullRequestListPreferences({ involvement: "all", state: "open" }, denied),
|
||||
).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
const ENV_1 = "env-1" as EnvironmentId;
|
||||
const ENV_2 = "env-2" as EnvironmentId;
|
||||
|
||||
|
||||
@@ -985,7 +985,7 @@ export function scorePullRequestMatch(entry: PullRequestListEntry, query: string
|
||||
|
||||
/**
|
||||
* Search results in the order they answer the question, most convincing first, and by recency
|
||||
* among equals. Only for a search: without one, a listing is a timeline and recency is the order.
|
||||
* among equals. Without a search, preserve the host order for the caller's browse-time ranking.
|
||||
*/
|
||||
export function rankPullRequestMatches<Entry extends PullRequestListEntry>(
|
||||
entries: ReadonlyArray<Entry>,
|
||||
@@ -998,6 +998,35 @@ export function rankPullRequestMatches<Entry extends PullRequestListEntry>(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The default review queue: work that is green and approved, then green work still waiting on a
|
||||
* verdict, then everything else still open. Drafts stay in that third tier because their author
|
||||
* has not made them mergeable yet. Finished work follows open work when all states are visible. A
|
||||
* known conflict is never ready, whatever its checks, review or state say, so it stays at the
|
||||
* bottom. Smaller measured changes come first within a tier; recency only breaks a remaining tie.
|
||||
*/
|
||||
export function rankPullRequestsByMergeReadiness<Entry extends PullRequestListEntry>(
|
||||
entries: ReadonlyArray<Entry>,
|
||||
hasMeasuredSize: (entry: Entry) => boolean = (entry) => entry.additions + entry.deletions > 0,
|
||||
): ReadonlyArray<Entry> {
|
||||
const tier = (entry: Entry) => {
|
||||
if (entry.mergeability === "conflicting") return 4;
|
||||
if (entry.state !== "open") return 3;
|
||||
if (entry.isDraft) return 2;
|
||||
if (entry.checksState === "passing" && entry.reviewDecision === "approved") return 0;
|
||||
if (entry.checksState === "passing") return 1;
|
||||
return 2;
|
||||
};
|
||||
return entries.toSorted((left, right) => {
|
||||
const byTier = tier(left) - tier(right);
|
||||
if (byTier !== 0) return byTier;
|
||||
const byMeasurement = Number(hasMeasuredSize(right)) - Number(hasMeasuredSize(left));
|
||||
if (byMeasurement !== 0) return byMeasurement;
|
||||
const bySize = left.additions + left.deletions - (right.additions + right.deletions);
|
||||
return bySize !== 0 ? bySize : right.updatedAt.localeCompare(left.updatedAt);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A row with the line counts that arrived after it did. Only where the host left them out — a
|
||||
* listing that carried them is not second-guessed — and only where they have arrived, since a row
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import {
|
||||
EnvironmentId,
|
||||
ProjectId,
|
||||
PullRequestInvolvement,
|
||||
PullRequestListFilters,
|
||||
PullRequestListState,
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
export const PullRequestListSort = Schema.Literals([
|
||||
"ready",
|
||||
"updated",
|
||||
"newest",
|
||||
"oldest",
|
||||
"largest",
|
||||
"smallest",
|
||||
]);
|
||||
export type PullRequestListSort = typeof PullRequestListSort.Type;
|
||||
|
||||
export interface PullRequestListPreferences {
|
||||
readonly involvement: PullRequestInvolvement;
|
||||
readonly state: PullRequestListState;
|
||||
readonly environmentId?: EnvironmentId;
|
||||
readonly projectId?: ProjectId;
|
||||
readonly host?: string;
|
||||
readonly q?: string;
|
||||
readonly draft?: "only" | "hide";
|
||||
readonly review?: NonNullable<PullRequestListFilters["review"]>;
|
||||
readonly checks?: NonNullable<PullRequestListFilters["checks"]>;
|
||||
readonly author?: string;
|
||||
readonly labels?: ReadonlyArray<string>;
|
||||
readonly sort?: PullRequestListSort;
|
||||
}
|
||||
|
||||
export type PullRequestListPreferencePatch = {
|
||||
[Key in keyof PullRequestListPreferences]?: PullRequestListPreferences[Key] | undefined;
|
||||
};
|
||||
|
||||
export const DEFAULT_PULL_REQUEST_LIST_PREFERENCES = {
|
||||
involvement: "all",
|
||||
state: "open",
|
||||
} as const satisfies PullRequestListPreferences;
|
||||
|
||||
const BoundedPreference = Schema.String.check(Schema.isMaxLength(200));
|
||||
const PullRequestListPreferencesSchema = Schema.Struct({
|
||||
involvement: PullRequestInvolvement,
|
||||
state: PullRequestListState,
|
||||
environmentId: Schema.optional(EnvironmentId),
|
||||
projectId: Schema.optional(ProjectId),
|
||||
host: Schema.optional(BoundedPreference),
|
||||
q: Schema.optional(BoundedPreference),
|
||||
draft: PullRequestListFilters.fields.draft,
|
||||
review: PullRequestListFilters.fields.review,
|
||||
checks: PullRequestListFilters.fields.checks,
|
||||
author: Schema.optional(BoundedPreference),
|
||||
labels: Schema.optional(Schema.Array(BoundedPreference).check(Schema.isMaxLength(10))),
|
||||
sort: Schema.optional(PullRequestListSort),
|
||||
});
|
||||
|
||||
const decodePullRequestListPreferences = Schema.decodeUnknownOption(
|
||||
PullRequestListPreferencesSchema,
|
||||
);
|
||||
const PULL_REQUEST_LIST_PREFERENCES_STORAGE_KEY = "t3.pullRequests.preferences";
|
||||
type PreferenceStorage = Pick<Storage, "getItem" | "setItem">;
|
||||
|
||||
function resolvePreferenceStorage(
|
||||
storage: PreferenceStorage | undefined,
|
||||
): PreferenceStorage | undefined {
|
||||
return storage ?? (typeof window === "undefined" ? undefined : window.localStorage);
|
||||
}
|
||||
|
||||
/** Only list controls are remembered. The selected row remains a URL and right-panel concern. */
|
||||
export function pullRequestListPreferences(
|
||||
search: PullRequestListPreferences | Schema.Schema.Type<typeof PullRequestListPreferencesSchema>,
|
||||
): PullRequestListPreferences {
|
||||
return {
|
||||
involvement: search.involvement,
|
||||
state: search.state,
|
||||
...(search.environmentId ? { environmentId: search.environmentId } : {}),
|
||||
...(search.projectId ? { projectId: search.projectId } : {}),
|
||||
...(search.host ? { host: search.host } : {}),
|
||||
...(search.q ? { q: search.q } : {}),
|
||||
...(search.draft ? { draft: search.draft } : {}),
|
||||
...(search.review ? { review: search.review } : {}),
|
||||
...(search.checks ? { checks: search.checks } : {}),
|
||||
...(search.author ? { author: search.author } : {}),
|
||||
...(search.labels && search.labels.length > 0 ? { labels: search.labels } : {}),
|
||||
...(search.sort && search.sort !== "ready" ? { sort: search.sort } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export function readPullRequestListPreferences(
|
||||
storage?: PreferenceStorage,
|
||||
): PullRequestListPreferences {
|
||||
try {
|
||||
const raw = resolvePreferenceStorage(storage)?.getItem(
|
||||
PULL_REQUEST_LIST_PREFERENCES_STORAGE_KEY,
|
||||
);
|
||||
if (!raw) return DEFAULT_PULL_REQUEST_LIST_PREFERENCES;
|
||||
const decoded = decodePullRequestListPreferences(JSON.parse(raw));
|
||||
return decoded._tag === "Some"
|
||||
? pullRequestListPreferences(decoded.value)
|
||||
: DEFAULT_PULL_REQUEST_LIST_PREFERENCES;
|
||||
} catch {
|
||||
return DEFAULT_PULL_REQUEST_LIST_PREFERENCES;
|
||||
}
|
||||
}
|
||||
|
||||
export function writePullRequestListPreferences(
|
||||
preferences: PullRequestListPreferences,
|
||||
storage?: PreferenceStorage,
|
||||
): void {
|
||||
try {
|
||||
resolvePreferenceStorage(storage)?.setItem(
|
||||
PULL_REQUEST_LIST_PREFERENCES_STORAGE_KEY,
|
||||
JSON.stringify(preferences),
|
||||
);
|
||||
} catch {
|
||||
// Storage can be full or denied; the URL remains the source of truth for this visit.
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,11 @@ export function PullRequestStateGlyph({
|
||||
|
||||
const CHECK_STATUS_PRESENTATION = {
|
||||
pending: { label: "Running", Icon: LoaderIcon, toneClassName: "animate-spin text-amber-500" },
|
||||
"action-required": {
|
||||
label: "Awaiting action",
|
||||
Icon: CircleDotIcon,
|
||||
toneClassName: "text-amber-600 dark:text-amber-400/90",
|
||||
},
|
||||
success: {
|
||||
label: "Passed",
|
||||
Icon: CircleCheckIcon,
|
||||
@@ -134,8 +139,20 @@ const CHECK_STATUS_PRESENTATION = {
|
||||
{ label: string; Icon: typeof CircleCheckIcon; toneClassName: string }
|
||||
>;
|
||||
|
||||
export function pullRequestCheckStatusLabel(status: PullRequestCheckStatus): string {
|
||||
return CHECK_STATUS_PRESENTATION[status].label;
|
||||
function isWorkflowApprovalCheck(check: Pick<PullRequestCheck, "status" | "url">): boolean {
|
||||
return (
|
||||
check.status === "action-required" &&
|
||||
check.url !== null &&
|
||||
/\/actions\/runs\/\d+(?:\/|$)/u.test(check.url)
|
||||
);
|
||||
}
|
||||
|
||||
export function pullRequestCheckStatusLabel(
|
||||
check: Pick<PullRequestCheck, "status" | "url">,
|
||||
): string {
|
||||
return isWorkflowApprovalCheck(check)
|
||||
? "Awaiting approval"
|
||||
: CHECK_STATUS_PRESENTATION[check.status].label;
|
||||
}
|
||||
|
||||
export function PullRequestCheckStatusIcon({ status }: { status: PullRequestCheckStatus }) {
|
||||
@@ -187,10 +204,10 @@ export function pullRequestChecksState(
|
||||
checks: ReadonlyArray<PullRequestCheck>,
|
||||
): PullRequestChecksState | null {
|
||||
if (checks.length === 0) return null;
|
||||
const statuses = checks.map((check) => check.status);
|
||||
if (statuses.includes("failure") || statuses.includes("cancelled")) return "failing";
|
||||
if (statuses.includes("pending")) return "pending";
|
||||
return statuses.includes("success") ? "passing" : null;
|
||||
const statuses = new Set(checks.map((check) => check.status));
|
||||
if (statuses.has("failure") || statuses.has("cancelled")) return "failing";
|
||||
if (statuses.has("pending") || statuses.has("action-required")) return "pending";
|
||||
return statuses.has("success") ? "passing" : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,12 +452,24 @@ export function PullRequestMetaLine({
|
||||
|
||||
export function summarizePullRequestChecks(checks: ReadonlyArray<PullRequestCheck>): string {
|
||||
if (checks.length === 0) return "No checks reported";
|
||||
const actionRequired = checks.filter((check) => check.status === "action-required");
|
||||
const workflowApprovalRequired = actionRequired.filter(isWorkflowApprovalCheck).length;
|
||||
const otherActionRequired = actionRequired.length - workflowApprovalRequired;
|
||||
const failed = checks.filter(
|
||||
(check) => check.status === "failure" || check.status === "cancelled",
|
||||
).length;
|
||||
const pending = checks.filter((check) => check.status === "pending").length;
|
||||
const passed = checks.filter((check) => check.status === "success").length;
|
||||
if (failed > 0) return `${failed} of ${checks.length} failing`;
|
||||
if (workflowApprovalRequired > 0 && otherActionRequired > 0) {
|
||||
return `${workflowApprovalRequired} ${workflowApprovalRequired === 1 ? "workflow" : "workflows"} and ${otherActionRequired} ${otherActionRequired === 1 ? "check" : "checks"} awaiting action`;
|
||||
}
|
||||
if (workflowApprovalRequired > 0) {
|
||||
return `${workflowApprovalRequired} ${workflowApprovalRequired === 1 ? "workflow" : "workflows"} awaiting approval`;
|
||||
}
|
||||
if (otherActionRequired > 0) {
|
||||
return `${otherActionRequired} ${otherActionRequired === 1 ? "check" : "checks"} awaiting action`;
|
||||
}
|
||||
if (pending > 0) return `${pending} of ${checks.length} running`;
|
||||
return passed === checks.length ? "All checks passed" : `${passed} of ${checks.length} passing`;
|
||||
}
|
||||
Reference in new issue
Block a user