Skip to content

Commit

Permalink
Adds source to Generate Commit Message command
Browse files Browse the repository at this point in the history
  • Loading branch information
axosoft-ramint committed Dec 18, 2024
1 parent f080b61 commit a66c356
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/commands/generateCommitMessage.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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 };

Expand All @@ -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...' },
Expand Down
1 change: 1 addition & 0 deletions src/plus/webviews/graph/graphWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3667,6 +3667,7 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph

return executeCommand<GenerateCommitMessageCommandArgs>(GlCommand.GenerateCommitMessage, {
repoPath: ref.repoPath,
source: 'graph',
});
}

Expand Down

0 comments on commit a66c356

Please sign in to comment.