From dda6ba49cf6735aa632d62e9fce4488678186cd4 Mon Sep 17 00:00:00 2001 From: asepharyana Date: Fri, 3 Jul 2026 05:23:33 +0700 Subject: [PATCH] fix: filter profile repo events, better PushEvent formatting --- scripts/generate-ai-blog.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/scripts/generate-ai-blog.js b/scripts/generate-ai-blog.js index 642f0d3..89cdf42 100644 --- a/scripts/generate-ai-blog.js +++ b/scripts/generate-ai-blog.js @@ -79,11 +79,16 @@ function formatEvent(event) { .slice(0, 3) .map((c) => c.message?.split("\n")[0] || "no message") .filter(Boolean); - return `• Push ${commits.length} commit${commits.length > 1 ? "s" : ""} ke \`${repo}\` (${branch}): ${msgs.join("; ")}`; + if (commits.length > 0) { + return `• Push ${commits.length} commit${commits.length > 1 ? "s" : ""} ke \`${repo}\` (${branch}): ${msgs.join("; ")}`; + } + return `• Push ke \`${repo}\` (${branch})`; } case "CreateEvent": { const refType = event.payload?.ref_type || ""; const ref = event.payload?.ref || refType; + // Skip branch creations (usually noisy — CI/initial setup) + if (refType === "branch") return null; return `• Membuat ${refType} baru: \`${ref}\` di \`${repo}\``; } case "PullRequestEvent": { @@ -166,13 +171,14 @@ async function main() { return; } - // 2. Filter to recent + relevant event types + // 2. Filter: recent + relevant event types, and exclude profile repo itself + const profileRepo = `${GITHUB_USER}/${GITHUB_USER}`; + const relevantTypes = ["PushEvent", "CreateEvent", "PullRequestEvent", "IssuesEvent", "WatchEvent", "ForkEvent"]; const recent = events.filter( (e) => isRecent(e.created_at, EVENTS_DAYS_BACK) && - ["PushEvent", "CreateEvent", "PullRequestEvent", "IssuesEvent", "WatchEvent", "ForkEvent"].includes( - e.type - ) + relevantTypes.includes(e.type) && + e.repo?.name !== profileRepo ); if (recent.length === 0) { @@ -183,7 +189,16 @@ async function main() { // 3. Format and deduplicate const deduped = deduplicate(recent); - const formatted = deduped.map(formatEvent).join("\n"); + const formatted = deduped + .map(formatEvent) + .filter(Boolean) + .join("\n"); + + if (!formatted) { + console.log("[AI Blog] No meaningful activity after filtering"); + writeFallback(); + return; + } console.log(`[AI Blog] Found ${deduped.length} unique events:\n${formatted}`); // 4. Build LLM prompt