-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
53 lines (45 loc) · 1.18 KB
/
Copy pathindex.ts
File metadata and controls
53 lines (45 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/env node
import { execSync } from "child_process";
import clipboard from "clipboardy";
const CONVENTIONAL_REQUEST = `following conventional commit (<type>: <subject>)`;
try {
execSync("git rev-parse --is-inside-work-tree 2>/dev/null");
} catch (e) {
console.log("This is not a git repository.");
process.exit(1);
}
let diff = "";
try {
diff = execSync("git diff --cached").toString();
if (!diff) {
console.log("No changes to commit.");
process.exit(0);
}
} catch (e) {
console.log("There was an error while getting the diff.", String(e));
process.exit(1);
}
async function main(diff: string) {
const command =
`Suggest me a few good commit messages for my commit ${CONVENTIONAL_REQUEST}.\n` +
"```\n" +
diff +
"\n" +
"```\n\n" +
`Output results as a list, not more than 6 items.`;
clipboard.writeSync(command);
console.log(
"Request copied to clipboard. Open https://chat.openai.com/chat and paste it there."
);
}
main(diff)
.then(() => {
process.exit(0);
})
.catch((e) => {
console.log("Error: " + e.message);
if ((e as any).details) {
console.log((e as any).details);
}
process.exit(1);
});