feat(sidebar): improve PR checks and comments (#1134)
* feat(sidebar): improve PR checks and comments Co-authored-by: Orca <help@stably.ai> * fix(sidebar): classify bot comments via GitHub user.type instead of login heuristic Third-party review bots like qodo-ai-reviewer, coderabbitai, and sonarcloud don't follow the [bot] suffix or "bot"/"automation" substring convention, so the regex-based detector misclassified them as human. Plumb REST `user.type === 'Bot'` and GraphQL `author.__typename === 'Bot'` through to the renderer as an authoritative isBot flag; fall back to the login heuristic only when the data source can't report it. Co-authored-by: Orca <help@stably.ai> * fix(sidebar): allowlist AI review services that sign in as User accounts qodo-ai-reviewer, coderabbitai, codium-ai and similar third-party review services register as regular GitHub user accounts, so REST `user.type` is "User" and their logins contain no "bot"/"automation" tokens. The previous fix relied on the GitHub-reported type, which fails for these. Add an explicit substring allowlist of known automation services so they still land in the Bots tab. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai> Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
This commit is contained in:
co-authored by
Orca
Jinjing
parent
7720ed136c
commit
fe6eecba0c
@@ -860,7 +860,7 @@ query($owner: String!, $repo: String!, $pr: Int!) {
|
||||
comments(first: 100) {
|
||||
nodes {
|
||||
databaseId
|
||||
author { login avatarUrl(size: 48) }
|
||||
author { __typename login avatarUrl(size: 48) }
|
||||
body
|
||||
createdAt
|
||||
url
|
||||
@@ -932,7 +932,7 @@ export async function getPRComments(
|
||||
// Parse issue comments (REST)
|
||||
type RESTComment = {
|
||||
id: number
|
||||
user: { login: string; avatar_url: string } | null
|
||||
user: { login: string; avatar_url: string; type?: string } | null
|
||||
body: string
|
||||
created_at: string
|
||||
html_url: string
|
||||
@@ -946,7 +946,8 @@ export async function getPRComments(
|
||||
authorAvatarUrl: c.user?.avatar_url ?? '',
|
||||
body: c.body ?? '',
|
||||
createdAt: c.created_at,
|
||||
url: c.html_url
|
||||
url: c.html_url,
|
||||
isBot: c.user?.type === 'Bot'
|
||||
})
|
||||
)
|
||||
} else {
|
||||
@@ -964,7 +965,7 @@ export async function getPRComments(
|
||||
comments: {
|
||||
nodes: {
|
||||
databaseId: number
|
||||
author: { login: string; avatarUrl: string } | null
|
||||
author: { __typename?: string; login: string; avatarUrl: string } | null
|
||||
body: string
|
||||
createdAt: string
|
||||
url: string
|
||||
@@ -990,6 +991,7 @@ export async function getPRComments(
|
||||
path: c.path,
|
||||
threadId: thread.id,
|
||||
isResolved: thread.isResolved,
|
||||
isBot: c.author?.__typename === 'Bot',
|
||||
// Why: GitHub nulls out line/startLine when the commented code is
|
||||
// outdated (e.g. after a force-push). Fall back to originalLine which
|
||||
// always preserves the line numbers from when the comment was created.
|
||||
@@ -1006,7 +1008,7 @@ export async function getPRComments(
|
||||
// since empty-body reviews (e.g. approvals with no comment) add noise.
|
||||
type RESTReview = {
|
||||
id: number
|
||||
user: { login: string; avatar_url: string } | null
|
||||
user: { login: string; avatar_url: string; type?: string } | null
|
||||
body: string
|
||||
state: string
|
||||
submitted_at: string
|
||||
@@ -1023,7 +1025,8 @@ export async function getPRComments(
|
||||
authorAvatarUrl: r.user?.avatar_url ?? '',
|
||||
body: r.body,
|
||||
createdAt: r.submitted_at,
|
||||
url: r.html_url
|
||||
url: r.html_url,
|
||||
isBot: r.user?.type === 'Bot'
|
||||
})
|
||||
)
|
||||
} else {
|
||||
|
||||
@@ -158,7 +158,7 @@ async function getIssueBodyAndComments(
|
||||
}
|
||||
type RESTComment = {
|
||||
id: number
|
||||
user: { login: string; avatar_url: string } | null
|
||||
user: { login: string; avatar_url: string; type?: string } | null
|
||||
body: string
|
||||
created_at: string
|
||||
html_url: string
|
||||
@@ -170,7 +170,8 @@ async function getIssueBodyAndComments(
|
||||
authorAvatarUrl: c.user?.avatar_url ?? '',
|
||||
body: c.body ?? '',
|
||||
createdAt: c.created_at,
|
||||
url: c.html_url
|
||||
url: c.html_url,
|
||||
isBot: c.user?.type === 'Bot'
|
||||
})
|
||||
)
|
||||
const assignees = (issue.assignees ?? []).map((a) => a.login)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { clampCheckDetailsHeight } from './check-details-resize'
|
||||
|
||||
describe('clampCheckDetailsHeight', () => {
|
||||
it('keeps the checks list resize height within readable bounds', () => {
|
||||
expect(clampCheckDetailsHeight(20)).toBe(72)
|
||||
expect(clampCheckDetailsHeight(260)).toBe(260)
|
||||
expect(clampCheckDetailsHeight(900)).toBe(520)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,51 @@
|
||||
import { useCallback, useEffect, useRef, useState, type MouseEvent as ReactMouseEvent } from 'react'
|
||||
|
||||
const DEFAULT_CHECK_DETAILS_HEIGHT = 260
|
||||
const MIN_CHECK_DETAILS_HEIGHT = 72
|
||||
const MAX_CHECK_DETAILS_HEIGHT = 520
|
||||
|
||||
export function clampCheckDetailsHeight(height: number): number {
|
||||
return Math.min(MAX_CHECK_DETAILS_HEIGHT, Math.max(MIN_CHECK_DETAILS_HEIGHT, height))
|
||||
}
|
||||
|
||||
export function useCheckDetailsResize(enabled: boolean): {
|
||||
detailsHeight: number
|
||||
handleResizeStart: (event: ReactMouseEvent<HTMLDivElement>) => void
|
||||
} {
|
||||
const [detailsHeight, setDetailsHeight] = useState(DEFAULT_CHECK_DETAILS_HEIGHT)
|
||||
const dragStartRef = useRef<{ y: number; height: number } | null>(null)
|
||||
|
||||
const handleResizeStart = useCallback(
|
||||
(event: ReactMouseEvent<HTMLDivElement>) => {
|
||||
if (!enabled) {
|
||||
return
|
||||
}
|
||||
event.preventDefault()
|
||||
dragStartRef.current = { y: event.clientY, height: detailsHeight }
|
||||
},
|
||||
[detailsHeight, enabled]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
const handleMouseMove = (event: MouseEvent): void => {
|
||||
const dragStart = dragStartRef.current
|
||||
if (!dragStart) {
|
||||
return
|
||||
}
|
||||
setDetailsHeight(clampCheckDetailsHeight(dragStart.height + event.clientY - dragStart.y))
|
||||
}
|
||||
|
||||
const handleMouseUp = (): void => {
|
||||
dragStartRef.current = null
|
||||
}
|
||||
|
||||
document.addEventListener('mousemove', handleMouseMove)
|
||||
document.addEventListener('mouseup', handleMouseUp)
|
||||
return () => {
|
||||
document.removeEventListener('mousemove', handleMouseMove)
|
||||
document.removeEventListener('mouseup', handleMouseUp)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return { detailsHeight, handleResizeStart }
|
||||
}
|
||||
@@ -11,11 +11,19 @@ import {
|
||||
Files,
|
||||
Copy,
|
||||
Check,
|
||||
MessageSquare
|
||||
MessageSquare,
|
||||
ChevronDown
|
||||
} from 'lucide-react'
|
||||
import { ExternalLink } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import CommentMarkdown from '@/components/sidebar/CommentMarkdown'
|
||||
import type { PRInfo, PRCheckDetail, PRComment } from '../../../../shared/types'
|
||||
import {
|
||||
filterPRCommentsByAudience,
|
||||
isAutomatedPRComment,
|
||||
type PRCommentAudienceFilter
|
||||
} from './pr-comment-filters'
|
||||
import { useCheckDetailsResize } from './check-details-resize'
|
||||
|
||||
export const PullRequestIcon = GitPullRequest
|
||||
|
||||
@@ -106,6 +114,10 @@ export function ChecksList({
|
||||
checks: PRCheckDetail[]
|
||||
checksLoading: boolean
|
||||
}): React.JSX.Element {
|
||||
const [checksExpanded, setChecksExpanded] = useState(true)
|
||||
const { detailsHeight, handleResizeStart } = useCheckDetailsResize(
|
||||
checksExpanded && checks.length > 0
|
||||
)
|
||||
const sorted = [...checks].sort(
|
||||
(a, b) =>
|
||||
(CHECK_SORT_ORDER[a.conclusion ?? 'pending'] ?? 3) -
|
||||
@@ -123,7 +135,15 @@ export function ChecksList({
|
||||
<>
|
||||
{/* Checks Summary */}
|
||||
{checks.length > 0 && (
|
||||
<div className="flex items-center gap-3 px-3 py-2 border-b border-border text-[10px] text-muted-foreground">
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full items-center gap-3 border-b border-border px-3 py-2 text-left text-[10px] text-muted-foreground transition-colors hover:bg-accent/40 hover:text-foreground"
|
||||
onClick={() => setChecksExpanded((expanded) => !expanded)}
|
||||
aria-expanded={checksExpanded}
|
||||
>
|
||||
<ChevronDown
|
||||
className={cn('size-3 shrink-0 transition-transform', !checksExpanded && '-rotate-90')}
|
||||
/>
|
||||
{passingCount > 0 && (
|
||||
<span className="flex items-center gap-1">
|
||||
<CircleCheck className="size-3 text-emerald-500" />
|
||||
@@ -142,7 +162,9 @@ export function ChecksList({
|
||||
{pendingCount} pending
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="flex-1" />
|
||||
{checksLoading && <LoaderCircle className="size-3 animate-spin text-muted-foreground" />}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{/* Checks List */}
|
||||
@@ -154,38 +176,54 @@ export function ChecksList({
|
||||
<div className="flex items-center justify-center py-8 text-[11px] text-muted-foreground">
|
||||
No checks configured
|
||||
</div>
|
||||
) : (
|
||||
<div className="py-1">
|
||||
{sorted.map((check) => {
|
||||
const conclusion = check.conclusion ?? 'pending'
|
||||
const Icon = CHECK_ICON[conclusion] ?? CircleDashed
|
||||
const color = CHECK_COLOR[conclusion] ?? 'text-muted-foreground'
|
||||
return (
|
||||
<div
|
||||
key={check.name}
|
||||
className={cn(
|
||||
'flex items-center gap-2 px-3 py-1.5 hover:bg-accent/40 transition-colors',
|
||||
check.url && 'cursor-pointer'
|
||||
)}
|
||||
onClick={() => {
|
||||
if (check.url) {
|
||||
window.api.shell.openUrl(check.url)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Icon
|
||||
) : !checksExpanded ? null : (
|
||||
<>
|
||||
<div
|
||||
className="overflow-y-auto py-1 scrollbar-sleek"
|
||||
style={{ maxHeight: detailsHeight }}
|
||||
>
|
||||
{sorted.map((check) => {
|
||||
const conclusion = check.conclusion ?? 'pending'
|
||||
const Icon = CHECK_ICON[conclusion] ?? CircleDashed
|
||||
const color = CHECK_COLOR[conclusion] ?? 'text-muted-foreground'
|
||||
return (
|
||||
<div
|
||||
key={check.name}
|
||||
className={cn(
|
||||
'size-3.5 shrink-0',
|
||||
color,
|
||||
conclusion === 'pending' && 'animate-spin'
|
||||
'flex items-center gap-2 px-3 py-1.5 hover:bg-accent/40 transition-colors',
|
||||
check.url && 'cursor-pointer'
|
||||
)}
|
||||
/>
|
||||
<span className="flex-1 truncate text-[12px] text-foreground">{check.name}</span>
|
||||
{check.url && <ExternalLink className="size-3 text-muted-foreground/40 shrink-0" />}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
onClick={() => {
|
||||
if (check.url) {
|
||||
window.api.shell.openUrl(check.url)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Icon
|
||||
className={cn(
|
||||
'size-3.5 shrink-0',
|
||||
color,
|
||||
conclusion === 'pending' && 'animate-spin'
|
||||
)}
|
||||
/>
|
||||
<span className="flex-1 truncate text-[12px] text-foreground">{check.name}</span>
|
||||
{check.url && (
|
||||
<ExternalLink className="size-3 shrink-0 text-muted-foreground/40" />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
<div
|
||||
role="separator"
|
||||
aria-orientation="horizontal"
|
||||
title="Drag to resize checks"
|
||||
className="group flex h-2 cursor-row-resize items-center border-b border-border"
|
||||
onMouseDown={handleResizeStart}
|
||||
>
|
||||
<div className="h-px w-full bg-transparent transition-colors group-hover:bg-ring/40" />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
@@ -284,6 +322,7 @@ function CommentRow({
|
||||
showResolve: boolean
|
||||
onResolve?: (threadId: string, resolve: boolean) => void
|
||||
}): React.JSX.Element {
|
||||
const automated = isAutomatedPRComment(comment)
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
@@ -319,6 +358,11 @@ function CommentRow({
|
||||
>
|
||||
{comment.author}
|
||||
</span>
|
||||
{automated && (
|
||||
<span className="shrink-0 rounded border border-border bg-accent/40 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-muted-foreground">
|
||||
bot
|
||||
</span>
|
||||
)}
|
||||
{!isReply && comment.path && (
|
||||
<span className="text-[10px] font-mono text-muted-foreground/60 truncate min-w-0">
|
||||
{comment.path.split('/').pop()}
|
||||
@@ -337,15 +381,14 @@ function CommentRow({
|
||||
<CopyButton text={buildCopyText(comment)} />
|
||||
</div>
|
||||
</div>
|
||||
{/* Comment body */}
|
||||
<p
|
||||
<CommentMarkdown
|
||||
content={comment.body}
|
||||
className={cn(
|
||||
'text-[11px] text-muted-foreground leading-snug mt-0.5',
|
||||
isReply ? 'pl-5 line-clamp-1' : 'pl-[22px] line-clamp-2'
|
||||
'mt-1 text-[11px] leading-snug text-muted-foreground',
|
||||
'break-words [&_p]:my-1 [&_pre]:max-h-none [&_table]:min-w-max',
|
||||
isReply ? 'pl-5' : 'pl-[22px]'
|
||||
)}
|
||||
>
|
||||
{comment.body}
|
||||
</p>
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
@@ -404,16 +447,53 @@ export function PRCommentsList({
|
||||
commentsLoading: boolean
|
||||
onResolve?: (threadId: string, resolve: boolean) => void
|
||||
}): React.JSX.Element {
|
||||
const groups = React.useMemo(() => groupComments(comments), [comments])
|
||||
const [audienceFilter, setAudienceFilter] = useState<PRCommentAudienceFilter>('all')
|
||||
const humanCount = React.useMemo(
|
||||
() => comments.filter((comment) => !isAutomatedPRComment(comment)).length,
|
||||
[comments]
|
||||
)
|
||||
const botCount = comments.length - humanCount
|
||||
const filteredComments = React.useMemo(
|
||||
() => filterPRCommentsByAudience(comments, audienceFilter),
|
||||
[comments, audienceFilter]
|
||||
)
|
||||
const groups = React.useMemo(() => groupComments(filteredComments), [filteredComments])
|
||||
const filterOptions: { value: PRCommentAudienceFilter; label: string; count: number }[] = [
|
||||
{ value: 'all', label: 'All', count: comments.length },
|
||||
{ value: 'human', label: 'Humans', count: humanCount },
|
||||
{ value: 'bot', label: 'Bots', count: botCount }
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="border-t border-border">
|
||||
{/* Header */}
|
||||
<div className="flex items-center gap-2 px-3 py-2 border-b border-border">
|
||||
<MessageSquare className="size-3.5 text-muted-foreground" />
|
||||
<span className="text-[11px] font-medium text-foreground">Comments</span>
|
||||
<div className="border-b border-border px-3 py-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<MessageSquare className="size-3.5 text-muted-foreground" />
|
||||
<span className="text-[11px] font-medium text-foreground">Comments</span>
|
||||
{comments.length > 0 && (
|
||||
<span className="text-[10px] text-muted-foreground">{comments.length}</span>
|
||||
)}
|
||||
</div>
|
||||
{comments.length > 0 && (
|
||||
<span className="text-[10px] text-muted-foreground">{comments.length}</span>
|
||||
<div className="mt-2 grid grid-cols-3 rounded-md border border-border bg-background p-0.5">
|
||||
{filterOptions.map((option) => (
|
||||
<button
|
||||
key={option.value}
|
||||
type="button"
|
||||
className={cn(
|
||||
'rounded px-1.5 py-1 text-[10px] font-medium leading-none transition-colors',
|
||||
audienceFilter === option.value
|
||||
? 'bg-accent text-foreground shadow-sm'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
)}
|
||||
onClick={() => setAudienceFilter(option.value)}
|
||||
>
|
||||
{option.label}{' '}
|
||||
<span className="text-[9px] tabular-nums opacity-70">{option.count}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -426,6 +506,10 @@ export function PRCommentsList({
|
||||
<div className="flex items-center justify-center py-6 text-[11px] text-muted-foreground">
|
||||
No comments
|
||||
</div>
|
||||
) : filteredComments.length === 0 ? (
|
||||
<div className="flex items-center justify-center py-6 text-[11px] text-muted-foreground">
|
||||
No {audienceFilter === 'human' ? 'human' : 'bot'} comments
|
||||
</div>
|
||||
) : (
|
||||
<div className="py-1">
|
||||
{groups.map((group) => {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { PRComment } from '../../../../shared/types'
|
||||
import { filterPRCommentsByAudience, isAutomatedPRComment } from './pr-comment-filters'
|
||||
|
||||
function comment(author: string): PRComment {
|
||||
return {
|
||||
id: author.length,
|
||||
author,
|
||||
authorAvatarUrl: '',
|
||||
body: 'body',
|
||||
createdAt: '2026-04-26T00:00:00.000Z',
|
||||
url: ''
|
||||
}
|
||||
}
|
||||
|
||||
describe('pr-comment-filters', () => {
|
||||
it('classifies GitHub app and automation authors as bot comments', () => {
|
||||
expect(isAutomatedPRComment(comment('github-actions[bot]'))).toBe(true)
|
||||
expect(isAutomatedPRComment(comment('dependabot[bot]'))).toBe(true)
|
||||
expect(isAutomatedPRComment(comment('renovate-bot'))).toBe(true)
|
||||
expect(isAutomatedPRComment(comment('preview-automation'))).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps normal user logins as human comments', () => {
|
||||
expect(isAutomatedPRComment(comment('octocat'))).toBe(false)
|
||||
expect(isAutomatedPRComment(comment('robotics-dev'))).toBe(false)
|
||||
})
|
||||
|
||||
it('trusts the GitHub-provided isBot flag when true', () => {
|
||||
expect(isAutomatedPRComment({ ...comment('github-actions[bot]'), isBot: true })).toBe(true)
|
||||
})
|
||||
|
||||
it('classifies known AI review services that register as User accounts', () => {
|
||||
// These sign in as regular GitHub users, so GitHub's user.type is 'User'
|
||||
// and their logins have no "bot" / "automation" tokens. Allowlist picks
|
||||
// them up regardless.
|
||||
expect(isAutomatedPRComment({ ...comment('qodo-ai-reviewer'), isBot: false })).toBe(true)
|
||||
expect(isAutomatedPRComment({ ...comment('coderabbitai'), isBot: false })).toBe(true)
|
||||
expect(isAutomatedPRComment(comment('sonarcloud'))).toBe(true)
|
||||
expect(isAutomatedPRComment(comment('codium-ai-reviewer'))).toBe(true)
|
||||
})
|
||||
|
||||
it('filters comments by audience', () => {
|
||||
const comments = [
|
||||
comment('octocat'),
|
||||
comment('github-actions[bot]'),
|
||||
comment('mona'),
|
||||
comment('dependabot[bot]')
|
||||
]
|
||||
|
||||
expect(filterPRCommentsByAudience(comments, 'all')).toEqual(comments)
|
||||
expect(filterPRCommentsByAudience(comments, 'human').map((c) => c.author)).toEqual([
|
||||
'octocat',
|
||||
'mona'
|
||||
])
|
||||
expect(filterPRCommentsByAudience(comments, 'bot').map((c) => c.author)).toEqual([
|
||||
'github-actions[bot]',
|
||||
'dependabot[bot]'
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,69 @@
|
||||
import type { PRComment } from '../../../../shared/types'
|
||||
|
||||
export type PRCommentAudienceFilter = 'all' | 'human' | 'bot'
|
||||
|
||||
const BOT_LOGIN_SUFFIX = '[bot]'
|
||||
const AUTOMATION_LOGIN_PATTERNS = [
|
||||
/bot$/i,
|
||||
/-bot$/i,
|
||||
/\bbot\b/i,
|
||||
/automation/i,
|
||||
/actions/i,
|
||||
/renovate/i,
|
||||
/dependabot/i
|
||||
]
|
||||
// Why: several AI code-review services register as regular GitHub *user*
|
||||
// accounts rather than GitHub Apps, so REST `user.type` returns "User" and
|
||||
// their logins don't contain "bot"/"automation" either (qodo-ai-reviewer,
|
||||
// coderabbitai, codium-ai, etc.). Maintain an explicit allowlist so these
|
||||
// still land in the Bots tab. Matched as a substring to cover variants
|
||||
// like `coderabbitai[bot]`, `qodo-ai-reviewer`, `qodo-merge-pro`.
|
||||
const KNOWN_AUTOMATION_LOGIN_SUBSTRINGS = [
|
||||
'qodo',
|
||||
'coderabbit',
|
||||
'codium',
|
||||
'sonarcloud',
|
||||
'sonarqube',
|
||||
'sourcery-ai',
|
||||
'deepsource',
|
||||
'snyk',
|
||||
'codecov',
|
||||
'greptile',
|
||||
'ellipsis',
|
||||
'graphite-app',
|
||||
'reviewer-gpt',
|
||||
'-reviewer'
|
||||
]
|
||||
|
||||
export function isAutomatedPRComment(comment: PRComment): boolean {
|
||||
// Why: GitHub's REST `user.type === 'Bot'` and GraphQL `author.__typename === 'Bot'`
|
||||
// only flag accounts registered as GitHub Apps. Several popular AI reviewers
|
||||
// (qodo-ai-reviewer, coderabbitai) sign in as regular *user* accounts, so
|
||||
// `isBot` returns false for them. Treat isBot=true as authoritative, but when
|
||||
// absent or false, fall through to login heuristics + a known-bot allowlist.
|
||||
if (comment.isBot === true) {
|
||||
return true
|
||||
}
|
||||
const author = comment.author.trim()
|
||||
const normalized = author.toLowerCase()
|
||||
if (normalized.endsWith(BOT_LOGIN_SUFFIX)) {
|
||||
return true
|
||||
}
|
||||
if (KNOWN_AUTOMATION_LOGIN_SUBSTRINGS.some((needle) => normalized.includes(needle))) {
|
||||
return true
|
||||
}
|
||||
return AUTOMATION_LOGIN_PATTERNS.some((pattern) => pattern.test(author))
|
||||
}
|
||||
|
||||
export function filterPRCommentsByAudience(
|
||||
comments: PRComment[],
|
||||
filter: PRCommentAudienceFilter
|
||||
): PRComment[] {
|
||||
if (filter === 'all') {
|
||||
return comments
|
||||
}
|
||||
return comments.filter((comment) => {
|
||||
const automated = isAutomatedPRComment(comment)
|
||||
return filter === 'bot' ? automated : !automated
|
||||
})
|
||||
}
|
||||
@@ -2,6 +2,8 @@ import React from 'react'
|
||||
import Markdown from 'react-markdown'
|
||||
import remarkGfm from 'remark-gfm'
|
||||
import remarkBreaks from 'remark-breaks'
|
||||
import rehypeRaw from 'rehype-raw'
|
||||
import rehypeSanitize from 'rehype-sanitize'
|
||||
import type { Components } from 'react-markdown'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
@@ -99,6 +101,9 @@ const components: Components = {
|
||||
// remark-breaks converts single newlines to <br>, keeping backward compat
|
||||
// with existing plain-text comments that rely on newline formatting.
|
||||
const remarkPlugins = [remarkGfm, remarkBreaks]
|
||||
// Why: GitHub comments commonly contain trusted-looking raw HTML from bots
|
||||
// (`<table>`, `<h2>`). Parse it for readability, then sanitize before render.
|
||||
const rehypePlugins = [rehypeRaw, rehypeSanitize]
|
||||
|
||||
type CommentMarkdownProps = React.ComponentPropsWithoutRef<'div'> & {
|
||||
content: string
|
||||
@@ -124,7 +129,11 @@ const CommentMarkdown = React.memo(
|
||||
)}
|
||||
{...rest}
|
||||
>
|
||||
<Markdown remarkPlugins={remarkPlugins} components={components}>
|
||||
<Markdown
|
||||
remarkPlugins={remarkPlugins}
|
||||
rehypePlugins={rehypePlugins}
|
||||
components={components}
|
||||
>
|
||||
{content}
|
||||
</Markdown>
|
||||
</div>
|
||||
|
||||
@@ -381,6 +381,12 @@ export type PRComment = {
|
||||
line?: number
|
||||
/** Start line of the review annotation range (1-based). Absent for single-line comments. */
|
||||
startLine?: number
|
||||
/** True when GitHub identifies the author as a bot (REST `user.type === 'Bot'` or
|
||||
* GraphQL `__typename === 'Bot'`). Preferred over login-string heuristics because
|
||||
* third-party review bots (e.g. qodo-ai-reviewer, coderabbitai) don't follow a
|
||||
* predictable naming convention. Absent when the data source can't report it
|
||||
* (non-GitHub fallbacks via `gh pr view`). */
|
||||
isBot?: boolean
|
||||
}
|
||||
|
||||
export type IssueInfo = {
|
||||
|
||||
Reference in New Issue
Block a user