Skip to content

Commit 24d7b05

Browse files
authored
refactor and optimize git operations for commit messages and failure analysis (#7412)
1 parent 2ae4ac8 commit 24d7b05

File tree

4 files changed

+264
-33
lines changed

4 files changed

+264
-33
lines changed

.gitignore.genai

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/genaiscript.d.ts
2+
**/package-lock.json
3+
**/yarn.lock

genaisrc/gai.genai.mts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
script({
2+
tools: ["agent_fs", "agent_git", "agent_github"],
3+
})
4+
5+
const {
6+
workflow = "latest failed",
7+
failure_run_id = "latest",
8+
branch = await git.defaultBranch(),
9+
} = env.vars
10+
11+
$`Investigate the status of the ${workflow} workflow and identify the root cause of the failure of run ${failure_run_id} in branch ${branch}.
12+
13+
- Correlate the failure with the relevant commits, pull requests or issues.
14+
- Compare the source code between the failed run commit and the last successful run commit before that run.
15+
16+
In your report, include html links to the relevant runs, commits, pull requests or issues.
17+
`

genaisrc/gcm.genai.mts

+9-21
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,16 @@ script({
66
description: "Generate a commit message for all staged changes",
77
})
88

9-
// TODO: update this diff command to match your workspace
10-
const diffCmd = "git diff --cached -- . :!**/genaiscript.d.ts"
11-
129
// Check for staged changes and stage all changes if none are staged
13-
let diff = await host.exec(diffCmd)
14-
if (!diff.stdout) {
15-
/**
16-
* Ask user to stage all changes if none are staged
17-
*/
18-
const stage = await host.confirm("No staged changes. Stage all changes?", {
19-
default: true,
20-
})
21-
if (stage) {
22-
// Stage all changes and recompute diff
23-
await host.exec("git add .")
24-
diff = await host.exec(diffCmd)
25-
}
26-
if (!diff.stdout) cancel("no staged changes")
27-
}
10+
const diff = await git.diff({
11+
staged: true,
12+
excludedPaths: "**/genaiscript.d.ts",
13+
askStageOnEmpty: true,
14+
})
15+
if (!diff) cancel("no staged changes")
2816

2917
// show diff in the console
30-
console.log(diff.stdout)
18+
console.log(diff)
3119

3220
let choice
3321
let message
@@ -79,9 +67,9 @@ Please generate a concise, one-line commit message for these changes.
7967
}
8068
// Regenerate message
8169
if (choice === "commit" && message) {
82-
console.log((await host.exec("git", ["commit", "-m", message])).stdout)
70+
console.log(await git.exec(["commit", "-m", message]))
8371
if (await host.confirm("Push changes?", { default: true }))
84-
console.log((await host.exec("git push")).stdout)
72+
console.log(await git.exec("push"))
8573
break
8674
}
8775
} while (choice !== "commit")

0 commit comments

Comments
 (0)