🌟 Enhance commit script with AI summarization and add new script metadata
This commit is contained in:
36
libraries/deno-ai-mod.ts
Normal file
36
libraries/deno-ai-mod.ts
Normal 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"];
|
||||||
|
}
|
||||||
@@ -63,12 +63,12 @@
|
|||||||
},
|
},
|
||||||
"commit.ts": {
|
"commit.ts": {
|
||||||
"script_name": "commit.ts",
|
"script_name": "commit.ts",
|
||||||
"script_length": 4194,
|
"script_length": 3222,
|
||||||
"script_sha256": "2436bfbe5aae9e3a2c881959e3855eaee986142d547ccf04a5741e9c20d0addd",
|
"script_sha256": "81cc7d465fdf97591e1f1ff71a8a454fa538a308a929efe968736c2e12ae0c62",
|
||||||
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/commit.ts",
|
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/commit.ts",
|
||||||
"single_script_file": true,
|
"single_script_file": true,
|
||||||
"publish_time": 1769318306585,
|
"publish_time": 1769318306585,
|
||||||
"update_time": 1775315385172
|
"update_time": 1775488837666
|
||||||
},
|
},
|
||||||
"decode-uri-component.ts": {
|
"decode-uri-component.ts": {
|
||||||
"script_name": "decode-uri-component.ts",
|
"script_name": "decode-uri-component.ts",
|
||||||
@@ -124,6 +124,15 @@
|
|||||||
"publish_time": 1775239056991,
|
"publish_time": 1775239056991,
|
||||||
"update_time": 1775487544902
|
"update_time": 1775487544902
|
||||||
},
|
},
|
||||||
|
"git-ai-summarize.ts": {
|
||||||
|
"script_name": "git-ai-summarize.ts",
|
||||||
|
"script_length": 766,
|
||||||
|
"script_sha256": "7eab10eade8daa55c5f831114a1998bd8dc9a4c9d44bc5bd0f13e786b19d34da",
|
||||||
|
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/git-ai-summarize.ts",
|
||||||
|
"single_script_file": true,
|
||||||
|
"publish_time": 1775488837668,
|
||||||
|
"update_time": 1775488837668
|
||||||
|
},
|
||||||
"git-check.ts": {
|
"git-check.ts": {
|
||||||
"script_name": "git-check.ts",
|
"script_name": "git-check.ts",
|
||||||
"script_length": 3107,
|
"script_length": 3107,
|
||||||
|
|||||||
@@ -2,15 +2,8 @@
|
|||||||
|
|
||||||
import {createInterface} from "node:readline/promises";
|
import {createInterface} from "node:readline/promises";
|
||||||
import {stdin, stdout} from "node:process";
|
import {stdin, stdout} from "node:process";
|
||||||
import {
|
import {execCommandShell, log, ProcessBar, term,} from "https://script.hatter.ink/@61/deno-commons-mod.ts";
|
||||||
execCommand,
|
import {summarizeGitStatusDiff} from "https://script.hatter.ink/@0/deno-ai-mod.ts";
|
||||||
execCommandShell,
|
|
||||||
fetchDataWithTimeout,
|
|
||||||
getSecretValue,
|
|
||||||
log,
|
|
||||||
ProcessBar,
|
|
||||||
term,
|
|
||||||
} from "https://script.hatter.ink/@61/deno-commons-mod.ts";
|
|
||||||
import {getGitLocalRev, getGitRemoteRev, getGitStatus,} from "https://script.hatter.ink/@2/deno-git-mod.ts";
|
import {getGitLocalRev, getGitRemoteRev, getGitStatus,} from "https://script.hatter.ink/@2/deno-git-mod.ts";
|
||||||
|
|
||||||
async function checkRev(): Promise<boolean> {
|
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() {
|
async function main() {
|
||||||
await checkRev(); // check local rev <--> remote rev equals
|
await checkRev(); // check local rev <--> remote rev equals
|
||||||
const gitStatus = await getGitStatus();
|
const gitStatus = await getGitStatus();
|
||||||
@@ -68,7 +31,7 @@ async function main() {
|
|||||||
|
|
||||||
const summary = await new ProcessBar("AI summarizing").call(
|
const summary = await new ProcessBar("AI summarizing").call(
|
||||||
async (): Promise<string> => {
|
async (): Promise<string> => {
|
||||||
return await summarize();
|
return await summarizeGitStatusDiff();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (summary != null) {
|
if (summary != null) {
|
||||||
|
|||||||
23
single-scripts/git-ai-summarize.ts
Executable file
23
single-scripts/git-ai-summarize.ts
Executable 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
|
||||||
Reference in New Issue
Block a user