Skip to content

Commit a80bf8e

Browse files
committed
fix: defensive parsing and dynamic branch in GitHub URLs
- RepoSummaryCard: defensive namingConventions sort (handle NaN, empty array) - ResultCard: language badge uses same fallback as SyntaxHighlighter - ResultCard: use defaultBranch prop instead of hardcoded 'main' - SearchPanel: pass defaultBranch to ResultCard - DashboardHome: pass repo.branch to SearchPanel
1 parent 3e45072 commit a80bf8e

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

frontend/src/components/RepoSummaryCard.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,16 @@ function generateSummary(repo: Repository, insights: any, style: any) {
117117
const asyncAdoption = style?.summary?.async_adoption || null
118118
const typeHints = style?.summary?.type_hints_usage || null
119119

120-
// Get naming convention
120+
// Get naming convention - defensive parsing
121121
const namingConventions = style?.naming_conventions?.functions || {}
122-
const primaryNaming = Object.entries(namingConventions)
123-
.sort((a: any, b: any) => parseFloat(b[1].percentage) - parseFloat(a[1].percentage))[0]
122+
const namingEntries = Object.entries(namingConventions)
123+
const primaryNaming = namingEntries.length > 0
124+
? namingEntries.sort((a: any, b: any) => {
125+
const pctA = parseFloat(a[1]?.percentage ?? '0') || 0
126+
const pctB = parseFloat(b[1]?.percentage ?? '0') || 0
127+
return pctB - pctA
128+
})[0]
129+
: null
124130
const namingStyle = primaryNaming ? primaryNaming[0] : null
125131

126132
// Get critical files

frontend/src/components/SearchPanel.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ interface SearchPanelProps {
99
apiUrl: string;
1010
apiKey: string;
1111
repoUrl?: string;
12+
defaultBranch?: string;
1213
}
1314

14-
export function SearchPanel({ repoId, apiUrl, apiKey, repoUrl }: SearchPanelProps) {
15+
export function SearchPanel({ repoId, apiUrl, apiKey, repoUrl, defaultBranch }: SearchPanelProps) {
1516
const [query, setQuery] = useState('');
1617
const [results, setResults] = useState<SearchResult[]>([]);
1718
const [loading, setLoading] = useState(false);
@@ -79,6 +80,7 @@ export function SearchPanel({ repoId, apiUrl, apiKey, repoUrl }: SearchPanelProp
7980
isExpanded={idx === 0}
8081
aiSummary={idx === 0 ? aiSummary || undefined : undefined}
8182
repoUrl={repoUrl}
83+
defaultBranch={defaultBranch}
8284
/>
8385
))}
8486
</div>

frontend/src/components/dashboard/DashboardHome.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ export function DashboardHome() {
229229
apiUrl={API_URL}
230230
apiKey={session?.access_token || ''}
231231
repoUrl={selectedRepoData?.git_url?.replace('.git', '')}
232+
defaultBranch={selectedRepoData?.branch}
232233
/>
233234
)}
234235
{activeTab === 'dependencies' && (

frontend/src/components/search/ResultCard.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ interface ResultCardProps {
1313
isExpanded?: boolean;
1414
aiSummary?: string;
1515
repoUrl?: string;
16+
defaultBranch?: string;
1617
}
1718

18-
export function ResultCard({ result, rank, isExpanded: initialExpanded = false, aiSummary, repoUrl }: ResultCardProps) {
19+
export function ResultCard({ result, rank, isExpanded: initialExpanded = false, aiSummary, repoUrl, defaultBranch = 'main' }: ResultCardProps) {
1920
const [expanded, setExpanded] = useState(initialExpanded);
2021
const contentRef = useRef<HTMLDivElement>(null);
2122
const [contentHeight, setContentHeight] = useState<number | undefined>(initialExpanded ? undefined : 0);
@@ -26,7 +27,7 @@ export function ResultCard({ result, rank, isExpanded: initialExpanded = false,
2627

2728
const cleanFilePath = result.file_path.replace(/^repos\/[a-f0-9-]+\//, '');
2829
const displayPath = cleanFilePath.split('/').slice(-3).join('/');
29-
const githubUrl = repoUrl ? `${repoUrl}/blob/main/${cleanFilePath}#L${result.line_start}-L${result.line_end}` : null;
30+
const githubUrl = repoUrl ? `${repoUrl}/blob/${defaultBranch}/${cleanFilePath}#L${result.line_start}-L${result.line_end}` : null;
3031

3132
useEffect(() => {
3233
if (expanded) {
@@ -98,7 +99,7 @@ export function ResultCard({ result, rank, isExpanded: initialExpanded = false,
9899
>
99100
{result.code}
100101
</SyntaxHighlighter>
101-
<span className="absolute top-3 right-3 px-2 py-0.5 text-[10px] font-mono uppercase bg-muted text-muted-foreground rounded">{result.language}</span>
102+
<span className="absolute top-3 right-3 px-2 py-0.5 text-[10px] font-mono uppercase bg-muted text-muted-foreground rounded">{result.language || 'text'}</span>
102103
</div>
103104

104105
<div className="px-4 py-3 bg-muted/50 flex items-center justify-between">

0 commit comments

Comments
 (0)