🌟 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"];
|
||||
}
|
||||
Reference in New Issue
Block a user