Skip to content

Commit f942147

Browse files
committed
refactor(api.ts, config.ts, prepare-commit-msg-hook.ts): change OPENAI_API_KEY to OPENCOMMIT_OPENAI_API_KEY
This change is done in order to avoid reading possible generic variables from the user environment without his consent
1 parent 1a195dc commit f942147

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ All the commits in this repo are done with OpenCommit — look into [the commits
3131
3. Set the key to opencommit config:
3232

3333
```sh
34-
opencommit config set OPENAI_API_KEY=<your_api_key>
34+
opencommit config set OPENCOMMIT_OPENAI_API_KEY=<your_api_key>
3535
```
3636

3737
Your api key is stored locally in `~/.opencommit` config file.

src/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import { CONFIG_MODES, getConfig } from './commands/config';
1111

1212
const config = getConfig();
1313

14-
let apiKey = config?.OPENAI_API_KEY;
14+
let apiKey = config?.OPENCOMMIT_OPENAI_API_KEY;
1515

1616
const [command, mode] = process.argv.slice(2);
1717

1818
if (!apiKey && command !== 'config' && mode !== CONFIG_MODES.set) {
1919
intro('opencommit');
2020

2121
outro(
22-
'OPENAI_API_KEY is not set, please run `oc config set OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`'
22+
'OPENCOMMIT_OPENAI_API_KEY is not set, please run `oc config set OPENCOMMIT_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`'
2323
);
2424
outro(
2525
'For help look into README https://github.com/di-sukharev/opencommit#setup'

src/commands/config.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import { intro, outro } from '@clack/prompts';
77
import chalk from 'chalk';
88
import { COMMANDS } from '../CommandsEnum';
99

10+
import * as dotenv from 'dotenv'
11+
dotenv.config()
12+
1013
export enum CONFIG_KEYS {
11-
OPENAI_API_KEY = 'OPENAI_API_KEY',
14+
OPENCOMMIT_OPENAI_API_KEY = 'OPENCOMMIT_OPENAI_API_KEY',
1215
OPENCOMMIT_DESCRIPTION = 'OPENCOMMIT_DESCRIPTION',
1316
OPENCOMMIT_EMOJI = 'OPENCOMMIT_EMOJI'
1417
}
@@ -32,15 +35,15 @@ const validateConfig = (
3235
};
3336

3437
export const configValidators = {
35-
[CONFIG_KEYS.OPENAI_API_KEY](value: any) {
36-
validateConfig(CONFIG_KEYS.OPENAI_API_KEY, value, 'Cannot be empty');
38+
[CONFIG_KEYS.OPENCOMMIT_OPENAI_API_KEY](value: any) {
39+
validateConfig(CONFIG_KEYS.OPENCOMMIT_OPENAI_API_KEY, value, 'Cannot be empty');
3740
validateConfig(
38-
CONFIG_KEYS.OPENAI_API_KEY,
41+
CONFIG_KEYS.OPENCOMMIT_OPENAI_API_KEY,
3942
value.startsWith('sk-'),
4043
'Must start with "sk-"'
4144
);
4245
validateConfig(
43-
CONFIG_KEYS.OPENAI_API_KEY,
46+
CONFIG_KEYS.OPENCOMMIT_OPENAI_API_KEY,
4447
value.length === 51,
4548
'Must be 51 characters long'
4649
);

src/commands/prepare-commit-msg-hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const prepareCommitMessageHook = async () => {
2525

2626
const config = getConfig();
2727

28-
if (!config?.OPENAI_API_KEY) {
28+
if (!config?.OPENCOMMIT_OPENAI_API_KEY) {
2929
throw new Error(
3030
'No OPEN_AI_API exists. Set your OPEN_AI_API=<key> in ~/.opencommit'
3131
);

0 commit comments

Comments
 (0)