Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Oct 18, 2024
1 parent f31b7e3 commit 084bb1b
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 3 deletions.
1 change: 1 addition & 0 deletions genaisrc/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
genaiscript.d.ts -diff merge=ours linguist-generated
4 changes: 4 additions & 0 deletions genaisrc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# auto-generated
genaiscript.d.ts
tsconfig.json
jsconfig.json
87 changes: 87 additions & 0 deletions genaisrc/gcm.genai.mjs
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")
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"package:vscode": "cd vscode && yarn package",
"processvideos": "node scripts/processvideos.mjs",
"bumprelease": "node scripts/bump.mjs --cloud",
"changelog": "auto-changelog -o ./vscode/CHANGELOG.md --hide-credit --hide-empty-releases --ignore-commit-pattern \"(skip ci|bump bytecode|bump to)\""
"changelog": "auto-changelog -o ./vscode/CHANGELOG.md --hide-credit --hide-empty-releases --ignore-commit-pattern \"(skip ci|bump bytecode|bump to)\"",
"genai": "npx --yes genaiscript run",
"gcm": "npx --yes genaiscript run gcm"
},
"workspaces": [
"interop",
Expand Down
13 changes: 11 additions & 2 deletions website/docs/getting-started/vscode/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ import StaticVideo from "@site/src/components/StaticVideo"

The [Visual Studio Code](https://code.visualstudio.com/) extension provides the best developer experience for DeviceScript.

- **install the [DeviceScript extension](https://marketplace.visualstudio.com/items?itemName=devicescript.devicescript-vscode)**
- **find the latest release at [https://github.com/microsoft/devicescript/releases](https://github.com/microsoft/devicescript/releases?expanded=true)**
- download `devicescript.vsix` from **Assets**
- install the .vsix file in code

:::tip

The DeviceScript extension is not available from the Marketplace anymore.

:::


You will also need

Expand All @@ -27,7 +36,7 @@ You will also need
- Device, services, register [Explorer view](./vscode/user-interface)
- Register and Event watch

### (Optional) Manual installation from the GitHub releases
### Manual installation from the GitHub releases

- **find the latest release at [https://github.com/microsoft/devicescript/releases](https://github.com/microsoft/devicescript/releases?expanded=true)**
- download `devicescript.vsix` from **Assets**
Expand Down

0 comments on commit 084bb1b

Please sign in to comment.