🌟 Enhance commit script with AI summarization and add new script metadata
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user