Created
February 1, 2024 20:30
-
-
Save rexwhitten/b22510e9ca0b2c048a62412963ee8569 to your computer and use it in GitHub Desktop.
Git Commit Message Creator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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); | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use ChatGPT to create a conventional commit message based on the output of
git statusTo Use
OPENAI_API_KEYnpm install -g .gptcliin a directory containing a git repository.