Skip to content

Commit 52fd4b1

Browse files
authored
Merge pull request #5458 from gitbutlerapp/kv-branch-1
Fixes a bug preventing generating branch names
2 parents 7fe5d0c + 149445c commit 52fd4b1

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

apps/desktop/src/lib/ai/service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ interface SummarizeCommitOpts extends BaseAIServiceOpts {
6262
}
6363

6464
interface SummarizeBranchOpts extends BaseAIServiceOpts {
65-
hunks: Hunk[];
65+
hunks: DiffInput[];
6666
branchTemplate?: Prompt;
6767
}
6868

@@ -75,8 +75,13 @@ interface SummarizePROpts extends BaseAIServiceOpts {
7575
prBodyTemplate?: string;
7676
}
7777

78+
interface DiffInput {
79+
filePath: string;
80+
diff: string;
81+
}
82+
7883
// Exported for testing only
79-
export function buildDiff(hunks: Hunk[], limit: number) {
84+
export function buildDiff(hunks: DiffInput[], limit: number) {
8085
return shuffle(hunks.map((h) => `${h.filePath} - ${h.diff}`))
8186
.join('\n')
8287
.slice(0, limit);

apps/desktop/src/lib/branch/SeriesHeader.svelte

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import { isFailure } from '$lib/result';
2424
import { openExternalUrl } from '$lib/utils/url';
2525
import { BranchController } from '$lib/vbranches/branchController';
26+
import { listCommitFiles } from '$lib/vbranches/remoteCommits';
2627
import { PatchSeries, VirtualBranch, type CommitStatus } from '$lib/vbranches/types';
2728
import { CloudBranchesService } from '@gitbutler/shared/cloud/stacks/service';
2829
import { getContext, getContextStore } from '@gitbutler/shared/context';
@@ -140,7 +141,15 @@
140141
async function generateBranchName() {
141142
if (!aiGenEnabled || !currentSeries) return;
142143
143-
const hunks = currentSeries.patches.flatMap((p) => p.files.flatMap((f) => f.hunks));
144+
let hunk_promises = currentSeries.patches.flatMap(async (p) => {
145+
let files = await listCommitFiles(project.id, p.id);
146+
return files.flatMap((f) =>
147+
f.hunks.map((h) => {
148+
return { filePath: f.path, diff: h.diff };
149+
})
150+
);
151+
});
152+
let hunks = (await Promise.all(hunk_promises)).flat();
144153
145154
const prompt = promptService.selectedBranchPrompt(project.id);
146155
const messageResult = await aiService.summarizeBranch({

apps/desktop/src/lib/vbranches/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ export class DetailedCommit {
204204
createdAt!: Date;
205205
isRemote!: boolean;
206206
isIntegrated!: boolean;
207-
@Type(() => LocalFile)
208-
files!: LocalFile[];
209207
parentIds!: string[];
210208
branchId!: string;
211209
changeId!: string;

0 commit comments

Comments
 (0)