Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 76 additions & 12 deletions apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
import { LegendList, type LegendListRef } from "@legendapp/list/react-native";
import { useNavigation } from "@react-navigation/native";
import { use, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { EnvironmentId } from "@t3tools/contracts";
import { useAtomValue } from "@effect/atom-react";
import {
Keyboard,
Expand All @@ -32,11 +33,14 @@ import { usePullRequestListControls } from "./usePullRequestListControls";
import { usePullRequestListActions } from "./usePullRequestListActions";
import {
filterPullRequestList,
groupPullRequestListErrors,
pullRequestListFacets,
pullRequestListInput,
pullRequestListRowsAreEqual,
scopedPullRequestListKey as pullRequestKey,
type EnvironmentPullRequestListEntry,
type EnvironmentPullRequestListError,
type EnvironmentPullRequestProviderSummary,
withoutScratchProjectScope,
} from "./pullRequestList";
import { useDebouncedValue } from "../../state/queries";
Expand All @@ -57,6 +61,63 @@ function PullRequestScrollView(props: ScrollViewProps) {
);
}

function PullRequestListErrors(props: {
readonly errors: readonly EnvironmentPullRequestListError[];
readonly providers: readonly EnvironmentPullRequestProviderSummary[];
readonly connectedEnvironmentIds: ReadonlySet<EnvironmentId>;
readonly environmentLabel: (environmentId: EnvironmentId) => string;
}) {
const [expanded, setExpanded] = useState(false);
const { environments, providers, repositories } = groupPullRequestListErrors(
props.errors,
props.providers,
props.connectedEnvironmentIds,
);
const lines = environments.map(
(error) => `${props.environmentLabel(error.environmentId)}: ${error.message}`,
);
lines.push(
...providers.map(
(provider) =>
`${props.environmentLabel(provider.environmentId)}: ${provider.host}: ${provider.detail}`,
),
);
if (repositories.length === 1)
lines.push(`${repositories[0]!.projectTitle}: ${repositories[0]!.message}`);
if (!lines.length && !repositories.length) return null;
return (
<View className="px-4 py-3">
{lines.length ? (
<Text className="text-sm text-foreground-muted">{lines.join("\n")}</Text>
) : null}
{repositories.length > 1 ? (
<Pressable
accessibilityRole="button"
accessibilityState={{ expanded }}
accessibilityLabel={
expanded
? "Hide repositories that could not be read"
: `Show ${repositories.length} repositories that could not be read`
}
hitSlop={8}
onPress={() => setExpanded((value) => !value)}
className="min-h-11 flex-row items-center gap-2"
>
<Text className="shrink text-sm text-foreground-muted">
{repositories.length} repositories could not be read.
</Text>
<Text className="text-sm font-t3-medium text-link">{expanded ? "Hide" : "Show"}</Text>
</Pressable>
) : null}
{expanded && repositories.length > 1 ? (
<Text className="pt-1 text-sm text-foreground-muted">
{repositories.map((error) => `${error.projectTitle}: ${error.message}`).join("\n")}
</Text>
) : null}
</View>
);
}

export function PullRequestsScreen(
props: {
readonly sidebar?: boolean;
Expand Down Expand Up @@ -145,6 +206,10 @@ export function PullRequestsScreen(
const sidebar = props.sidebar === true || primaryColumn !== null;
const selectedKey = props.selectedPullRequestKey ?? primaryColumn?.selectedPullRequestKey;
const connectedKey = connectedTargets.map((target) => target.environmentId).join("\n");
const connectedEnvironmentIds = useMemo(
() => new Set(connectedKey ? connectedKey.split("\n").map((id) => EnvironmentId.make(id)) : []),
[connectedKey],
);
const entries = useMemo(
() =>
filterPullRequestList(
Expand All @@ -153,9 +218,9 @@ export function PullRequestsScreen(
result.data?.viewers ?? {},
query,
result.data.localSearchHosts,
new Set(connectedKey.split("\n")),
connectedEnvironmentIds,
),
[result.entries, controls, query, result.data, connectedKey],
[result.entries, controls, query, result.data, connectedEnvironmentIds],
);
const facets = useMemo(() => pullRequestListFacets(result.entries), [result.entries]);
const [knownFacets, setKnownFacets] = useState({ environmentId, source: facets, ...facets });
Expand Down Expand Up @@ -306,16 +371,15 @@ export function PullRequestsScreen(
}
projects={projects}
/>
{result.data?.errors.length ? (
<Text className="px-4 py-3 text-sm text-foreground-muted">
{result.data.errors
.map(
(error) =>
`${error.projectTitle || environments.find((environment) => environment.environmentId === error.environmentId)?.environmentLabel || "Environment"}: ${error.message}`,
)
.join("\n")}
</Text>
) : null}
<PullRequestListErrors
errors={result.data.errors}
providers={result.data.providers}
connectedEnvironmentIds={connectedEnvironmentIds}
environmentLabel={(id) =>
environments.find((environment) => environment.environmentId === id)
?.environmentLabel ?? "Environment"
}
/>
</>
}
ListFooterComponent={
Expand Down
176 changes: 176 additions & 0 deletions apps/mobile/src/features/pull-requests/pullRequestList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import {
EnvironmentId,
SourceControlProviderKind,
type PullRequestListEntry,
type PullRequestProviderSummary,
type PullRequestListResult,
} from "@t3tools/contracts";
import {
appendPullRequestListPage,
DEFAULT_PR_LIST_CONTROLS,
filterPullRequestList,
groupPullRequestListErrors,
mergePullRequestListEntries,
mergeEnvironmentPullRequestPages,
nextPullRequestListInput,
PR_LIST_PAGE_SIZE,
pullRequestListFacets,
pullRequestListErrorMessage,
pullRequestListHead,
pullRequestListInput,
pullRequestListReviewStatus,
Expand Down Expand Up @@ -63,6 +66,19 @@ function page(
};
}

function provider(patch: Partial<PullRequestProviderSummary> = {}): PullRequestProviderSummary {
return {
host: "github.com",
kind: SourceControlProviderKind.make("github"),
searchesOnHost: true,
actions: [],
projectCount: 1,
configured: true,
detail: null,
...patch,
};
}

describe("recycled PR list rows", () => {
const scopedEntry = (patch: Partial<PullRequestListEntry> = {}) => ({
...entry(1, patch),
Expand Down Expand Up @@ -166,6 +182,85 @@ describe("mobile PR list pagination", () => {
expect(nextPullRequestListInput({ ...first, limit: 490 }, { state: "all" })?.limit).toBe(500);
expect(nextPullRequestListInput({ ...first, limit: 500 }, { state: "all" })).toBeNull();
});
it("advances readable repositories while retaining failed repository cursors", () => {
const first = pullRequestListHead(
null,
page([entry(3)], { readable: "readable-first", failed: "failed-first" }),
);
const partial = appendPullRequestListPage(
first,
{
...page([entry(2)], { readable: "readable-second" }),
errors: [
{
projectId: entry(1).projectId,
projectTitle: "Failed",
message: "Failed could not be read.",
cursorKey: "failed",
},
],
},
{ state: "open", cursors: first.nextCursors },
);
expect(partial.entries.map((row) => row.number)).toEqual([3, 2]);
const retryInput = nextPullRequestListInput(partial, { state: "open" })!;
expect(retryInput.cursors).toEqual({
readable: "readable-second",
failed: "failed-first",
});
const retried = appendPullRequestListPage(partial, page([entry(1)]), retryInput);
expect(retried.entries.map((row) => row.number)).toEqual([3, 2, 1]);
expect(nextPullRequestListInput(retried, { state: "open" })).toBeNull();
});
it("keeps the whole continuation when an older server omits failed cursor keys", () => {
const first = pullRequestListHead(null, page([entry(2)], { repo: "first" }));
const partial = appendPullRequestListPage(
first,
{
...page([entry(1)], { repo: "second" }),
errors: [
{
projectId: entry(1).projectId,
projectTitle: "Project",
message: "Project could not be read.",
},
],
},
{ state: "open", cursors: first.nextCursors },
);
expect(partial.entries.map((row) => row.number)).toEqual([2, 1]);
const retryInput = nextPullRequestListInput(partial, { state: "open" })!;
expect(retryInput.cursors).toEqual({ repo: "first" });
const retried = appendPullRequestListPage(partial, page([entry(1)]), retryInput);
expect(retried.entries.map((row) => row.number)).toEqual([2, 1]);
expect(nextPullRequestListInput(retried, { state: "open" })).toBeNull();
});
it("keeps a limit-based continuation retryable after a keyed repository failure", () => {
const first = pullRequestListHead(null, { ...page([entry(3)]), truncated: true });
const input = nextPullRequestListInput(first, { state: "open" })!;
const partial = appendPullRequestListPage(
first,
{
...page([entry(2)]),
errors: [
{
projectId: entry(1).projectId,
projectTitle: "Failed",
message: "HTTP 404",
host: "github.com",
cursorKey: "github.com org/failed",
},
],
},
input,
);

expect(partial.entries.map((row) => row.number)).toEqual([3, 2]);
expect(nextPullRequestListInput(partial, { state: "open" })).toEqual(input);
const retried = appendPullRequestListPage(partial, page([entry(1)]), input);
expect(retried.entries.map((row) => row.number)).toEqual([3, 2, 1]);
expect(nextPullRequestListInput(retried, { state: "open" })).toBeNull();
});
});

describe("all-environment PR list", () => {
Expand Down Expand Up @@ -407,6 +502,87 @@ describe("mobile PR scan and filters", () => {
});
});

describe("pull request list errors", () => {
const environmentId = EnvironmentId.make("environment-1");
const repository = (index: number) => ({
environmentId,
projectId: `project-${index}`,
projectTitle: `repo-${index}`,
message: `org/repo-${index} could not be read.`,
host: "github.com",
});

it("summarizes repeated repository failures while retaining details and a single actionable error", () => {
const errors = [repository(1), repository(2), repository(1)];
expect(pullRequestListErrorMessage(errors)).toBe("2 repositories could not be read.");
expect(groupPullRequestListErrors(errors).repositories).toEqual([repository(1), repository(2)]);
expect(pullRequestListErrorMessage([repository(1)])).toBe(
"repo-1: org/repo-1 could not be read.",
);
});

it("keeps host failures actionable without hiding another environment or legacy repository errors", () => {
const otherId = EnvironmentId.make("environment-2");
const offline = {
environmentId: EnvironmentId.make("offline"),
projectTitle: "",
message: "Disconnected.",
};
const failedProvider = provider({
configured: false,
detail: "Run gh auth login --hostname github.com.",
});
const unrelatedProvider = provider({
host: "git.example.test",
detail: "This host cannot be browsed here yet.",
});
const merged = mergeEnvironmentPullRequestPages([
{
environmentId,
pages: pullRequestListHead(null, {
...page([]),
providers: [failedProvider, unrelatedProvider],
}),
},
]);
expect(groupPullRequestListErrors([], merged.providers).providers).toEqual([]);
expect(pullRequestListErrorMessage([], merged.providers)).toBe("");
const otherRepository = { ...repository(1), environmentId: otherId };
const legacy = { ...repository(3), host: undefined };
const errors = [repository(1), repository(2), otherRepository, legacy, offline];
const grouped = groupPullRequestListErrors(errors, merged.providers);

expect(grouped.environments).toEqual([offline]);
expect(grouped.providers).toEqual([{ ...failedProvider, environmentId }]);
expect(grouped.repositories).toEqual([otherRepository, legacy]);
expect(pullRequestListErrorMessage(errors, merged.providers)).toBe(
"github.com: Run gh auth login --hostname github.com.\n2 repositories could not be read.",
);
});

it("keeps environment failures visible while suppressing stale host and repository details", () => {
const connectedId = EnvironmentId.make("environment-2");
const failedProvider = {
...provider({ detail: "GitHub could not be reached." }),
environmentId,
};
const connectedRepository = { ...repository(2), environmentId: connectedId };
const errors = [repository(1), connectedRepository];
expect(groupPullRequestListErrors(errors, [failedProvider], new Set([connectedId]))).toEqual({
environments: [],
providers: [],
repositories: [connectedRepository],
});

const offline = { environmentId, projectTitle: "", message: "Disconnected." };
expect(groupPullRequestListErrors([...errors, offline], [failedProvider])).toEqual({
environments: [offline],
providers: [],
repositories: [connectedRepository],
});
});
});

describe("withoutScratchProjectScope", () => {
const projects = [
{ id: "repo", environmentId: "env-a" },
Expand Down
Loading
Loading