Skip to content
Merged
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,40 @@ import {
InfoIcon,
} from "@phosphor-icons/react";
import { Box, Button, Flex, Spinner, Text, Tooltip } from "@radix-ui/themes";
import { useMemo } from "react";

/**
* Past this count, the tooltip would become an unreadable wall of `owner/name`
* rows, so we collapse to owner-level summaries instead.
*/
const REPO_LIST_TOOLTIP_THRESHOLD = 10;

function summarizeReposByOwner(
repositories: readonly string[],
): { owner: string; count: number }[] {
const counts = new Map<string, number>();
for (const repo of repositories) {
const owner = repo.includes("/") ? (repo.split("/", 1)[0] ?? repo) : repo;
counts.set(owner, (counts.get(owner) ?? 0) + 1);
}
return [...counts.entries()]
.map(([owner, count]) => ({ owner, count }))
.sort((a, b) => b.count - a.count || a.owner.localeCompare(b.owner));
}
Comment on lines +22 to +33
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing tests for summarizeReposByOwner

The helper has non-trivial logic — grouping, deduplication, a two-key sort (count desc, then owner name asc), and a fallback for repo strings without a / — all of which are easy to break silently. The project preference is for parameterised tests; without them, edge cases like ties in count, repos whose name has no owner prefix, or repos with the same owner but different capitalisation go unverified.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/settings/components/sections/GitHubIntegrationSection.tsx
Line: 22-33

Comment:
**Missing tests for `summarizeReposByOwner`**

The helper has non-trivial logic — grouping, deduplication, a two-key sort (count desc, then owner name asc), and a fallback for repo strings without a `/` — all of which are easy to break silently. The project preference is for parameterised tests; without them, edge cases like ties in count, repos whose name has no owner prefix, or repos with the same owner but different capitalisation go unverified.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


export function GitHubIntegrationSection({
hasGithubIntegration,
}: {
hasGithubIntegration: boolean;
}) {
const { repositories, isLoadingRepos } = useRepositoryIntegration();
const ownerSummary = useMemo(
() =>
repositories.length > REPO_LIST_TOOLTIP_THRESHOLD
? summarizeReposByOwner(repositories)
: null,
[repositories],
);
const projectId = useAuthStateValue((state) => state.projectId);
const {
error: connectError,
Expand Down Expand Up @@ -51,13 +78,27 @@ export function GitHubIntegrationSection({
repositories.length > 0 ? (
<Tooltip
content={
<Flex direction="column" gap="1">
{repositories.map((repo) => (
<Text key={repo} className="text-[13px]">
{repo}
ownerSummary ? (
<Flex direction="column" gap="1">
<Text className="text-(--gray-10) text-[13px]">
{repositories.length} repos across {ownerSummary.length}{" "}
{ownerSummary.length === 1 ? "owner" : "owners"}
</Text>
))}
</Flex>
{ownerSummary.map(({ owner, count }) => (
<Text key={owner} className="text-[13px]">
{owner} ({count})
</Text>
))}
</Flex>
) : (
<Flex direction="column" gap="1">
{repositories.map((repo) => (
<Text key={repo} className="text-[13px]">
{repo}
</Text>
))}
</Flex>
)
}
side="bottom"
>
Expand Down
Loading