Comparing version
@@ -15,2 +15,3 @@ #!/usr/bin/env node | ||
}; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -22,9 +23,9 @@ exports.main = void 0; | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
let OPENAI_API_KEY = process.env.OPENAI_API_KEY; | ||
let OPENAI_KEY = (_a = process.env.OPENAI_KEY) !== null && _a !== void 0 ? _a : process.env.OPENAI_API_KEY; | ||
function main() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
console.log(chalk_1.default.white("▲ ") + chalk_1.default.green("Welcome to AICommits!")); | ||
if (!OPENAI_API_KEY) { | ||
if (!OPENAI_KEY) { | ||
console.error(chalk_1.default.white("▲ ") + | ||
"Please save your OpenAI API key as an env variable by doing 'export OPENAI_API_KEY=YOUR_API_KEY'"); | ||
"Please save your OpenAI API key as an env variable by doing 'export OPENAI_KEY=YOUR_API_KEY'"); | ||
process.exit(1); | ||
@@ -57,20 +58,27 @@ } | ||
console.log(chalk_1.default.white("▲ ") + chalk_1.default.gray("Generating your AI commit message...\n")); | ||
const aiCommitMessage = yield generateCommitMessage(prompt); | ||
console.log(chalk_1.default.white("▲ ") + chalk_1.default.bold("Commit message: ") + aiCommitMessage + "\n"); | ||
const confirmationMessage = yield inquirer_1.default.prompt([ | ||
{ | ||
name: "useCommitMessage", | ||
message: "Would you like to use this commit message? (Y / n)", | ||
choices: ["Y", "y", "n"], | ||
default: "y", | ||
}, | ||
]); | ||
if (confirmationMessage.useCommitMessage === "n") { | ||
console.log(chalk_1.default.white("▲ ") + "Commit message has not been commited."); | ||
try { | ||
const aiCommitMessage = yield generateCommitMessage(prompt); | ||
console.log(chalk_1.default.white("▲ ") + chalk_1.default.bold("Commit message: ") + aiCommitMessage + | ||
"\n"); | ||
const confirmationMessage = yield inquirer_1.default.prompt([ | ||
{ | ||
name: "useCommitMessage", | ||
message: "Would you like to use this commit message? (Y / n)", | ||
choices: ["Y", "y", "n"], | ||
default: "y", | ||
}, | ||
]); | ||
if (confirmationMessage.useCommitMessage === "n") { | ||
console.log(chalk_1.default.white("▲ ") + "Commit message has not been commited."); | ||
process.exit(1); | ||
} | ||
(0, child_process_1.execSync)(`git commit -m "${aiCommitMessage}"`, { | ||
stdio: "inherit", | ||
encoding: "utf8", | ||
}); | ||
} | ||
catch (e) { | ||
console.error(chalk_1.default.white("▲ ") + chalk_1.default.red(e.message)); | ||
process.exit(1); | ||
} | ||
(0, child_process_1.execSync)(`git commit -m "${aiCommitMessage}"`, { | ||
stdio: "inherit", | ||
encoding: "utf8", | ||
}); | ||
}); | ||
@@ -80,2 +88,3 @@ } | ||
function generateCommitMessage(prompt) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -96,3 +105,3 @@ const payload = { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${OPENAI_API_KEY !== null && OPENAI_API_KEY !== void 0 ? OPENAI_API_KEY : ""}`, | ||
Authorization: `Bearer ${OPENAI_KEY !== null && OPENAI_KEY !== void 0 ? OPENAI_KEY : ""}`, | ||
}, | ||
@@ -102,2 +111,6 @@ method: "POST", | ||
}); | ||
if (response.status !== 200) { | ||
const errorJson = yield response.json(); | ||
throw new Error(`OpenAI API failed while processing the request '${(_a = errorJson === null || errorJson === void 0 ? void 0 : errorJson.error) === null || _a === void 0 ? void 0 : _a.message}'`); | ||
} | ||
const json = yield response.json(); | ||
@@ -104,0 +117,0 @@ const aiCommit = json.choices[0].text; |
{ | ||
"name": "aicommits", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Writes your git commit messages for you with AI", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -20,3 +20,3 @@ <div align="center"> | ||
1. `npm install -g aicommits` | ||
2. `export OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxx` | ||
2. `export OPENAI_KEY=sk-xxxxxxxxxxxxxxxx` | ||
@@ -49,4 +49,6 @@ It's recommended to add the line in #2 to your `.zshrc` or `.bashrc` so it persists instead of having to define it in each terminal session. | ||
- Add ability to specify a commit message from inside aicommit | ||
- Use gpt-3-tokenizer | ||
- Add automated github releases | ||
- Add opt-in emoji flag | ||
- Add opt-in languages flag | ||
- Build landing page for the 2.0 launch |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
10451
20.11%5
25%130
11.11%53
3.92%3
50%