From e5f50d3db365c5d4813d4dd2645c774df66a94f8 Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Mon, 4 Aug 2025 14:31:32 +0200 Subject: [PATCH] refactor(api): require webhook payload for commit summary and remove local git fallback Update the summarizeMostRecentCommitDE function to enforce the presence of a webhook payload for commit data retrieval, eliminating the fallback to local git. Add logging for missing payloads and repository information to enhance error handling. --- x.js | 53 +++++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/x.js b/x.js index 8d5362a..3b243ba 100644 --- a/x.js +++ b/x.js @@ -169,36 +169,33 @@ async function summarizeMostRecentCommitDE(webhookPayload = null) { return null; } - let commits = []; - let diff = ''; - - if (webhookPayload && webhookPayload.commits && webhookPayload.commits.length > 0) { - // Use webhook payload data - commits = webhookPayload.commits.map(commit => ({ - hash: commit.id, - author: commit.author?.name || 'Unknown', - date: commit.timestamp || new Date().toISOString(), - subject: commit.message?.split('\n')[0] || 'No subject', - body: commit.message?.split('\n').slice(1).join('\n') || '' - })); - - // Extract Gitea base URL from webhook payload - const giteaBaseUrl = webhookPayload.repository?.html_url?.match(/^https?:\/\/[^\/]+/)?.[0]; - const repoOwner = webhookPayload.repository?.owner?.login; - const repoName = webhookPayload.repository?.name; - const latestCommitHash = commits[0]?.hash; - - if (giteaBaseUrl && repoOwner && repoName && latestCommitHash) { - diff = await getCommitDiffFromGitea(giteaBaseUrl, repoOwner, repoName, latestCommitHash); - } - } else { - // Fallback to local git (original behavior) - commits = await getLastCommits({ count: 10, repoDir: process.cwd() }); - if (!commits.length) return null; - diff = await getLastCommitDiff({ repoDir: process.cwd(), contextLines: 3 }); + // Require webhook payload - no fallback to local git + if (!webhookPayload || !webhookPayload.commits || webhookPayload.commits.length === 0) { + logMessage('No webhook payload or commits provided for executive summary', 'warn'); + return null; } - if (!commits.length) return null; + // Use webhook payload data + const commits = webhookPayload.commits.map(commit => ({ + hash: commit.id, + author: commit.author?.name || 'Unknown', + date: commit.timestamp || new Date().toISOString(), + subject: commit.message?.split('\n')[0] || 'No subject', + body: commit.message?.split('\n').slice(1).join('\n') || '' + })); + + // Extract Gitea base URL from webhook payload + const giteaBaseUrl = webhookPayload.repository?.html_url?.match(/^https?:\/\/[^\/]+/)?.[0]; + const repoOwner = webhookPayload.repository?.owner?.login; + const repoName = webhookPayload.repository?.name; + const latestCommitHash = commits[0]?.hash; + + if (!giteaBaseUrl || !repoOwner || !repoName || !latestCommitHash) { + logMessage('Missing required repository information in webhook payload for executive summary', 'warn'); + return null; + } + + const diff = await getCommitDiffFromGitea(giteaBaseUrl, repoOwner, repoName, latestCommitHash); const prompt = buildMostRecentCommitPromptGerman(commits); if (!prompt) return null;