Skip to content

Commit c0ef4cd

Browse files
authored
fix: allow conventional commit for pr title gen (#1666)
## Problem Pull request descriptions generated by the AI assistant don't follow project-specific commit conventions, making them inconsistent with team standards and potentially causing issues with automated tooling that expects conventional commit formats. ## Changes - Added `getCommitConventions()` call to retrieve project-specific commit convention settings - Integrated conventional commit format hints into the AI prompt when conventional commits are enabled - Updated the system prompt to include guidance on using conventional commit prefixes (feat, fix, docs, chore, etc.) - Added `conventionalCommits` flag to telemetry tracking for monitoring adoption The AI will now generate PR titles that follow conventional commit format when the project has this convention enabled, improving consistency across the codebase.
1 parent ddd2484 commit c0ef4cd

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

apps/code/src/main/services/git/service.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,12 +1254,14 @@ ${truncatedDiff}${contextSection}`;
12541254
]);
12551255

12561256
const head = currentBranch ?? undefined;
1257-
const [branchDiff, stagedDiff, unstagedDiff, commits] = await Promise.all([
1258-
getDiffAgainstRemote(directoryPath, defaultBranch),
1259-
getStagedDiff(directoryPath),
1260-
getUnstagedDiff(directoryPath),
1261-
getCommitsBetweenBranches(directoryPath, defaultBranch, head, 30),
1262-
]);
1257+
const [branchDiff, stagedDiff, unstagedDiff, commits, conventions] =
1258+
await Promise.all([
1259+
getDiffAgainstRemote(directoryPath, defaultBranch),
1260+
getStagedDiff(directoryPath),
1261+
getUnstagedDiff(directoryPath),
1262+
getCommitsBetweenBranches(directoryPath, defaultBranch, head, 30),
1263+
getCommitConventions(directoryPath),
1264+
]);
12631265

12641266
const uncommittedDiff = [stagedDiff, unstagedDiff]
12651267
.filter(Boolean)
@@ -1283,6 +1285,12 @@ ${truncatedDiff}${contextSection}`;
12831285
)}`
12841286
: "";
12851287

1288+
const conventionHint = conventions.conventionalCommits
1289+
? `- Use conventional commit format for the title (e.g., "feat(scope): description"). Common prefixes: ${
1290+
conventions.commonPrefixes.join(", ") || "feat, fix, docs, chore"
1291+
}.`
1292+
: "";
1293+
12861294
const system = `You are a PR description generator. Generate a title and detailed description for a pull request.
12871295
12881296
Output format (use exactly this format):
@@ -1295,6 +1303,7 @@ Rules for the title:
12951303
- Short and descriptive (max 72 chars)
12961304
- Use imperative mood ("Add feature" not "Added feature")
12971305
- Be specific about what the PR accomplishes
1306+
${conventionHint}
12981307
12991308
Rules for the body:
13001309
- Start with a TL;DR section (1-2 sentences summarizing the change)
@@ -1326,6 +1335,7 @@ ${truncatedDiff || "(no diff available)"}${contextSection}`;
13261335
diffLength: fullDiff.length,
13271336
hasTemplate: !!prTemplate.template,
13281337
hasConversationContext: !!conversationContext,
1338+
conventionalCommits: conventions.conventionalCommits,
13291339
});
13301340

13311341
const response = await this.llmGateway.prompt(

0 commit comments

Comments
 (0)