Skip to content

Instantly share code, notes, and snippets.

@rexwhitten
Created February 1, 2024 20:30
Show Gist options
  • Save rexwhitten/b22510e9ca0b2c048a62412963ee8569 to your computer and use it in GitHub Desktop.
Save rexwhitten/b22510e9ca0b2c048a62412963ee8569 to your computer and use it in GitHub Desktop.
Git Commit Message Creator
#! /usr/bin/env node
import OpenAI from "openai";
import { exec } from 'child_process';
exec('git status', async (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
if (stderr) {
console.log(`git status stderr: ${stderr}`);
}
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
const chatCompletion = await openai.chat.completions.create({
messages: [{ role: "user", content: `Based on the following pending git changes, please create a verbose, well structured, and intelligent conventional commit message: ${stdout}` }],
model: "gpt-3.5-turbo",
});
console.log(chatCompletion.choices[0].message.content);
});
@rexwhitten
Copy link
Author

rexwhitten commented Feb 1, 2024

Use ChatGPT to create a conventional commit message based on the output of git status

To Use

  • Put your OpenAI key in an environment variable called OPENAI_API_KEY
  • run npm install -g .
  • run gptcli in a directory containing a git repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment