/// import { computed, Default, derive, fetchData, generateText, NAME, pattern, UI, Writable, } from "commontools"; type CommitResponse = Array<{ sha: string; html_url: string; commit: { message: string; author: { name: string; date: string; }; }; }>; function parseUrl(url: string): { owner: string; repo: string } { const match = url.match(/github\.com\/([^\/]+)\/([^\/]+)/); if (match) { return { owner: match[1], repo: match[2] }; } return { owner: "", repo: "" }; } export default pattern<{ repoUrl: Writable< Default >; }>((state) => { // Parse URL and create API endpoint const parsed = computed(() => parseUrl(state.repoUrl.get())); const apiUrl = computed(() => { const { owner, repo } = parsed; if (owner && repo) { return `https://api.github.com/repos/${owner}/${repo}/commits`; } return ""; }); // Fetch commits data const commitsData = fetchData({ url: apiUrl, mode: "json", }); const commits = commitsData.result; // Build prompt from commits const prompt = computed(() => { const commitList = commits ?? []; if (commitList.length === 0) return ""; const messages = commitList .slice(0, 10) .map((c) => `- ${c.commit.message.split("\n")[0]}`) .join("\n"); return `Recent commits:\n${messages}`; }); // Generate summary const summary = generateText({ system: "You are a concise technical writer. Summarize the recent development activity based on these commit messages. Focus on themes and notable changes. Keep it to 2-3 sentences.", prompt: prompt, }); const repoName = computed(() => { const { owner, repo } = parsed; if (owner && repo) { return `${owner}/${repo}`; } return "GitHub Activity"; }); return { [NAME]: computed(() => `GitHub Activity: ${repoName}`), [UI]: ( {derive( [summary.pending, summary.result], ([pending, result]) => pending ? ( Generating summary... ) : result ? ( Activity Summary {result} ) : null, )} {derive(commits, (commitList) => { if (!commitList || commitList.length === 0) { return ( No commits found ); } return ( {commitList.slice(0, 20).map((commit) => { const firstLine = commit.commit.message.split("\n")[0]; const date = new Date(commit.commit.author.date) .toLocaleDateString(); return ( {firstLine} {commit.commit.author.name} • {date} View commit → ); })} ); })} ), }; });
{result}