Skip to content
Draft
Show file tree
Hide file tree
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
79 changes: 73 additions & 6 deletions apps/mobile/src/features/pull-requests/PullRequestTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { PullRequestEntryRow } from "./PullRequestEntryRow";
import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
import IconGitCommit from "@tabler/icons-react-native/IconGitCommit";
import {
aiReviewerDisplayBody,
aiReviewerOneLine,
parseAiReviewerFeedback,
} from "@t3tools/client-runtime/ai-reviewer-feedback";
import {
pullRequestConversationThreads,
type PullRequestActivity,
Expand All @@ -14,13 +19,15 @@ import {
import { StackActions, type NavigationProp } from "@react-navigation/native";
import { useMemo, useState, type ComponentProps, type ReactNode } from "react";
import { Pressable, StyleSheet, View } from "react-native";
import Animated from "react-native-reanimated";
import { parseMarkdownDocument } from "../../lib/markdownDocument";
import { AppText as Text } from "../../components/ui/AppText";
import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol";
import { byTimestamp, relativeTime } from "../../lib/time";
import { PullRequestAvatar } from "./PullRequestPresentation";
import { PullRequestMarkdown } from "./PullRequestMarkdown";
import { PullRequestCommentFooter } from "./PullRequestReactions";
import { PR_DISCLOSURE_ENTER, PR_ROW_LAYOUT } from "./pullRequestAnimations";
import { pullRequestDescriptionContent } from "./pullRequestDescriptionContent";
import { discussionCommentCountLabel } from "./pullRequestDiffComments";
import { normalizedReviewState } from "./pullRequestStatus";
Expand Down Expand Up @@ -86,11 +93,20 @@ function TimelineComment({
const linked =
target?.kind === "timeline" && pullRequestAnchorMatchesUrl(target.anchor, comment.url);
const [expanded, setExpanded] = useState(linked);
const [showOriginal, setShowOriginal] = useState(false);
const { themeVariables: colors } = useAppearancePreferences();
const long = comment.body.length > 450 || comment.body.split("\n").length > 8;
const feedback = useMemo(() => parseAiReviewerFeedback(comment.body), [comment.body]);
const compactBody = useMemo(
() => (feedback === null ? null : aiReviewerDisplayBody(feedback)),
[feedback],
);
const displayBody = showOriginal || compactBody === null ? comment.body : compactBody;
const oneLine = feedback === null ? null : aiReviewerOneLine(feedback);
const long =
oneLine !== null ? true : displayBody.length > 450 || displayBody.split("\n").length > 8;
const content = useMemo(
() => pullRequestDescriptionContent(parseMarkdownDocument(comment.body)),
[comment.body],
() => pullRequestDescriptionContent(parseMarkdownDocument(displayBody)),
[displayBody],
);
const preview = content.preview;
const state = normalizedReviewState(comment.reviewState);
Expand Down Expand Up @@ -118,7 +134,58 @@ function TimelineComment({
{comment.path}
</Text>
) : null}
{preview.trim() || content.attachments.length ? (
{oneLine !== null ? (
<Animated.View layout={PR_ROW_LAYOUT} className="w-full min-w-0">
<View
className={
linked
? "w-full min-w-0 gap-2 overflow-hidden rounded-2xl border border-primary bg-primary/10 p-3"
: "w-full min-w-0 gap-2 overflow-hidden rounded-2xl bg-grouped-card p-3"
}
>
<Pressable
onPress={() => setExpanded((current) => !current)}
accessibilityRole="button"
accessibilityState={{ expanded }}
className="w-full min-w-0 flex-row items-center gap-1 active:opacity-70"
>
<View className="shrink-0">
<SymbolView
name={expanded ? "chevron.down" : "chevron.right"}
size={11}
tintColorClassName="accent-icon-muted"
/>
</View>
<Text
className="min-w-0 flex-1 shrink text-sm text-foreground-muted"
numberOfLines={1}
ellipsizeMode="tail"
>
{oneLine}
</Text>
</Pressable>
{expanded ? (
<Animated.View
entering={PR_DISCLOSURE_ENTER}
className="w-full min-w-0 gap-2 overflow-hidden"
>
<PullRequestMarkdown markdown={displayBody} imageGroupMarkdown={displayBody} />
<Pressable
accessibilityRole="button"
accessibilityState={{ selected: showOriginal }}
onPress={() => setShowOriginal((current) => !current)}
hitSlop={8}
className="self-start py-1 active:opacity-70"
>
<Text className="text-xs font-t3-medium text-foreground-muted">
{showOriginal ? "Show summary" : "Show original"}
</Text>
</Pressable>
</Animated.View>
) : null}
</View>
</Animated.View>
) : preview.trim() || content.attachments.length ? (
<View
className={
linked
Expand All @@ -128,8 +195,8 @@ function TimelineComment({
>
<View style={long && !expanded ? { maxHeight: 240, overflow: "hidden" } : undefined}>
<PullRequestMarkdown
markdown={long && !expanded ? comment.body.slice(0, 1200) : comment.body}
imageGroupMarkdown={comment.body}
markdown={long && !expanded ? displayBody.slice(0, 1200) : displayBody}
imageGroupMarkdown={displayBody}
/>
</View>
{long && !expanded ? (
Expand Down
47 changes: 1 addition & 46 deletions apps/mobile/src/features/pull-requests/botBadgeImages.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1 @@
/** Only asset paths are bot badges; keep same-host screenshots and all inline markdown images. */
const BOT_BADGE_PREFIXES = [
"static.devin.ai/assets/",
"cursor.com/assets/images/",
"storage.googleapis.com/coderabbit_public_assets/",
"greptile-static-assets.s3.amazonaws.com/badges/",
"static.graphite.dev/",
"qodo.ai/wp-content/uploads/",
"cubic.dev/buttons/",
"github.githubassets.com/static/images/icons/copilot-code-review/",
"gstatic.com/codereviewagent/",
"vercel.com/vercel-agent-view-suggestion-",
"agents-vade-review.vercel.sh/",
"new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/",
"pr-comments-assets.blacksmith.sh/",
"app.roocode.com/cloud-agents/github/",
"app.parameter.ai/_static/icons/",
"img.shields.io/",
"raster.shields.io/",
"dependabot-badges.githubapp.com/",
"developer.mend.io/api/mc/badges/",
"api.securityscorecards.dev/projects/",
"github-app-statics.socket.dev/",
"static.deepsource.com/comment_artifacts/",
"sonarsource.github.io/sonarcloud-github-static-resources/",
"codescene.io/imgs/svg/",
"app.codecov.io/gh/",
"github.com/codecov/engineering-team/assets/",
"codspeed.io/pr-report/",
"static.trunk.io/assets/",
"res.cloudinary.com/snyk/",
"api.segment.io/v1/pixel/",
"cla-assistant.io/pull/badge/",
"vercel.com/static/status/",
"vercel.com/api/www/avatar",
"app.netlify.com/qr-code/",
"workers.cloudflare.com/logo.svg",
// Cloudflare Pages reuses one old GitHub upload as its logo.
"user-images.githubusercontent.com/23264/106598434-9e719e00-654f-11eb-9e59-6167043cfa01.png",
"qr.expo.dev/",
];

export function isBotBadgeImage(href: string) {
const path = href.replace(/^https?:\/\/(?:www\.)?/i, "").toLowerCase();
return BOT_BADGE_PREFIXES.some((prefix) => path.startsWith(prefix));
}
export { isBotBadgeImage } from "@t3tools/client-runtime/bot-badge-images";
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {
parseAiReviewerFeedback,
type AiReviewerFeedback,
} from "@t3tools/client-runtime/ai-reviewer-feedback";
import type { PullRequestComment } from "@t3tools/contracts";

export function pullRequestAiReviewerFeedback(
comment: Pick<PullRequestComment, "body">,
): AiReviewerFeedback | null {
return parseAiReviewerFeedback(comment.body);
}
7 changes: 4 additions & 3 deletions apps/web/src/components/pullRequest/PullRequestCodeTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { useRenderedAppearance } from "~/hooks/useTheme";
import { areAllDiffFilesCollapsed } from "~/lib/diffCollapse";
import {
pullRequestFindingKey,
pullRequestFixFindingLabel,
type PullRequestChatSubject,
type PullRequestFinding,
} from "./pullRequestDetail.logic";
Expand Down Expand Up @@ -357,7 +358,7 @@ function PullRequestCodeTab({
selectedCommitOid,
onSelectedCommitChange,
pendingFinding,
fixFindingLabel = "Fix in a thread",
fixInThisThread = false,
onFixFinding,
onAddToChat,
onAddToAgentSelection,
Expand All @@ -375,7 +376,7 @@ function PullRequestCodeTab({
selectedCommitOid: string | null;
onSelectedCommitChange: (oid: string | null) => void;
pendingFinding?: string | null;
fixFindingLabel?: string;
fixInThisThread?: boolean;
onFixFinding?: (finding: PullRequestFinding) => void;
/** Absent where there is no composer beside the panel to add a conversation to. */
onAddToChat?: (subject: PullRequestChatSubject) => void;
Expand Down Expand Up @@ -1058,7 +1059,7 @@ function PullRequestCodeTab({
completionScope={completionScope}
pending={threadPending}
fixPending={pendingFinding === pullRequestFindingKey({ kind: "thread", thread })}
fixLabel={fixFindingLabel}
fixLabel={pullRequestFixFindingLabel({ kind: "thread", thread }, fixInThisThread)}
{...(onFixFinding ? { onFix: () => onFixFinding({ kind: "thread", thread }) } : {})}
{...(onAddToChat
? { onAddToChat: (loaded) => onAddToChat({ kind: "thread", thread: loaded }) }
Expand Down
113 changes: 96 additions & 17 deletions apps/web/src/components/pullRequest/PullRequestCommentBody.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,80 @@
import {
aiReviewerDisplayBody,
aiReviewerOneLine,
parseAiReviewerFeedback,
} from "@t3tools/client-runtime/ai-reviewer-feedback";
import { ChevronRightIcon } from "lucide-react";
import { useId, useRef, useState, type ComponentProps } from "react";

import { cn } from "~/lib/utils";
import { observeResize } from "~/lib/observeResize";
import { Button } from "../ui/button";
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
import { PullRequestMarkdown } from "./PullRequestMarkdown";
import { observeResize } from "~/lib/observeResize";
import { visibleBody } from "./pullRequestDetail.logic";

export function PullRequestCommentBody({
className,
text,
/** When false, AI findings render their compact body immediately (e.g. inside an already-expanded thread). */
aiCollapsed = true,
...props
}: ComponentProps<typeof PullRequestMarkdown>) {
}: ComponentProps<typeof PullRequestMarkdown> & { aiCollapsed?: boolean }) {
const [expanded, setExpanded] = useState(false);
const [aiOpen, setAiOpen] = useState(false);
const [showOriginal, setShowOriginal] = useState(false);
const [overflowing, setOverflowing] = useState(false);
const clip = useRef<HTMLDivElement>(null);
const id = useId();
const feedback = parseAiReviewerFeedback(text);
const optimized =
feedback !== null
? {
compact: aiReviewerDisplayBody(feedback),
oneLine: aiReviewerOneLine(feedback),
}
: null;
// visibleBody trims; keep leading spaces on ordinary comments so indented fences stay code.
const original = feedback === null ? text : (visibleBody(text) ?? text);
const rendered = showOriginal || optimized === null ? original : optimized.compact;

if (aiCollapsed && optimized !== null && !showOriginal) {
return (
<div className={cn("min-w-0", className)}>
<Collapsible open={aiOpen} onOpenChange={setAiOpen}>
<CollapsibleTrigger className="flex w-full min-w-0 items-center gap-1 rounded-md py-0.5 text-left text-sm hover:bg-muted/50">
<ChevronRightIcon
aria-hidden
className={cn(
"-me-0.5 size-3.5 shrink-0 text-muted-foreground transition-transform duration-200 motion-reduce:transition-none",
aiOpen && "rotate-90",
)}
/>
<span className="min-w-0 flex-1 truncate text-muted-foreground">
{optimized.oneLine}
</span>
</CollapsibleTrigger>
{/* Keep children mounted so CollapsiblePanel can animate height open and closed. */}
<CollapsiblePanel>
<div className="space-y-2 pt-2">
<PullRequestMarkdown {...props} text={optimized.compact} />
<Button
size="xs"
variant="ghost-muted"
aria-pressed={false}
onClick={() => {
setShowOriginal(true);
setExpanded(true);
}}
>
Show original
</Button>
</div>
</CollapsiblePanel>
</Collapsible>
</div>
);
}

return (
<div className={cn("min-w-0", className)}>
Expand All @@ -30,7 +92,7 @@ export function PullRequestCommentBody({
});
}}
>
<PullRequestMarkdown {...props} />
<PullRequestMarkdown {...props} text={rendered} />
</div>
{overflowing && !expanded ? (
<div
Expand All @@ -39,20 +101,37 @@ export function PullRequestCommentBody({
/>
) : null}
</div>
{overflowing ? (
<Button
size="xs"
variant="ghost-muted"
className="mt-2"
aria-expanded={expanded}
aria-controls={id}
onClick={() => {
if (expanded) clip.current?.scrollIntoView({ block: "nearest" });
setExpanded(!expanded);
}}
>
{expanded ? "Show less" : "Show full comment"}
</Button>
{overflowing || optimized !== null ? (
<div className="mt-2 flex flex-wrap gap-1">
{overflowing ? (
<Button
size="xs"
variant="ghost-muted"
aria-expanded={expanded}
aria-controls={id}
onClick={() => {
if (expanded) clip.current?.scrollIntoView({ block: "nearest" });
setExpanded(!expanded);
}}
>
{expanded ? "Show less" : "Show full comment"}
</Button>
) : null}
{optimized !== null ? (
<Button
size="xs"
variant="ghost-muted"
aria-pressed={showOriginal}
onClick={() => {
setShowOriginal((current) => !current);
setExpanded(true);
if (showOriginal) setAiOpen(true);
}}
>
{showOriginal ? "Show summary" : "Show original"}
</Button>
) : null}
</div>
) : null}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ export function PullRequestDetailPanel({
checksStale={checksStale}
activityError={activityError}
pendingFinding={handoff}
fixFindingLabel={handoffLabels.fixFinding}
fixInThisThread={attachTarget !== null}
fixCheckLabel={handoffLabels.fixCheck}
{...(canFixFindings ? { onFixFinding: startFixFinding } : {})}
{...(attachTarget === null ? {} : { onAddToChat: addCommentToChat })}
Expand Down Expand Up @@ -1970,7 +1970,7 @@ export function PullRequestDetailPanel({
selectedCommitOid={selectedCodeCommitOid}
onSelectedCommitChange={selectCodeCommit}
pendingFinding={handoff}
fixFindingLabel={handoffLabels.fixFinding}
fixInThisThread={attachTarget !== null}
{...(canFixFindings ? { onFixFinding: startFixFinding } : {})}
{...(attachTarget === null ? {} : { onAddToChat: addCommentToChat })}
onRefresh={refreshDetail}
Expand Down
Loading
Loading