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.
This commit is contained in:
sebseb7
2025-08-04 14:31:32 +02:00
parent a5db1f34cb
commit e5f50d3db3

23
x.js
View File

@@ -169,12 +169,14 @@ async function summarizeMostRecentCommitDE(webhookPayload = null) {
return null; return null;
} }
let commits = []; // Require webhook payload - no fallback to local git
let diff = ''; if (!webhookPayload || !webhookPayload.commits || webhookPayload.commits.length === 0) {
logMessage('No webhook payload or commits provided for executive summary', 'warn');
return null;
}
if (webhookPayload && webhookPayload.commits && webhookPayload.commits.length > 0) {
// Use webhook payload data // Use webhook payload data
commits = webhookPayload.commits.map(commit => ({ const commits = webhookPayload.commits.map(commit => ({
hash: commit.id, hash: commit.id,
author: commit.author?.name || 'Unknown', author: commit.author?.name || 'Unknown',
date: commit.timestamp || new Date().toISOString(), date: commit.timestamp || new Date().toISOString(),
@@ -188,17 +190,12 @@ async function summarizeMostRecentCommitDE(webhookPayload = null) {
const repoName = webhookPayload.repository?.name; const repoName = webhookPayload.repository?.name;
const latestCommitHash = commits[0]?.hash; const latestCommitHash = commits[0]?.hash;
if (giteaBaseUrl && repoOwner && repoName && latestCommitHash) { if (!giteaBaseUrl || !repoOwner || !repoName || !latestCommitHash) {
diff = await getCommitDiffFromGitea(giteaBaseUrl, repoOwner, repoName, latestCommitHash); logMessage('Missing required repository information in webhook payload for executive summary', 'warn');
} return null;
} 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 });
} }
if (!commits.length) return null; const diff = await getCommitDiffFromGitea(giteaBaseUrl, repoOwner, repoName, latestCommitHash);
const prompt = buildMostRecentCommitPromptGerman(commits); const prompt = buildMostRecentCommitPromptGerman(commits);
if (!prompt) return null; if (!prompt) return null;