Add git branch and log info to prompt
This commit is contained in:
@@ -69,10 +69,15 @@ class GenerateCommitMessageService extends Disposable implements IGenerateCommit
|
||||
const requestId = this.setRequestId()
|
||||
try {
|
||||
const { path, repo } = this.gitRepoInfo()
|
||||
const [stat, sampledDiffs] = await Promise.all([this.voidSCM.gitStat(path), this.voidSCM.gitSampledDiffs(path)])
|
||||
const [stat, sampledDiffs, branch, log] = await Promise.all([
|
||||
this.voidSCM.gitStat(path),
|
||||
this.voidSCM.gitSampledDiffs(path),
|
||||
this.voidSCM.gitBranch(path),
|
||||
this.voidSCM.gitLog(path)
|
||||
])
|
||||
this.checkIsCurrentRequest(requestId)
|
||||
const modelOptions = this.prepareModelOptions()
|
||||
const prompt = this.preparePrompt(stat, sampledDiffs)
|
||||
const prompt = this.preparePrompt(stat, sampledDiffs, branch, log)
|
||||
const { messages, separateSystemMessage } = this.prepareMessages(prompt, modelOptions)
|
||||
const commitMessage = await this.sendLLMMessage(messages, separateSystemMessage!, modelOptions)
|
||||
this.checkIsCurrentRequest(requestId)
|
||||
@@ -151,20 +156,29 @@ class GenerateCommitMessageService extends Disposable implements IGenerateCommit
|
||||
}
|
||||
}
|
||||
|
||||
private preparePrompt(stat: string, sampledDiffs: string) {
|
||||
private preparePrompt(stat: string, sampledDiffs: string, branch: string, log: string) {
|
||||
const section1 = `Section 1 - Summary of Changes (git diff --stat):`
|
||||
const section2 = `Section 2 - Sampled File Diffs (Top changed files):`
|
||||
const section3 = `Section 3 - Current Git Branch:`
|
||||
const section4 = `Section 4 - Last 5 Commits (excluding merges):`
|
||||
return `
|
||||
Based on the following Git changes, write a clear, concise commit message that accurately summarizes the intent of the code changes.
|
||||
Based on the following Git changes, write a clear, concise commit message that accurately summarizes the intent of the code changes.
|
||||
|
||||
${section1}
|
||||
${section1}
|
||||
|
||||
${stat}
|
||||
${stat}
|
||||
|
||||
${section2}
|
||||
${section2}
|
||||
|
||||
${sampledDiffs}
|
||||
`.trim()
|
||||
${sampledDiffs}
|
||||
|
||||
${section3}
|
||||
|
||||
${branch}
|
||||
|
||||
${section4}
|
||||
|
||||
${log}`.trim()
|
||||
}
|
||||
|
||||
private prepareMessages(prompt: string, modelOptions: ModelOptions) {
|
||||
|
||||
@@ -14,6 +14,18 @@ export interface IVoidSCM {
|
||||
* @param path Path to the git repository
|
||||
*/
|
||||
gitSampledDiffs(path: string): Promise<string>
|
||||
/**
|
||||
* Get the current git branch
|
||||
*
|
||||
* @param path Path to the git repository
|
||||
*/
|
||||
gitBranch(path: string): Promise<string>
|
||||
/**
|
||||
* Get the last 5 commits excluding merges
|
||||
*
|
||||
* @param path Path to the git repository
|
||||
*/
|
||||
gitLog(path: string): Promise<string>
|
||||
}
|
||||
|
||||
export const IVoidSCM = createDecorator<IVoidSCM>('voidSCMService')
|
||||
|
||||
@@ -53,6 +53,14 @@ export class VoidSCM implements IVoidSCM {
|
||||
const diffs = await Promise.all(topFiles.map(async ({ file }) => ({ file, diff: await getSampledDiff(file, path) })))
|
||||
return diffs.map(({ file, diff }) => `==== ${file} ====\n${diff}`).join('\n\n')
|
||||
}
|
||||
|
||||
gitBranch(path: string): Promise<string> {
|
||||
return git('git branch --show-current', path)
|
||||
}
|
||||
|
||||
gitLog(path: string): Promise<string> {
|
||||
return git('git log --pretty=format:"%h|%s|%ad" --date=short --no-merges -n 5', path)
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IVoidSCM, VoidSCM, InstantiationType.Delayed)
|
||||
|
||||
Reference in New Issue
Block a user