Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make basePath configurable #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "auto-commit-gpt",
"displayName": "Auto Commit with GPT",
"description": "Generate commit messages using ChatGPT",
"version": "2.1.1",
"version": "2.1.2",
"homepage": "https://github.com/sohanemon/AutoCommit#readme",
"bugs": "https://github.com/sohanemon/AutoCommit/issues",
"repository": {
Expand Down Expand Up @@ -57,6 +57,11 @@
"default": "",
"description": "Needed for generating AI commit messages"
},
"autocommit.openAI.apiUrl": {
"type": "string",
"default": "https://api.openai.com",
"description": "Required for generating AI commit messages. Should start with \"https://\""
},
"autocommit.appearance.delimeter": {
"type": "string",
"default": "*",
Expand Down Expand Up @@ -90,4 +95,4 @@
"execa": "^7.1.1",
"openai": "^3.2.1"
}
}
}
3 changes: 2 additions & 1 deletion src/autocommit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { assertGitRepo, getStagedDiff, stageAllChanges } from './utils/git';
import { generateCommitMessage } from './utils/openai';
import { runTaskWithTimeout } from './utils/timer';

async function generateAICommitMessage(apiKey: string, delimeter?: string) {
async function generateAICommitMessage(apiKey: string,apiUrl: string, delimeter?: string) {
try {
const assertResult = await assertGitRepo();

Expand Down Expand Up @@ -56,6 +56,7 @@ async function generateAICommitMessage(apiKey: string, delimeter?: string) {

const commitMessage = await generateCommitMessage(
apiKey,
apiUrl,
staged.diff,
delimeter
);
Expand Down
2 changes: 2 additions & 0 deletions src/autocommit/utils/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { trimNewLines } from './text';

export const generateCommitMessage = async (
apiKey: string,
apiUrl: string,
diff: string,
delimeter?: string
) => {
Expand All @@ -19,6 +20,7 @@ export const generateCommitMessage = async (
const openAI = new OpenAIApi(
new Configuration({
apiKey: apiKey,
basePath: `${apiUrl}/v1`.replace(/\/+$/, ""),
})
);

Expand Down
33 changes: 32 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ async function setOpenAiApiKey(apiKey: string) {
);
}

function getOpenAiApiUrl() {
const configuration = vscode.workspace.getConfiguration('autocommit');
const apiUrl = configuration.get<string>('openAI.apiUrl');
return apiUrl;
}

async function setOpenAiApiUrl(apiUrl: string) {
const configuration = vscode.workspace.getConfiguration('autocommit');
await configuration.update(
'openAI.apiUrl',
apiUrl,
vscode.ConfigurationTarget.Global
);
}

function getDelimeter() {
const configuration = vscode.workspace.getConfiguration('autocommit');
const delimeter = configuration.get<string>('appearance.delimeter');
Expand Down Expand Up @@ -70,9 +85,25 @@ async function generateAICommitCommand() {

await setOpenAiApiKey(apiKey);
}
let apiUrl = getOpenAiApiUrl();

if (!apiUrl || !apiUrl.startsWith('https://')) {
apiUrl = await vscode.window.showInputBox({
title: 'Please enter your OpenAi Url starting with https://',
});

if (!apiUrl || apiUrl.trim() === '') {
vscode.window.showErrorMessage(
'You should set OpenAi API Url before extension using!'
);
return;
}

await setOpenAiApiUrl(apiUrl);
}

const delimeter = getDelimeter();
const commitMessage = await generateAICommitMessage(apiKey, delimeter);
const commitMessage = await generateAICommitMessage(apiKey, apiUrl, delimeter);

if (!commitMessage) {
return;
Expand Down