Skip to content

Commit

Permalink
refactor and optimize git operations for commit messages and failure …
Browse files Browse the repository at this point in the history
…analysis (#7412)
  • Loading branch information
pelikhan authored Oct 4, 2024
1 parent 2ae4ac8 commit 24d7b05
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gitignore.genai
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/genaiscript.d.ts
**/package-lock.json
**/yarn.lock
17 changes: 17 additions & 0 deletions genaisrc/gai.genai.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
script({
tools: ["agent_fs", "agent_git", "agent_github"],
})

const {
workflow = "latest failed",
failure_run_id = "latest",
branch = await git.defaultBranch(),
} = env.vars

$`Investigate the status of the ${workflow} workflow and identify the root cause of the failure of run ${failure_run_id} in branch ${branch}.
- Correlate the failure with the relevant commits, pull requests or issues.
- Compare the source code between the failed run commit and the last successful run commit before that run.
In your report, include html links to the relevant runs, commits, pull requests or issues.
`
30 changes: 9 additions & 21 deletions genaisrc/gcm.genai.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@ script({
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
let diff = await host.exec(diffCmd)
if (!diff.stdout) {
/**
* Ask user to stage all changes if none are staged
*/
const stage = await host.confirm("No staged changes. Stage all changes?", {
default: true,
})
if (stage) {
// Stage all changes and recompute diff
await host.exec("git add .")
diff = await host.exec(diffCmd)
}
if (!diff.stdout) cancel("no staged changes")
}
const diff = await git.diff({
staged: true,
excludedPaths: "**/genaiscript.d.ts",
askStageOnEmpty: true,
})
if (!diff) cancel("no staged changes")

// show diff in the console
console.log(diff.stdout)
console.log(diff)

let choice
let message
Expand Down Expand Up @@ -79,9 +67,9 @@ Please generate a concise, one-line commit message for these changes.
}
// Regenerate message
if (choice === "commit" && message) {
console.log((await host.exec("git", ["commit", "-m", message])).stdout)
console.log(await git.exec(["commit", "-m", message]))
if (await host.confirm("Push changes?", { default: true }))
console.log((await host.exec("git push")).stdout)
console.log(await git.exec("push"))
break
}
} while (choice !== "commit")
Loading

0 comments on commit 24d7b05

Please sign in to comment.