Skip to content

Commit c5539fe

Browse files
committed
Hide API generation action when no configurations exist and read manual commit messages from clipboard
- should not show 'make api call' if there are no configurations - 'enter manually' should automatically prefill the input field with clipboard text - when comparing to strings use '==' or '!=', not '===' or '!==' └── apps └── editor └── src ├── commands │ └── generate-commit-message-commands │ ├── actions │ │ ├── get-prompt-data.ts │ │ └── run-generate-action.ts │ ├── generate-commit-message-commands.ts │ ├── index.ts │ └── utils │ ├── build-commit-message-prompt.ts │ ├── generate-commit-message-with-api.ts │ ├── get-commit-message-config.ts │ └── strip-wrapping-quotes.ts └── i18n └── translations └── commands └── generate-commit-message.ts
1 parent 88bf5ee commit c5539fe

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎apps/editor/src/commands/generate-commit-message-commands/actions/run-generate-action.ts‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { show_configuration_quick_pick } from '@/utils/show-configuration-quick-
2121
import { CHATBOTS } from '@shared/constants/chatbots'
2222
import { dictionary } from '@shared/constants/dictionary'
2323
import { WebSocketManager } from '@/services/websocket-manager'
24+
import { ModelProvidersManager } from '@/services/model-providers-manager'
2425

2526
const truncate_prompt = (text: string): string => {
2627
if (text.length <= MAX_PROMPT_CHARS_IN_COMMIT_MESSAGE) return text
@@ -85,13 +86,22 @@ export const run_generate_action = async (params: {
8586
'command.generate-commit-message.action.copy-prompt'
8687
)
8788

89+
const model_providers_manager = new ModelProvidersManager(
90+
params.extension_context
91+
)
92+
const api_configurations =
93+
await model_providers_manager.get_api_configurations()
94+
const has_api_configurations = api_configurations.length > 0
95+
8896
const action = await new Promise<string | undefined | 'back'>(
8997
(resolve) => {
9098
const quick_pick = vscode.window.createQuickPick<
9199
vscode.QuickPickItem & { id: string }
92100
>()
93101
quick_pick.items = [
94-
{ label: action_make_api, id: 'make-api' },
102+
...(has_api_configurations
103+
? [{ label: action_make_api, id: 'make-api' }]
104+
: []),
95105
...(params.websocket_manager.is_connected_with_browser()
96106
? [{ label: action_autofill_in_chatbot, id: 'autofill' }]
97107
: []),
@@ -162,7 +172,7 @@ export const run_generate_action = async (params: {
162172
}
163173
)
164174

165-
if (action === 'back') {
175+
if (action == 'back') {
166176
if (was_empty_stage) {
167177
if (!show_back_button) {
168178
await vscode.commands.executeCommand('git.unstageAll', repository)
@@ -188,7 +198,7 @@ export const run_generate_action = async (params: {
188198
action
189199
)
190200

191-
if (action === 'copy') {
201+
if (action == 'copy') {
192202
await vscode.env.clipboard.writeText(chatbot_prompt)
193203
vscode.window.showInformationMessage(
194204
t('command.generate-commit-message.copied', {
@@ -201,7 +211,7 @@ export const run_generate_action = async (params: {
201211
return
202212
}
203213

204-
if (action === 'autofill') {
214+
if (action == 'autofill') {
205215
if (!params.websocket_manager.is_connected_with_browser()) {
206216
vscode.window.showWarningMessage(
207217
dictionary.warning_message.BROWSER_EXTENSION_NOT_CONNECTED
@@ -267,7 +277,7 @@ export const run_generate_action = async (params: {
267277
show_back_button: true
268278
})
269279

270-
if (result === 'back') {
280+
if (result == 'back') {
271281
force_quick_pick = true
272282
continue
273283
} else if (!result) {
@@ -310,8 +320,8 @@ export const run_generate_action = async (params: {
310320
return
311321
}
312322

313-
if (action === 'manual') {
314-
commit_message = ''
323+
if (action == 'manual') {
324+
commit_message = await vscode.env.clipboard.readText()
315325
} else {
316326
const api_configuration_data =
317327
await get_commit_message_api_configuration(

‎apps/editor/src/commands/generate-commit-message-commands/utils/get-commit-message-config.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const get_commit_message_api_configuration = async (
7070
show_back_button
7171
})
7272

73-
if (result === 'back' || !result) {
73+
if (result == 'back' || !result) {
7474
commit_message_api_configuration = 'back'
7575
} else {
7676
extension_context.workspaceState.update(
@@ -82,7 +82,7 @@ export const get_commit_message_api_configuration = async (
8282
}
8383
}
8484

85-
if (commit_message_api_configuration === 'back') {
85+
if (commit_message_api_configuration == 'back') {
8686
return 'back'
8787
}
8888

0 commit comments

Comments
 (0)