CoolFace
Apppublic

admin08077/Githubgemini

sourceHugging Faceotherupdated 10mo agoView on Hugging Face
0likes
VisualGitTree-CpR-Akou.js.map1 linesDownload Raw Back to assets
1{"version":3,"file":"VisualGitTree-CpR-Akou.js","sources":["../../components/features/VisualGitTree.tsx"],"sourcesContent":["import React, { useState, useCallback, useEffect, useMemo } from 'react';\nimport { GitBranchIcon, ArrowDownTrayIcon } from '../icons.tsx';\nimport { generateChangelogFromLogStream } from '../../services/geminiService.ts';\nimport { LoadingSpinner } from './shared/LoadingSpinner.tsx';\nimport { MarkdownRenderer } from '../shared/index.tsx';\nimport { downloadFile } from '../../services/fileUtils.ts';\n\nconst exampleLog = `* commit 3a4b5c6d7e8f9g0h1i2j3k4l5m6n7o8p9q0r (HEAD -> main, origin/main)\n|\\\\  Merge: 1a2b3c4 2d3e4f5\n| | Author: Dev One <dev.one@example.com>\n| | Date:   Mon Jul 15 11:30:00 2024 -0400\n| |\n| |     feat: Implement collapsible sidebar navigation\n| |\n* | commit 2d3e4f5g6h7i8j9k0l1m2n3o4p5q6r7s8t9u (feature/new-sidebar)\n| | Author: Dev Two <dev.two@example.com>\n| | Date:   Mon Jul 15 10:00:00 2024 -0400\n| |\n| |     feat: Add icons to sidebar items\n| |\n* | commit 1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r\n|/  Author: Dev One <dev.one@example.com>\n|   Date:   Fri Jul 12 16:45:00 2024 -0400\n|\n|       fix: Correct user authentication bug`;\n\nconst CommitGraph = ({ logInput }: { logInput: string }) => {\n    const commits = useMemo(() => {\n        const lines = logInput.split('\\n');\n        const parsedCommits: any[] = [];\n        let currentCommit: any = null;\n\n        lines.forEach(line => {\n            const commitMatch = line.match(/^.?[\\\\|/ ]*\\* commit (\\w+)(.*)/);\n            if (commitMatch) {\n                if (currentCommit) parsedCommits.push(currentCommit);\n                currentCommit = {\n                    hash: commitMatch[1],\n                    shortHash: commitMatch[1].substring(0, 7),\n                    refs: commitMatch[2].trim(),\n                    message: '',\n                    author: '',\n                };\n            } else if (currentCommit) {\n                 if (line.includes('Author:')) currentCommit.author = line.split('Author:')[1].trim();\n                 else if (line.trim().length > 0 && !line.match(/^[\\\\|/ ]*[\\\\|/ ]/)) {\n                     currentCommit.message += line.trim() + ' ';\n                 }\n            }\n        });\n        if (currentCommit) parsedCommits.push(currentCommit);\n        \n        return parsedCommits.map((c, i) => ({ ...c, x: 50, y: 50 + i * 60 }));\n    }, [logInput]);\n\n    return (\n         <svg width=\"100%\" height={50 + commits.length * 60} className=\"min-h-[200px]\">\n            {commits.map((commit, i) => {\n                const parent = commits[i + 1];\n                return (\n                    <g key={commit.hash}>\n                        {parent && <line x1={commit.x} y1={commit.y} x2={parent.x} y2={parent.y} stroke=\"var(--color-border)\" strokeWidth=\"2\" />}\n                        <g className=\"group cursor-pointer\">\n                            <circle cx={commit.x} cy={commit.y} r=\"8\" fill=\"var(--color-primary)\" stroke=\"var(--color-surface)\" strokeWidth=\"3\" />\n                            <foreignObject x={commit.x + 20} y={commit.y - 25} width=\"350\" height=\"50\">\n                                <div className=\"text-sm p-1\">\n                                    <p className=\"font-bold truncate text-text-primary\">{commit.message}</p>\n                                    <p className=\"text-xs text-text-secondary font-mono\">{commit.shortHash} <span className=\"text-amber-600\">{commit.refs}</span></p>\n                                </div>\n                            </foreignObject>\n                            <title>{`Commit: ${commit.hash}\\nAuthor: ${commit.author}\\n\\n${commit.message}`}</title>\n                        </g>\n                    </g>\n                );\n            })}\n        </svg>\n    );\n};\n\nexport const VisualGitTree: React.FC<{ logInput?: string }> = ({ logInput: initialLogInput }) => {\n    const [logInput, setLogInput] = useState(initialLogInput || exampleLog);\n    const [analysis, setAnalysis] = useState('');\n    const [isLoading, setIsLoading] = useState(false);\n    const [error, setError] = useState('');\n\n    const handleAnalyze = useCallback(async (logToAnalyze: string) => {\n        if (!logToAnalyze.trim()) {\n            setError('Please paste git log output.');\n            return;\n        }\n        setIsLoading(true);\n        setError('');\n        setAnalysis('');\n        try {\n            const stream = generateChangelogFromLogStream(logToAnalyze);\n            let fullResponse = '';\n            for await (const chunk of stream) {\n                fullResponse += chunk;\n                setAnalysis(fullResponse);\n            }\n        } catch (err) {\n            const errorMessage = err instanceof Error ? err.message : 'An unknown error occurred.';\n            setError(`Failed to analyze log: ${errorMessage}`);\n        } finally {\n            setIsLoading(false);\n        }\n    }, []);\n\n    useEffect(() => {\n        if (initialLogInput) {\n            setLogInput(initialLogInput);\n            handleAnalyze(initialLogInput);\n        }\n    }, [initialLogInput, handleAnalyze]);\n\n    return (\n        <div className=\"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary\">\n            <header className=\"mb-6\">\n                <h1 className=\"text-3xl font-bold flex items-center\">\n                    <GitBranchIcon />\n                    <span className=\"ml-3\">Visual Git Tree</span>\n                </h1>\n                <p className=\"text-text-secondary mt-1\">Paste your `git log --graph` output to visualize the history and get an AI summary.</p>\n            </header>\n            <div className=\"flex-grow grid grid-cols-1 lg:grid-cols-2 gap-6 h-full overflow-hidden\">\n                <div className=\"flex flex-col h-full\">\n                    <label htmlFor=\"log-input\" className=\"text-sm font-medium text-text-secondary mb-2\">Git Log Output</label>\n                    <textarea\n                        id=\"log-input\"\n                        value={logInput}\n                        onChange={(e) => setLogInput(e.target.value)}\n                        placeholder=\"Paste your git log output here...\"\n                        className=\"flex-grow p-4 bg-surface border border-border rounded-md resize-none font-mono text-sm\"\n                    />\n                    <button\n                        onClick={() => handleAnalyze(logInput)}\n                        disabled={isLoading}\n                        className=\"btn-primary mt-4 w-full flex items-center justify-center px-6 py-3\"\n                    >\n                        {isLoading ? <LoadingSpinner /> : 'Analyze & Summarize'}\n                    </button>\n                </div>\n                <div className=\"flex flex-col h-full gap-4\">\n                    <div className=\"flex flex-col h-1/2\">\n                        <label className=\"text-sm font-medium text-text-secondary mb-2\">Commit Graph</label>\n                        <div className=\"flex-grow p-2 bg-surface border border-border rounded-md overflow-auto\">\n                            <CommitGraph logInput={logInput} />\n                        </div>\n                    </div>\n                     <div className=\"flex flex-col h-1/2\">\n                        <div className=\"flex justify-between items-center mb-2\">\n                            <label className=\"text-sm font-medium text-text-secondary\">AI Summary</label>\n                            {analysis && !isLoading && (\n                                <button onClick={() => downloadFile(analysis, 'summary.md', 'text/markdown')} className=\"flex items-center gap-1 px-3 py-1 bg-gray-100 text-xs rounded-md hover:bg-gray-200\">\n                                    <ArrowDownTrayIcon className=\"w-4 h-4\"/> Download Summary\n                                </button>\n                            )}\n                        </div>\n                        <div className=\"flex-grow p-4 bg-background border border-border rounded-md overflow-y-auto\">\n                            {isLoading && <div className=\"flex items-center justify-center h-full\"><LoadingSpinner /></div>}\n                            {error && <p className=\"text-red-500\">{error}</p>}\n                            {analysis && !isLoading && <MarkdownRenderer content={analysis} />}\n                            {!isLoading && !analysis && !error && <div className=\"text-text-secondary h-full flex items-center justify-center\">AI summary will appear here.</div>}\n                        </div>\n                    </div>\n                </div>\n            </div>\n        </div>\n    );\n};"],"names":["exampleLog","CommitGraph","logInput","commits","useMemo","lines","parsedCommits","currentCommit","line","commitMatch","c","i","jsx","commit","parent","jsxs","VisualGitTree","initialLogInput","setLogInput","useState","analysis","setAnalysis","isLoading","setIsLoading","error","setError","handleAnalyze","useCallback","logToAnalyze","stream","generateChangelogFromLogStream","fullResponse","chunk","err","errorMessage","useEffect","GitBranchIcon","e","LoadingSpinner","downloadFile","ArrowDownTrayIcon","MarkdownRenderer"],"mappings":"ocAOA,MAAMA,EAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8CAmBbC,EAAc,CAAC,CAAE,SAAAC,KAAqC,CACxD,MAAMC,EAAUC,EAAAA,QAAQ,IAAM,CAC1B,MAAMC,EAAQH,EAAS,MAAM;AAAA,CAAI,EAC3BI,EAAuB,CAAA,EAC7B,IAAIC,EAAqB,KAEzB,OAAAF,EAAM,QAAQG,GAAQ,CAClB,MAAMC,EAAcD,EAAK,MAAM,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