3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-12 04:03:39 +00:00

Add .gitattributes for genaiscript and update git commit flow script. (#7396)

This commit is contained in:
Peli de Halleux 2024-09-23 09:47:34 -07:00 committed by GitHub
parent ec14ef765e
commit c34c8477f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 74 additions and 47 deletions

1
genaisrc/.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
genaiscript.d.ts -diff merge=ours linguist-generated

View file

@ -1,73 +1,78 @@
// https://microsoft.github.io/genaiscript/guides/auto-git-commit-message/ /**
import { select, input, confirm } from "@inquirer/prompts" * git commit flow with auto-generated commit message
*/
script({
title: "git commit message",
description: "Generate a commit message for all staged changes",
})
// TODO: update this diff command to match your workspace
const diffCmd = "git diff --cached -- . :!**/genaiscript.d.ts"
// Check for staged changes and stage all changes if none are staged // Check for staged changes and stage all changes if none are staged
let diff = await host.exec("git", ["diff", "--cached"]) let diff = await host.exec(diffCmd)
if (!diff.stdout) { if (!diff.stdout) {
const stage = await confirm({ /**
message: "No staged changes. Stage all changes?", * Ask user to stage all changes if none are staged
*/
const stage = await host.confirm("No staged changes. Stage all changes?", {
default: true, default: true,
}) })
if (stage) { if (stage) {
await host.exec("git", ["add", "."]) // Stage all changes and recompute diff
diff = await host.exec("git", [ await host.exec("git add .")
"diff", diff = await host.exec(diffCmd)
"--cached",
"--",
".",
":!**/genaiscript.d.ts",
])
} }
if (!diff.stdout) cancel("no staged changes") if (!diff.stdout) cancel("no staged changes")
} }
// show diff in the console
console.log(diff.stdout) console.log(diff.stdout)
let choice let choice
let message let message
do { do {
// Generate commit message // Generate commit message
message = ( const res = await runPrompt(
await runPrompt( (_) => {
(_) => { _.def("GIT_DIFF", diff, { maxTokens: 20000 })
_.def("GIT_DIFF", diff, { maxTokens: 20000 }) _.$`GIT_DIFF is a diff of all staged changes, coming from the command:
_.$`GIT_DIFF is a diff of all staged changes, coming from the command:
\`\`\` \`\`\`
git diff --cached git diff --cached
\`\`\` \`\`\`
Please generate a concise, one-line commit message for these changes. Please generate a concise, one-line commit message for these changes.
- do NOT add quotes` - do NOT add quotes
}, ` // TODO: add a better prompt
{ cache: false, temperature: 0.8 } },
) { cache: false, temperature: 0.8 }
).text )
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 for commit message // Prompt user for commit message
choice = await select({ choice = await host.select(message, [
message, {
choices: [ value: "commit",
{ description: "accept message and commit",
name: "commit", },
value: "commit", {
description: "accept message and commit", value: "edit",
}, description: "edit message and commit",
{ },
name: "edit", {
value: "edit", value: "regenerate",
description: "edit message and commit", description: "regenerate message",
}, },
{ ])
name: "regenerate",
value: "regenerate",
description: "regenerate message",
},
],
})
// Handle user choice // Handle user choice
if (choice === "edit") { if (choice === "edit") {
message = await input({ message = await host.input("Edit commit message", {
message: "Edit commit message",
required: true, required: true,
}) })
choice = "commit" choice = "commit"
@ -75,8 +80,8 @@ Please generate a concise, one-line commit message for these changes.
// Regenerate message // Regenerate message
if (choice === "commit" && message) { if (choice === "commit" && message) {
console.log((await host.exec("git", ["commit", "-m", message])).stdout) console.log((await host.exec("git", ["commit", "-m", message])).stdout)
if (await confirm({ message: "Push changes?", default: true })) if (await host.confirm("Push changes?", { default: true }))
console.log((await host.exec("git", ["push"])).stdout) console.log((await host.exec("git push")).stdout)
break break
} }
} while (choice !== "commit") } while (choice !== "commit")

BIN
genaisrc/genaiscript.d.ts generated vendored Normal file

Binary file not shown.

21
genaisrc/tsconfig.json Normal file
View file

@ -0,0 +1,21 @@
{
"compilerOptions": {
"lib": [
"ES2022"
],
"target": "ES2023",
"module": "NodeNext",
"moduleDetection": "force",
"moduleResolution": "nodenext",
"checkJs": true,
"allowJs": true,
"skipLibCheck": true,
"noEmit": true,
"allowImportingTsExtensions": true
},
"include": [
"*.mjs",
"*.mts",
"./genaiscript.d.ts"
]
}