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