🌟 Enhance commit script with AI summarization and add new script metadata

This commit is contained in:
2026-04-06 23:20:47 +08:00
parent a5be4f19de
commit f9af7981a2
4 changed files with 74 additions and 43 deletions

36
libraries/deno-ai-mod.ts Normal file
View File

@@ -0,0 +1,36 @@
import {
execCommand,
fetchDataWithTimeout,
getSecretValue,
term,
} from "https://script.hatter.ink/@67/deno-commons-mod.ts";
export async function summarizeGitStatusDiff(): Promise<string> {
const gitStatus = (await execCommand("git", ["status"]))
.assertSuccess().getStdoutAsStringThenTrim();
const gitDiff = (await execCommand("git", ["diff"]))
.assertSuccess().getStdoutAsStringThenTrim();
const response = await fetchDataWithTimeout(
"https://hatter.ink/ai/commit-summarize.json",
{
method: "POST",
headers: {
"Authorization": "Bearer " +
await getSecretValue("ai-commit-summarize-token"),
},
body: new URLSearchParams({
"gitStatus": gitStatus,
"gitDiff": gitDiff,
}),
},
);
if (response.status != 200) {
console.log(
term.yellow(
`Summarize commit message failed, status: ${response.status}`,
),
);
return null;
}
return (await response.json())["data"]["summary"];
}