-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
106 additions
and
3 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 @@ | ||
genaiscript.d.ts -diff merge=ours linguist-generated |
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,4 @@ | ||
# auto-generated | ||
genaiscript.d.ts | ||
tsconfig.json | ||
jsconfig.json |
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,87 @@ | ||
/** | ||
* Script to automate the git commit process with AI-generated commit messages. | ||
* It checks for staged changes, generates a commit message, and prompts the user to review or edit the message before committing. | ||
*/ | ||
|
||
script({ | ||
title: "git commit message", | ||
description: "Generate a commit message for all staged changes", | ||
}) | ||
|
||
// Check for staged changes and stage all changes if none are staged | ||
const diff = await git.diff({ | ||
staged: true, | ||
askStageOnEmpty: true, | ||
}) | ||
|
||
// If no staged changes are found, cancel the script with a message | ||
if (!diff) cancel("no staged changes") | ||
|
||
// Display the diff of staged changes in the console | ||
console.log(diff) | ||
|
||
let choice | ||
let message | ||
do { | ||
// Generate a conventional commit message based on the staged changes diff | ||
const res = await runPrompt( | ||
(_) => { | ||
_.def("GIT_DIFF", diff, { maxTokens: 10000, language: "diff" }) | ||
_.$`Generate a git conventional commit message that summarizes the changes in GIT_DIFF. | ||
- GIT_DIFF is generated by "git diff" | ||
- do NOT use markdown syntax | ||
- do NOT add quotes or code blocks | ||
- keep it short, 1 line only, maximum 50 characters | ||
- use emojis | ||
- do NOT confuse delete lines starting with '-' and add lines starting with '+' | ||
` | ||
}, | ||
{ | ||
model: "large", // Specifies the LLM model to use for message generation | ||
label: "generate commit message", // Label for the prompt task | ||
system: [ | ||
"system.safety_jailbreak", | ||
"system.safety_harmful_content", | ||
"system.safety_ungrounded_content_summarization", | ||
], | ||
} | ||
) | ||
if (res.error) throw res.error | ||
|
||
message = res.text | ||
if (!message) { | ||
console.log("No message generated, did you configure the LLM model?") | ||
break | ||
} | ||
|
||
// Prompt user to accept, edit, or regenerate the commit message | ||
choice = await host.select(message, [ | ||
{ | ||
value: "commit", | ||
description: "accept message and commit", | ||
}, | ||
{ | ||
value: "edit", | ||
description: "edit message and commit", | ||
}, | ||
{ | ||
value: "regenerate", | ||
description: "regenerate message", | ||
}, | ||
]) | ||
|
||
// Handle user's choice for commit message | ||
if (choice === "edit") { | ||
message = await host.input("Edit commit message", { | ||
required: true, | ||
}) | ||
choice = "commit" | ||
} | ||
// If user chooses to commit, execute the git commit and optionally push changes | ||
if (choice === "commit" && message) { | ||
console.log(await git.exec(["commit", "-m", message])) | ||
if (await host.confirm("Push changes?", { default: true })) | ||
console.log(await git.exec("push")) | ||
break | ||
} | ||
} while (choice !== "commit") |
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
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