Fixes a bug with generating branch names

This commit is contained in:
Kiril Videlov 2024-11-06 00:28:35 +01:00
parent 7fe5d0c85e
commit 40cffe091b
2 changed files with 17 additions and 3 deletions

View File

@ -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);

View File

@ -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({