diff --git a/apps/desktop/src/lib/ai/service.ts b/apps/desktop/src/lib/ai/service.ts index 3894bb355..b0a7ad7f7 100644 --- a/apps/desktop/src/lib/ai/service.ts +++ b/apps/desktop/src/lib/ai/service.ts @@ -62,7 +62,7 @@ interface SummarizeCommitOpts extends BaseAIServiceOpts { } interface SummarizeBranchOpts extends BaseAIServiceOpts { - hunks: Hunk[]; + hunks: DiffInput[]; branchTemplate?: Prompt; } @@ -75,8 +75,13 @@ interface SummarizePROpts extends BaseAIServiceOpts { prBodyTemplate?: string; } +interface DiffInput { + filePath: string; + diff: string; +} + // Exported for testing only -export function buildDiff(hunks: Hunk[], limit: number) { +export function buildDiff(hunks: DiffInput[], limit: number) { return shuffle(hunks.map((h) => `${h.filePath} - ${h.diff}`)) .join('\n') .slice(0, limit); diff --git a/apps/desktop/src/lib/branch/SeriesHeader.svelte b/apps/desktop/src/lib/branch/SeriesHeader.svelte index db7c0158d..5d36b9fdb 100644 --- a/apps/desktop/src/lib/branch/SeriesHeader.svelte +++ b/apps/desktop/src/lib/branch/SeriesHeader.svelte @@ -23,6 +23,7 @@ import { isFailure } from '$lib/result'; import { openExternalUrl } from '$lib/utils/url'; import { BranchController } from '$lib/vbranches/branchController'; + import { listCommitFiles } from '$lib/vbranches/remoteCommits'; import { PatchSeries, VirtualBranch, type CommitStatus } from '$lib/vbranches/types'; import { CloudBranchesService } from '@gitbutler/shared/cloud/stacks/service'; import { getContext, getContextStore } from '@gitbutler/shared/context'; @@ -140,7 +141,15 @@ async function generateBranchName() { if (!aiGenEnabled || !currentSeries) return; - const hunks = currentSeries.patches.flatMap((p) => p.files.flatMap((f) => f.hunks)); + let hunk_promises = currentSeries.patches.flatMap(async (p) => { + let files = await listCommitFiles(project.id, p.id); + return files.flatMap((f) => + f.hunks.map((h) => { + return { filePath: f.path, diff: h.diff }; + }) + ); + }); + let hunks = (await Promise.all(hunk_promises)).flat(); const prompt = promptService.selectedBranchPrompt(project.id); const messageResult = await aiService.summarizeBranch({