updates
This commit is contained in:
@@ -63,12 +63,12 @@
|
|||||||
},
|
},
|
||||||
"commit.ts": {
|
"commit.ts": {
|
||||||
"script_name": "commit.ts",
|
"script_name": "commit.ts",
|
||||||
"script_length": 2755,
|
"script_length": 4016,
|
||||||
"script_sha256": "ceb0915c81e38fdf02904a548ebf9cefe337bb7cf4d0a9510c95b83cd6d395fb",
|
"script_sha256": "db637841e28bdc0c9feb832d21371f0ef917c4f4a9e227060c69e7709aa6c9b7",
|
||||||
"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": 1770820023006
|
"update_time": 1775314689271
|
||||||
},
|
},
|
||||||
"decode-uri-component.ts": {
|
"decode-uri-component.ts": {
|
||||||
"script_name": "decode-uri-component.ts",
|
"script_name": "decode-uri-component.ts",
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
#!/usr/bin/env runts -- --allow-import --allow-run --allow-read
|
#!/usr/bin/env runts -- --allow-all
|
||||||
|
|
||||||
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 {execCommandShell, log, ProcessBar, term,} from "https://script.hatter.ink/@39/deno-commons-mod.ts";
|
import {
|
||||||
|
execCommand,
|
||||||
|
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> {
|
||||||
@@ -19,6 +27,36 @@ 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();
|
||||||
@@ -28,6 +66,9 @@ async function main() {
|
|||||||
}
|
}
|
||||||
log.info("Git status:", gitStatus);
|
log.info("Git status:", gitStatus);
|
||||||
|
|
||||||
|
const summary = await summarize();
|
||||||
|
log.success(`Git commit message: ${summary}`);
|
||||||
|
|
||||||
let emptyCount = 0;
|
let emptyCount = 0;
|
||||||
let message = "empty message";
|
let message = "empty message";
|
||||||
const readline = createInterface({ input: stdin, output: stdout });
|
const readline = createInterface({ input: stdin, output: stdout });
|
||||||
@@ -37,7 +78,12 @@ async function main() {
|
|||||||
console.log("Too many empty messages, then exit");
|
console.log("Too many empty messages, then exit");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
message = await readline.question("Input your commit message > ");
|
message = await readline.question(
|
||||||
|
"Input your commit message (Enter for AI summary) > ",
|
||||||
|
);
|
||||||
|
if (message.trim().length == 0) {
|
||||||
|
message = summary;
|
||||||
|
}
|
||||||
} while (message.length == 0);
|
} while (message.length == 0);
|
||||||
readline.close();
|
readline.close();
|
||||||
|
|
||||||
@@ -76,5 +122,5 @@ main().catch((err) => {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}).then(() => process.exit(0));
|
}).then(() => process.exit(0));
|
||||||
|
|
||||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260211T222644+08:00.MEUCIQDeEy/R3ZVM/5AY9eD8
|
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260404T225757+08:00.MEUCIQCp3myuHQTK17ZHS3zW
|
||||||
// m1nb8pL2i3GKiqHDs0YQom0muQIgSqAkWhL2jO4tLvm928X7wNRCEC9gpbcSw9/IxdPtoY4=
|
// Z7Wg/+Mgd0CasaV+FX34BHFB9gIgG8qRbLKxD1PD4jMrkGVucgT91xU1JLIwfVM6xwxh1Os=
|
||||||
|
|||||||
Reference in New Issue
Block a user