Skip to content

Commit

Permalink
Added support for rc files and cli arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Redknife committed Sep 26, 2022
1 parent b26278d commit 6458089
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
OPENAI_API_KEY=
GIT_AI_COMMIT_CONFIG_NAME=.git-ai-commit-config.js
9 changes: 3 additions & 6 deletions autocommit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
require('dotenv').config();
const {Configuration, OpenAIApi} = require("openai");
const {execSync, spawn} = require("child_process");
const rc = require('rc');

const os = require('os');
const fs = require('fs');

const configFilename = process.env.GIT_AI_COMMIT_CONFIG_NAME || '.git-ai-commit-config.js';
const configPath = os.homedir() + '/' + configFilename;
const defaultConfig = require('./config.js');

// if (!fs.existsSync(configPath)) {
// TODO: param to create default config file
Expand All @@ -18,7 +15,7 @@ const configPath = os.homedir() + '/' + configFilename;
// console.log(`Created default config file at ${configPath}`);
// }

const config = !fs.existsSync(configPath) ? require('./config.js') : require(configPath);
const config = rc('git-aicommit', defaultConfig);

try {
execSync(
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"license": "MIT",
"dependencies": {
"dotenv": "^16.0.2",
"openai": "^3.0.0"
"openai": "^3.0.0",
"rc": "1.2.8"
},
"preferGlobal": true,
"bin": {
Expand Down
30 changes: 30 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ combined-stream@^1.0.8:
dependencies:
delayed-stream "~1.0.0"

deep-extend@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac"
integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==

delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
Expand All @@ -45,6 +50,11 @@ form-data@^4.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

ini@~1.3.0:
version "1.3.8"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==

[email protected]:
version "1.52.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
Expand All @@ -57,10 +67,30 @@ mime-types@^2.1.12:
dependencies:
mime-db "1.52.0"

minimist@^1.2.0:
version "1.2.6"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==

openai@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/openai/-/openai-3.0.0.tgz#0816f1d72ee37820c9ff14d93d597431489fec37"
integrity sha512-YNAPZKzBfE6MnR5Ro/z3uKbg7T3F3W1FoTCtYheKRdEjZeheMX49QYFeL990gBFAhuGziEZCUdhnNT+eIrxX/Q==
dependencies:
axios "^0.26.0"
form-data "^4.0.0"

[email protected]:
version "1.2.8"
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed"
integrity sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==
dependencies:
deep-extend "^0.6.0"
ini "~1.3.0"
minimist "^1.2.0"
strip-json-comments "~2.0.1"

strip-json-comments@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
integrity sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==

0 comments on commit 6458089

Please sign in to comment.