"use client"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardHeader } from "@/components/ui/card"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; import { formatDistanceToNow } from "date-fns"; import { ptBR } from "date-fns/locale"; import { RiGitCommitLine, RiUserLine, RiCalendarLine, RiFileList2Line, } from "@remixicon/react"; type GitCommit = { hash: string; shortHash: string; author: string; date: string; message: string; body: string; filesChanged: string[]; }; type ChangelogListProps = { commits: GitCommit[]; repoUrl: string | null; }; type CommitType = { type: string; scope?: string; description: string; }; function parseCommitMessage(message: string): CommitType { const conventionalPattern = /^(\w+)(?:$$([^)]+)$$)?:\s*(.+)$/; const match = message.match(conventionalPattern); if (match) { return { type: match[1], scope: match[2], description: match[3], }; } return { type: "chore", description: message, }; } function getCommitTypeColor(type: string): string { const colors: Record = { feat: "bg-emerald-500/10 text-emerald-700 dark:text-emerald-400 border-emerald-500/20", fix: "bg-red-500/10 text-red-700 dark:text-red-400 border-red-500/20", docs: "bg-blue-500/10 text-blue-700 dark:text-blue-400 border-blue-500/20", style: "bg-purple-500/10 text-purple-700 dark:text-purple-400 border-purple-500/20", refactor: "bg-orange-500/10 text-orange-700 dark:text-orange-400 border-orange-500/20", perf: "bg-yellow-500/10 text-yellow-700 dark:text-yellow-400 border-yellow-500/20", test: "bg-pink-500/10 text-pink-700 dark:text-pink-400 border-pink-500/20", chore: "bg-gray-500/10 text-gray-700 dark:text-gray-400 border-gray-500/20", }; return colors[type] || colors.chore; } export function ChangelogList({ commits, repoUrl }: ChangelogListProps) { if (!commits || commits.length === 0) { return (

Nenhum commit encontrado no repositório

); } return (
{commits.map((commit) => ( ))}
); } function CommitCard({ commit, repoUrl, }: { commit: GitCommit; repoUrl: string | null; }) { const commitDate = new Date(commit.date); const relativeTime = formatDistanceToNow(commitDate, { addSuffix: true, locale: ptBR, }); const commitUrl = repoUrl ? `${repoUrl}/commit/${commit.hash}` : null; const parsed = parseCommitMessage(commit.message); return (
{parsed.type} {parsed.scope && ( {parsed.scope} )} {parsed.description}
{commitUrl ? ( {commit.shortHash} ) : ( {commit.shortHash} )} {commit.author} {relativeTime}
{commit.body && ( {commit.body} )} {commit.filesChanged.length > 0 && (
{commit.filesChanged.length} arquivo {commit.filesChanged.length !== 1 ? "s" : ""}
    {commit.filesChanged.map((file, index) => (
  • {file}
  • ))}
)}
); }