From 13d49f8cf34e7fd8da860d4f762771067a57926d Mon Sep 17 00:00:00 2001 From: pwwang Date: Fri, 31 Mar 2023 16:36:27 -0700 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20Add=20command=20gptcommit.showP?= =?UTF-8?q?erFileSummary=20(gptcommit=200.5.x)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 14 +++++++++----- src/commands/createCommandConfigs.ts | 28 ++++++++++++++++++++++++++++ src/extension.ts | 8 +++++++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index e84f466..aa215e5 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,10 @@ { "command": "gptcommit.setOutputLanguage", "title": "GPTCommit: Set output language" + }, + { + "command": "gptcommit.showPerFileSummary", + "title": "GPTCommit: Show per-file summary" } ], "menus": { @@ -81,16 +85,16 @@ "enum": [ "title", "title + summary", - "title + breakdown", - "title + summary + breakdown" + "title + per-file", + "title + summary + per-file" ], "enumDescriptions": [ "Only the title", "Title and bullet-point summary", - "Title and breakdown of each changed file", - "Title, bullet-point summary and each changed file" + "Title and per-file summary", + "Title, bullet-point summary and per-file summary" ], - "description": "Content of the message to fill in the express mode." + "description": "Content of the message to fill in the express mode. Note that you need enable per-file summary for the per-file content (by GPTCommit: Show per-file summary)." }, "gptcommit.onFiles": { "type": "string", diff --git a/src/commands/createCommandConfigs.ts b/src/commands/createCommandConfigs.ts index fbd1826..f139845 100644 --- a/src/commands/createCommandConfigs.ts +++ b/src/commands/createCommandConfigs.ts @@ -6,6 +6,7 @@ export function setupOpenAIApiKey(context: vscode.ExtensionContext, channel: vsc vscode.window.showInputBox({ prompt: 'Enter your OpenAI API key', placeHolder: 'sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', + ignoreFocusOut: true, }).then((key) => { if (key) { saveConfig( @@ -28,6 +29,7 @@ export function useDifferentModel(context: vscode.ExtensionContext, channel: vsc vscode.window.showInputBox({ prompt: 'Enter the model you want to use', placeHolder: 'gpt-3.5-turbo', + ignoreFocusOut: true, }).then((model) => { if (model) { saveConfig( @@ -50,6 +52,7 @@ export function setOutputLanguage(context: vscode.ExtensionContext, channel: vsc vscode.window.showInputBox({ prompt: 'Enter the language of the generated commit message', placeHolder: 'en', + ignoreFocusOut: true, }).then((lang) => { if (lang) { saveConfig( @@ -66,3 +69,28 @@ export function setOutputLanguage(context: vscode.ExtensionContext, channel: vsc context.subscriptions.push(languageCommand); } + +export function showPerFileSummary(context: vscode.ExtensionContext, channel: vscode.OutputChannel) { + let showPerFileCommand = vscode.commands.registerCommand('gptcommit.showPerFileSummary', async (uri?: vscode.SourceControl) => { + vscode.window.showQuickPick( + ["Yes", "No"], + { + placeHolder: 'Enable "show per-file summary"?', + ignoreFocusOut: true, + } + ).then((show) => { + if (show === "Yes" || show === "No") { + saveConfig( + 'output.show_per_file_summary', + 'output.show_per_file_summary', + channel, + getRepo(uri), + show === "Yes" ? "true" : "false", + 'Configuration show per-file summary saved' + ); + } + }); + }); + + context.subscriptions.push(showPerFileCommand); +} diff --git a/src/extension.ts b/src/extension.ts index 6fb1412..43d335c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,7 +2,12 @@ // Import the module and reference it with the alias vscode in your code below import * as vscode from 'vscode'; import createCommandGenerateGitCommitMessage from './commands/createCommandGenerateGitCommitMessage'; -import { setupOpenAIApiKey, useDifferentModel, setOutputLanguage } from './commands/createCommandConfigs'; +import { + setupOpenAIApiKey, + useDifferentModel, + setOutputLanguage, + showPerFileSummary, +} from './commands/createCommandConfigs'; // This method is called when your extension is activated // Your extension is activated the very first time the command is executed @@ -22,6 +27,7 @@ export function activate(context: vscode.ExtensionContext) { setupOpenAIApiKey(context, channel); useDifferentModel(context, channel); setOutputLanguage(context, channel); + showPerFileSummary(context, channel); } // This method is called when your extension is deactivated From 20e2bac63e95a0e29aedbdac3345f34d8700ffc1 Mon Sep 17 00:00:00 2001 From: pwwang Date: Fri, 31 Mar 2023 16:42:26 -0700 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9C=A8=20Add=20command=20gptcommit.disab?= =?UTF-8?q?leConventionalCommit=20(gptcommit=200.5.x)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++++ src/commands/createCommandConfigs.ts | 33 +++++++++++++++++++++++----- src/extension.ts | 2 ++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index aa215e5..0b0d302 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,10 @@ { "command": "gptcommit.showPerFileSummary", "title": "GPTCommit: Show per-file summary" + }, + { + "command": "gptcommit.disableConventionalCommit", + "title": "GPTCommit: Disable conventional commit" } ], "menus": { diff --git a/src/commands/createCommandConfigs.ts b/src/commands/createCommandConfigs.ts index f139845..f2635f2 100644 --- a/src/commands/createCommandConfigs.ts +++ b/src/commands/createCommandConfigs.ts @@ -15,7 +15,7 @@ export function setupOpenAIApiKey(context: vscode.ExtensionContext, channel: vsc channel, getRepo(uri), key, - 'OpenAI API key saved' + 'Configuration openai.api_key saved' ); } }); @@ -38,7 +38,7 @@ export function useDifferentModel(context: vscode.ExtensionContext, channel: vsc channel, getRepo(uri), model, - 'Model saved' + 'Configuration openai.model saved' ); } }); @@ -61,7 +61,7 @@ export function setOutputLanguage(context: vscode.ExtensionContext, channel: vsc channel, getRepo(uri), lang, - 'Output language saved' + 'Configuration output.lang saved' ); } }); @@ -76,7 +76,6 @@ export function showPerFileSummary(context: vscode.ExtensionContext, channel: vs ["Yes", "No"], { placeHolder: 'Enable "show per-file summary"?', - ignoreFocusOut: true, } ).then((show) => { if (show === "Yes" || show === "No") { @@ -86,7 +85,7 @@ export function showPerFileSummary(context: vscode.ExtensionContext, channel: vs channel, getRepo(uri), show === "Yes" ? "true" : "false", - 'Configuration show per-file summary saved' + 'Configuration output.show_per_file_summary saved' ); } }); @@ -94,3 +93,27 @@ export function showPerFileSummary(context: vscode.ExtensionContext, channel: vs context.subscriptions.push(showPerFileCommand); } + +export function disableConventionalCommit(context: vscode.ExtensionContext, channel: vscode.OutputChannel) { + let disableConvCommitCommand = vscode.commands.registerCommand('gptcommit.disableConventionalCommit', async (uri?: vscode.SourceControl) => { + vscode.window.showQuickPick( + ["Yes", "No"], + { + placeHolder: 'Disable conventional commit?', + } + ).then((show) => { + if (show === "Yes" || show === "No") { + saveConfig( + 'output.conventional_commit', + 'output.conventional_commit', + channel, + getRepo(uri), + show === "Yes" ? "false" : "true", + 'Configuration output.conventional_commit saved' + ); + } + }); + }); + + context.subscriptions.push(disableConvCommitCommand); +} diff --git a/src/extension.ts b/src/extension.ts index 43d335c..0404a27 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,6 +7,7 @@ import { useDifferentModel, setOutputLanguage, showPerFileSummary, + disableConventionalCommit, } from './commands/createCommandConfigs'; // This method is called when your extension is activated @@ -28,6 +29,7 @@ export function activate(context: vscode.ExtensionContext) { useDifferentModel(context, channel); setOutputLanguage(context, channel); showPerFileSummary(context, channel); + disableConventionalCommit(context, channel); } // This method is called when your extension is deactivated From d65095296b663361375422b64cb9e8b111b511ff Mon Sep 17 00:00:00 2001 From: pwwang Date: Fri, 31 Mar 2023 20:46:04 -0700 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=A8=20Add=20gptcommit.openConfigFile?= =?UTF-8?q?=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++++ src/commands/createCommandConfigs.ts | 19 +++++++++++++++++++ .../createCommandGenerateGitCommitMessage.ts | 4 ++-- src/extension.ts | 2 ++ src/utils.ts | 1 + 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0b0d302..caa0dbf 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,10 @@ { "command": "gptcommit.disableConventionalCommit", "title": "GPTCommit: Disable conventional commit" + }, + { + "command": "gptcommit.openConfigFile", + "title": "GPTCommit: Open gptcommit configuration file" } ], "menus": { diff --git a/src/commands/createCommandConfigs.ts b/src/commands/createCommandConfigs.ts index f2635f2..ff5bba7 100644 --- a/src/commands/createCommandConfigs.ts +++ b/src/commands/createCommandConfigs.ts @@ -1,4 +1,5 @@ import * as vscode from 'vscode'; +import * as path from 'path'; import { getRepo, saveConfig } from '../utils'; export function setupOpenAIApiKey(context: vscode.ExtensionContext, channel: vscode.OutputChannel) { @@ -117,3 +118,21 @@ export function disableConventionalCommit(context: vscode.ExtensionContext, chan context.subscriptions.push(disableConvCommitCommand); } + +export function openConfigFile(context: vscode.ExtensionContext, channel: vscode.OutputChannel) { + let openConfigFileCommand = vscode.commands.registerCommand('gptcommit.openConfigFile', async (uri?: vscode.SourceControl) => { + const repo = getRepo(uri); + if (!repo) { + return; + } + channel.appendLine(`Opening ${path.join(repo.rootUri.fsPath, ".git", "gptcommit.toml")}`); + const editor = vscode.window.activeTextEditor; + const doc = await vscode.workspace.openTextDocument(path.join(repo.rootUri.fsPath, ".git", "gptcommit.toml")); + await vscode.window.showTextDocument(doc, { + preview: false, + viewColumn: editor ? editor.viewColumn : undefined, + }); + }); + + context.subscriptions.push(openConfigFileCommand); +} diff --git a/src/commands/createCommandGenerateGitCommitMessage.ts b/src/commands/createCommandGenerateGitCommitMessage.ts index 7c0c802..3c64369 100644 --- a/src/commands/createCommandGenerateGitCommitMessage.ts +++ b/src/commands/createCommandGenerateGitCommitMessage.ts @@ -17,14 +17,14 @@ export default (context: vscode.ExtensionContext, channel: vscode.OutputChannel) if (repo) { repo.inputBox.value = message; } - vscode.commands.executeCommand('setContext', 'gptcommit.generating', false); }).catch((err) => { - vscode.commands.executeCommand('setContext', 'gptcommit.generating', false); vscode.window.showErrorMessage(err, "Show Output").then((choice) => { if (choice === "Show Output") { channel.show(); } }); + }).finally(() => { + vscode.commands.executeCommand('setContext', 'gptcommit.generating', false); }); } ); diff --git a/src/extension.ts b/src/extension.ts index 0404a27..b48e1f1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -8,6 +8,7 @@ import { setOutputLanguage, showPerFileSummary, disableConventionalCommit, + openConfigFile, } from './commands/createCommandConfigs'; // This method is called when your extension is activated @@ -30,6 +31,7 @@ export function activate(context: vscode.ExtensionContext) { setOutputLanguage(context, channel); showPerFileSummary(context, channel); disableConventionalCommit(context, channel); + openConfigFile(context, channel); } // This method is called when your extension is deactivated diff --git a/src/utils.ts b/src/utils.ts index b38d820..1f087d0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -118,6 +118,7 @@ export async function getCommitMessage( viewColumn: editor ? editor.viewColumn : undefined, }); progress.report({ increment: 100 }); + vscode.commands.executeCommand('setContext', 'gptcommit.generating', false); }); let disposable = vscode.workspace.onDidSaveTextDocument(async (doc) => { From 8e3da84622869d0ba52e3bfd999d2b32f5c4d7c0 Mon Sep 17 00:00:00 2001 From: pwwang Date: Fri, 31 Mar 2023 20:55:29 -0700 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=94=96=200.3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 ++++++++++++- package.json | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2f66555..f752b01 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Note: Do NOT install `gptcommit` hook via `gptcommit install` under the root of | < 0.1.0 | 1.75+ | 0.1.16 | | 0.1.x | 1.70+ | 0.1.16 | | 0.2.x | 1.70+ | 0.3.0 | +| 0.3.x | 1.70+ | 0.5.x | ## Commands @@ -35,10 +36,20 @@ Run via `Ctrl+Shift+P` or `Cmd+Shift+P`: - `GPTCommit: Set output language` Set the output language. Default is `en`. +- `GPTCommit: Show per-file summary` + Enable "show per-file summary"? It's disabled by default. + +- `GPTCommit: Disable conventional commit` + Disable "conventional commit"? It's enabled by default. + +- `GPTCommit: Open gptcommit configuration file` + Open the local gptcommit configuration file (~/.git/gptcommit.toml) + ## Extension Settings - `ExpressMode`: If true, generated message will be filled into the Source Control commit message input box directly, instead of opening a new editor. - `ExpressModeContent`: Content of the message to fill in the express mode. + - Note that to show per-file summary, you need to enable "show per-file summary" by running the `GPTCommit: Show per-file summary` command. - `GptcommitPath`: Path to the `gptcommit` executable. - `OnFiles`: Diff of files to use for generating the commit message. - `staged`: Use staged files @@ -47,7 +58,7 @@ Run via `Ctrl+Shift+P` or `Cmd+Shift+P`: ## Advanced configuration -Note that now all the configuration via the extension is saved in the `.git/gptcommit.toml` file. If you have to change advanced configuration, you can edit the `.git/gptcommit.toml` file directly, but make sure you know what you are doing. +Note that now all the configuration via the extension is saved in the `.git/gptcommit.toml` file. If you have to change advanced configuration, you can edit the `.git/gptcommit.toml` file directly, but make sure you know what you are doing. You can also use the `GPTCommit: Open gptcommit configuration file` command to open the configuration file. If you want to use the configuration globally, you can copy the `.git/gptcommit.toml` file to `~/.config/gptcommit/config.toml`, or just the sections of the configuration you want to be used globally. diff --git a/package.json b/package.json index caa0dbf..148ad48 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "gptcommit", "displayName": "vscode-gptcommit", "description": "Automated git commit messages using GPT models", - "version": "0.2.2", + "version": "0.3.0", "repository": { "url": "https://github.com/pwwang/vscode-gptcommit" },