From a66c356f8903a7be3565731a3697a11896d3df01 Mon Sep 17 00:00:00 2001 From: Ramin Tadayon Date: Wed, 18 Dec 2024 15:35:24 -0700 Subject: [PATCH] Adds source to Generate Commit Message command --- src/commands/generateCommitMessage.ts | 14 +++++++++++++- src/plus/webviews/graph/graphWebview.ts | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/commands/generateCommitMessage.ts b/src/commands/generateCommitMessage.ts index 51089a0b51c1c..88397144dcb75 100644 --- a/src/commands/generateCommitMessage.ts +++ b/src/commands/generateCommitMessage.ts @@ -1,16 +1,19 @@ import type { TextEditor, Uri } from 'vscode'; import { ProgressLocation, window } from 'vscode'; import { GlCommand } from '../constants.commands'; +import type { Sources } from '../constants.telemetry'; import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { showGenericErrorMessage } from '../messages'; import { getBestRepositoryOrShowPicker } from '../quickpicks/repositoryPicker'; import { Logger } from '../system/logger'; import { command, executeCoreCommand } from '../system/vscode/command'; +import type { CommandContext } from './base'; import { ActiveEditorCommand, getCommandUri } from './base'; export interface GenerateCommitMessageCommandArgs { repoPath?: string; + source?: Sources; } @command() @@ -19,6 +22,15 @@ export class GenerateCommitMessageCommand extends ActiveEditorCommand { super([GlCommand.GenerateCommitMessage, GlCommand.GenerateCommitMessageScm]); } + protected override preExecute(context: CommandContext, args?: GenerateCommitMessageCommandArgs) { + let source: Sources | undefined = args?.source; + if (source == null && context.command === GlCommand.GenerateCommitMessageScm) { + source = 'scm-input'; + } + + return this.execute(context.editor, context.uri, { ...args, source: source }); + } + async execute(editor?: TextEditor, uri?: Uri, args?: GenerateCommitMessageCommandArgs) { args = { ...args }; @@ -43,7 +55,7 @@ export class GenerateCommitMessageCommand extends ActiveEditorCommand { await this.container.ai )?.generateCommitMessage( repository, - { source: 'commandPalette' }, + { source: args?.source ?? 'commandPalette' }, { context: currentMessage, progress: { location: ProgressLocation.Notification, title: 'Generating commit message...' }, diff --git a/src/plus/webviews/graph/graphWebview.ts b/src/plus/webviews/graph/graphWebview.ts index 0f8176322a76d..9c256a1eaa029 100644 --- a/src/plus/webviews/graph/graphWebview.ts +++ b/src/plus/webviews/graph/graphWebview.ts @@ -3667,6 +3667,7 @@ export class GraphWebviewProvider implements WebviewProvider(GlCommand.GenerateCommitMessage, { repoPath: ref.repoPath, + source: 'graph', }); }