fix(github): restore pull request discovery health (#3609)

This commit is contained in:
Carlos Florêncio
2026-09-11 18:13:12 +01:00
committed by GitHub
parent d93b86a338
commit 8f7216fa1d
52 changed files with 4161 additions and 111 deletions
@@ -70,7 +70,11 @@ export function GitHubAccessHelp({
{description}
</DrawerDescription>
</DrawerHeader>
{content && <div className="px-4 pb-4">{content}</div>}
{content && (
<div className="max-h-[min(60dvh,32rem)] overflow-y-auto overscroll-contain px-4 pb-[calc(1rem+env(safe-area-inset-bottom))]">
{content}
</div>
)}
</DrawerContent>
</Drawer>
);
@@ -0,0 +1,63 @@
"use client";
import { IconAlertTriangle } from "@tabler/icons-react";
import { Alert, AlertDescription } from "@kandev/ui/alert";
import { formatTimeDistance, useDateLocale } from "@/lib/i18n/date-locale";
import type { GitHubPRDiscoveryHealth } from "@/lib/types/github";
import { useTranslation } from "react-i18next";
const CATEGORY_LABEL_KEYS: Record<NonNullable<GitHubPRDiscoveryHealth["category"]>, string> = {
invalid_query: "github:prDiscoveryCategoryInvalidQuery",
rate_limited: "github:prDiscoveryCategoryRateLimited",
unavailable: "github:prDiscoveryCategoryUnavailable",
};
function isDegraded(health?: GitHubPRDiscoveryHealth): health is GitHubPRDiscoveryHealth {
return Boolean(health && health.state === "degraded" && health.failed_target_count > 0);
}
function relativeTime(
value: string | undefined,
locale: ReturnType<typeof useDateLocale>,
fallback: string,
) {
return formatTimeDistance(value, locale) || fallback;
}
export function GitHubPRDiscoveryHealthWarning({ health }: { health?: GitHubPRDiscoveryHealth }) {
const { t } = useTranslation();
const locale = useDateLocale();
if (!isDegraded(health)) return null;
const category = health.category
? t(CATEGORY_LABEL_KEYS[health.category])
: t("github:prDiscoveryCategoryUnavailable");
const unknownTime = t("github:prDiscoveryUnknownTime");
return (
<Alert variant="destructive" className="min-w-0" data-testid="github-pr-discovery-health">
<IconAlertTriangle className="h-4 w-4 shrink-0" />
<AlertDescription className="min-w-0 text-xs">
<div className="space-y-1 break-words">
<p className="font-medium">{t("github:prDiscoveryFailed")}</p>
<p>{t("github:prDiscoveryCategory", { category })}</p>
<p>
{t("github:prDiscoveryLastFailure", {
time: relativeTime(health.last_failure_at, locale, unknownTime),
})}
</p>
<p>{t("github:prDiscoveryAffectedTargets", { count: health.failed_target_count })}</p>
{health.retry_at && (
<p>
{t("github:prDiscoveryRetryAt", {
time: relativeTime(health.retry_at, locale, unknownTime),
})}
</p>
)}
</div>
</AlertDescription>
</Alert>
);
}
export function GitHubPRDiscoveryHealthDetails({ health }: { health?: GitHubPRDiscoveryHealth }) {
return <GitHubPRDiscoveryHealthWarning health={health} />;
}
@@ -0,0 +1,38 @@
import { cleanup, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it } from "vitest";
import type { GitHubPRDiscoveryHealth } from "@/lib/types/github";
import { GitHubPRDiscoveryHealthWarning } from "./github-pr-discovery-health";
afterEach(cleanup);
const degradedHealth: GitHubPRDiscoveryHealth = {
state: "degraded",
failed_target_count: 2,
category: "invalid_query",
last_failure_at: "2026-09-11T12:00:00Z",
retry_at: "2026-09-11T12:01:00Z",
revision: 3,
credential_generation: 4,
};
describe("GitHub PR discovery health disclosure", () => {
it("shows operation, category, failure time, affected targets, and retry state", () => {
render(<GitHubPRDiscoveryHealthWarning health={degradedHealth} />);
expect(screen.getByTestId("github-pr-discovery-health")).toBeTruthy();
expect(screen.getByText("PR discovery failed")).toBeTruthy();
expect(screen.getByText(/Reason: Invalid query/)).toBeTruthy();
expect(screen.getByText(/Affected targets: 2/)).toBeTruthy();
expect(screen.getByText(/Retry after/)).toBeTruthy();
});
it("does not show a warning for healthy discovery", () => {
render(
<GitHubPRDiscoveryHealthWarning
health={{ ...degradedHealth, state: "healthy", failed_target_count: 0 }}
/>,
);
expect(screen.queryByTestId("github-pr-discovery-health")).toBeNull();
});
});
@@ -4,8 +4,13 @@ import { useEffect, useState } from "react";
import type { Locale } from "date-fns";
import { IconAlertTriangle, IconGauge } from "@tabler/icons-react";
import { Alert, AlertDescription } from "@kandev/ui/alert";
import type { GitHubRateLimitInfo, GitHubRateLimitSnapshot } from "@/lib/types/github";
import type {
GitHubPRDiscoveryHealth,
GitHubRateLimitInfo,
GitHubRateLimitSnapshot,
} from "@/lib/types/github";
import { GitHubAccessHelp } from "./github-access-help";
import { GitHubPRDiscoveryHealthDetails } from "./github-pr-discovery-health";
import { useTranslation } from "react-i18next";
// Locale-aware digit grouping; `toLocaleString("en-US")` pinned it to English.
import { formatNumber } from "@/lib/i18n/formats";
@@ -60,9 +65,11 @@ function snapshotsFromInfo(info: GitHubRateLimitInfo): GitHubRateLimitSnapshot[]
export function GitHubRateLimitDisplay({
info,
discoveryHealth,
onOpen,
}: {
info?: GitHubRateLimitInfo;
discoveryHealth?: GitHubPRDiscoveryHealth;
onOpen?: () => void;
}) {
const { t } = useTranslation();
@@ -77,8 +84,13 @@ export function GitHubRateLimitDisplay({
description={t("github:currentGithubApiRateAndQuery")}
icon={<IconGauge className="h-4 w-4" data-testid="github-rate-limit-icon" />}
content={
snapshots.length > 0 ? (
<RateLimitDetails snapshots={snapshots} exhausted={exhausted} />
snapshots.length > 0 || discoveryHealth?.state === "degraded" ? (
<div className="space-y-3">
<GitHubPRDiscoveryHealthDetails health={discoveryHealth} />
{snapshots.length > 0 && (
<RateLimitDetails snapshots={snapshots} exhausted={exhausted} />
)}
</div>
) : undefined
}
onOpen={onOpen}
+7 -1
View File
@@ -36,6 +36,7 @@ import { GitHubConnectionDialog } from "./github-connection-dialog";
import { GitHubAccessHelp } from "./github-access-help";
import { GitHubPermissionsDialog } from "./github-permissions-dialog";
import { GitHubRateLimitDisplay } from "./github-rate-limit";
import { GitHubPRDiscoveryHealthWarning } from "./github-pr-discovery-health";
import { GitHubTaskAccessSummary } from "./github-task-credentials-section";
import { useTranslation } from "react-i18next";
import type { TFunction } from "i18next";
@@ -106,7 +107,11 @@ function StatusLine({
{t(sourceLabelKeys[connection.source])}
</Badge>
{connection.status !== "active" && <Badge variant="outline">{connection.status}</Badge>}
<GitHubRateLimitDisplay info={status.rate_limit} onOpen={onRateLimitOpen} />
<GitHubRateLimitDisplay
info={status.rate_limit}
discoveryHealth={status.pr_discovery_health}
onOpen={onRateLimitOpen}
/>
</div>
);
}
@@ -138,6 +143,7 @@ function AutomationStatusSummary({
return (
<div className="min-w-0 space-y-1">
<StatusLine status={status} onRateLimitOpen={onRateLimitOpen} />
<GitHubPRDiscoveryHealthWarning health={status.pr_discovery_health} />
<AutomationActorExplanation status={status} appAutomation={appAutomation} />
{appAutomation && <AppRegistrationDetails app={app} />}
<AutomationError status={status} />