37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
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"];
|
|
}
|