-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added commit message automation script using GenAI in the project's h…
…usky hook configuration
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node packages/cli/built/genaiscript.cjs run commit-msg $1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const msg = env.files[0] | ||
const msgContent = msg.content | ||
?.split(/\n/g) | ||
.filter((l) => l && !/^# /.test(l)) | ||
.join("\n") | ||
if (!msgContent) cancel("commit message already exists") | ||
|
||
// Check for staged changes and stage all changes if none are staged | ||
let diff = await host.exec("git", ["diff", "--cached"]) | ||
if (!diff.stdout) cancel("no staged changes") | ||
// Generate commit message | ||
const res = await runPrompt( | ||
(_) => { | ||
_.def("GIT_DIFF", diff, { maxTokens: 20000 }) | ||
_.$`GIT_DIFF is a diff of all staged changes, coming from the command: | ||
\`\`\` | ||
git diff --cached | ||
\`\`\` | ||
Please generate a concise, one-line commit message for these changes. | ||
- do NOT add quotes` | ||
}, | ||
{ cache: false, temperature: 0.8 } | ||
) | ||
|
||
if (res.error) throw res.error | ||
const message = res.text | ||
if (!message) cancel("no message generated") | ||
await workspace.writeText(msg.filename, message) |