🌟 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

View File

@@ -2,15 +2,8 @@
import {createInterface} from "node:readline/promises";
import {stdin, stdout} from "node:process";
import {
execCommand,
execCommandShell,
fetchDataWithTimeout,
getSecretValue,
log,
ProcessBar,
term,
} from "https://script.hatter.ink/@61/deno-commons-mod.ts";
import {execCommandShell, log, ProcessBar, term,} from "https://script.hatter.ink/@61/deno-commons-mod.ts";
import {summarizeGitStatusDiff} from "https://script.hatter.ink/@0/deno-ai-mod.ts";
import {getGitLocalRev, getGitRemoteRev, getGitStatus,} from "https://script.hatter.ink/@2/deno-git-mod.ts";
async function checkRev(): Promise<boolean> {
@@ -27,36 +20,6 @@ async function checkRev(): Promise<boolean> {
}
}
async function summarize(): 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"];
}
async function main() {
await checkRev(); // check local rev <--> remote rev equals
const gitStatus = await getGitStatus();
@@ -68,7 +31,7 @@ async function main() {
const summary = await new ProcessBar("AI summarizing").call(
async (): Promise<string> => {
return await summarize();
return await summarizeGitStatusDiff();
},
);
if (summary != null) {

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env runts -- --allow-all
import {log, ProcessBar,} from "https://script.hatter.ink/@67/deno-commons-mod.ts";
import {summarizeGitStatusDiff} from "https://script.hatter.ink/@0/deno-ai-mod.ts";
async function main() {
const summary = await new ProcessBar("AI summarizing").call(
async (): Promise<string> => {
return await summarizeGitStatusDiff();
},
);
if (summary != null) {
log.success(`AI summarized git commit message: ${summary}`);
}
}
main().catch((err) => {
log.error(err);
process.exit(0);
}).then(() => process.exit(0));
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260406T231949+08:00.MEYCIQCvhjoBTNBaFA6ElSS8
// m6XruooQW8iNLQSRt0HObj3t/wIhAJLotqm8Ccdbb0MZTOvbhdQlD1+qS2wx9yrRd9lhi7Op