Skip to content

Commit 3f756ed

Browse files
committed
Uses a new AI prompt for generating Pull Request details
(vscode-gitlens-private#43, #4177)
1 parent d211702 commit 3f756ed

File tree

7 files changed

+77
-6
lines changed

7 files changed

+77
-6
lines changed

src/commands/createPullRequestOnRemote.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,15 @@ export class CreatePullRequestOnRemoteCommand extends GlCommandBase {
8484
}
8585
const baseRef = `${base.remote.name}/${base.branch}`;
8686
const compareRef = `${compare.remote.name}/${compare.branch}`;
87-
const result = await this.container.ai.generatePullRequestMessage(repo, baseRef, compareRef, {
88-
source: 'home', // TODO provide the real source
89-
});
90-
return result?.parsed;
87+
try {
88+
const result = await this.container.ai.generatePullRequestMessage(repo, baseRef, compareRef, {
89+
source: 'scm-input',
90+
});
91+
return result?.parsed;
92+
} catch (e) {
93+
void window.showErrorMessage(`Unable to generate pull request message: ${e}`);
94+
return undefined;
95+
}
9196
},
9297
};
9398

src/plus/ai/aiProviderService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,14 +543,14 @@ export class AIProviderService implements Disposable {
543543
}
544544

545545
const result = await this.sendRequest(
546-
'generate-commitMessage',
546+
'generate-pullRequestMessage',
547547
() => ({
548548
diff: diff?.contents ?? '',
549549
data: commits.sort((a, b) => a[1] - b[1]).map(c => c[0]),
550550
context: options?.context ?? '',
551551
instructions: configuration.get('ai.generateCommitMessage.customInstructions') ?? '',
552552
}),
553-
m => `Generating commit message with ${m.name}...`,
553+
m => `Generating pull request details with ${m.name}...`,
554554
source,
555555
m => ({
556556
key: 'ai/generate',

src/plus/ai/models/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface AIModelDescriptor<Provider extends AIProviders = AIProviders, M
2626

2727
export type AIActionType =
2828
| 'generate-commitMessage'
29+
| 'generate-pullRequestMessage'
2930
| 'generate-stashMessage'
3031
| 'generate-changelog'
3132
| `generate-create-${'cloudPatch' | 'codeSuggestion' | 'pullRequest'}`

src/plus/ai/models/promptTemplates.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface PromptTemplate {
99

1010
export type PromptTemplateContext<T extends AIActionType> = T extends
1111
| 'generate-commitMessage'
12+
| 'generate-pullRequestMessage'
1213
| 'generate-stashMessage'
1314
| 'generate-create-cloudPatch'
1415
| 'generate-create-codeSuggestion'

src/plus/ai/prompts.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,61 @@ Fixes #789
4949
5050
Based on the provided code diff and any additional context, create a concise but meaningful commit message following the instructions above.`;
5151

52+
export const generatePullRequestMessageUserPrompt = `You are an advanced AI programming assistant and are tasked with summarizing code changes into a concise but meaningful pull request title and description. You will be provided with a code diff and a list of commits. Your goal is to analyze the changes and create a clear, informative title and description that accurately represents the modifications made to the code.
53+
First, examine the following code changes provided in Git diff format:
54+
<~~diff~~>
55+
\${diff}
56+
</~~diff~~>
57+
58+
Then, review the list of commits to help understand the motivation behind the changes and any relevant background information:
59+
<~~data~~>
60+
\${data}
61+
</~~data~~>
62+
63+
Now, if provided, use this context to understand the motivation behind the changes and any relevant background information:
64+
<~~additional-context~~>
65+
\${context}
66+
</~~additional-context~~>
67+
68+
To create an effective pull request title and description, follow these steps:
69+
70+
1. Carefully analyze the diff, commit messages, context, focusing on:
71+
- The purpose and rationale of the changes
72+
- Any problems addressed or benefits introduced
73+
- Any significant logic changes or algorithmic improvements
74+
2. Ensure the following when composing the pull request title and description:
75+
- Emphasize the 'why' of the change, its benefits, or the problem it addresses
76+
- Use an informal yet professional tone
77+
- Use a future-oriented manner, third-person singular present tense (e.g., 'Fixes', 'Updates', 'Improves', 'Adds', 'Removes')
78+
- Be clear and concise
79+
- Synthesize only meaningful information from the diff and context
80+
- Avoid outputting code, specific code identifiers, names, or file names unless crucial for understanding
81+
- Avoid repeating information, broad generalities, and unnecessary phrases like "this", "this commit", or "this change"
82+
3. Summarize the main purpose of the changes in a single, concise sentence, which will be the title of your pull request message
83+
- Start with a third-person singular present tense verb
84+
- Limit to 50 characters if possible
85+
4. If necessary, provide a brief explanation of the changes, which will be the body of your pull request message
86+
- Add line breaks for readability and to separate independent ideas
87+
- Focus on the "why" rather than the "what" of the changes.
88+
- Structure the body with markdown bullets and headings for clarity
89+
5. If the changes are related to a specific issue or ticket, include the reference (e.g., "Fixes #123" or "Relates to JIRA-456") at the end of the pull request message.
90+
91+
Write your title inside <summary> tags and your description inside <body> tags and include no other text:
92+
93+
<summary>
94+
Implements user authentication feature
95+
</summary>
96+
<body>
97+
Adds login and registration endpoints:
98+
- Updates user model to include password hashing
99+
- Integrates JWT for secure token generation
100+
101+
Fixes #789
102+
</body>
103+
\${instructions}
104+
105+
Based on the provided code diff, commit list, and any additional context, create a concise but meaningful pull request title and body following the instructions above.`;
106+
52107
export const generateStashMessageUserPrompt = `You are an advanced AI programming assistant and are tasked with creating a concise but descriptive stash message. You will be provided with a code diff of uncommitted changes. Your goal is to analyze the changes and create a clear, single-line stash message that accurately represents the work in progress being stashed.
53108
54109
First, examine the following code changes provided in Git diff format:

src/plus/ai/utils/-webview/ai.utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export function getActionName(action: AIActionType): string {
2525
switch (action) {
2626
case 'generate-commitMessage':
2727
return 'Generate Commit Message';
28+
case 'generate-pullRequestMessage':
29+
return 'Generate Pull Request Details';
2830
case 'generate-stashMessage':
2931
return 'Generate Stash Message';
3032
case 'generate-changelog':

src/plus/ai/utils/-webview/prompt.utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
generateCloudPatchMessageUserPrompt,
99
generateCodeSuggestMessageUserPrompt,
1010
generateCommitMessageUserPrompt,
11+
generatePullRequestMessageUserPrompt,
1112
generateStashMessageUserPrompt,
1213
} from '../../prompts';
1314

@@ -19,6 +20,12 @@ export function getLocalPromptTemplate<T extends AIActionType>(action: T, _model
1920
template: generateCommitMessageUserPrompt,
2021
variables: ['diff', 'context', 'instructions'],
2122
};
23+
case 'generate-pullRequestMessage':
24+
return {
25+
name: 'Generate Pull Request Details',
26+
template: generatePullRequestMessageUserPrompt,
27+
variables: ['diff', 'data', 'context', 'instructions'],
28+
};
2229
case 'generate-stashMessage':
2330
return {
2431
name: 'Generate Stash Message',

0 commit comments

Comments
 (0)