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:
53
x.js
53
x.js
@@ -169,36 +169,33 @@ 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');
|
||||||
if (webhookPayload && webhookPayload.commits && webhookPayload.commits.length > 0) {
|
return null;
|
||||||
// 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 });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
const prompt = buildMostRecentCommitPromptGerman(commits);
|
||||||
if (!prompt) return null;
|
if (!prompt) return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user