@dev-angsu/cli 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +12 -1
- package/package.json +1 -1
- package/src/utils/engine.js +14 -12
package/bin/index.js
CHANGED
|
@@ -10,13 +10,15 @@ import chalk from "chalk";
|
|
|
10
10
|
import ora from "ora";
|
|
11
11
|
import fs from "fs";
|
|
12
12
|
|
|
13
|
+
import { run as review } from "../src/utils/engine.js";
|
|
14
|
+
|
|
13
15
|
const program = new Command();
|
|
14
16
|
|
|
15
17
|
// 1. Metadata
|
|
16
18
|
program
|
|
17
19
|
.name("cli")
|
|
18
20
|
.description("A CLI to demonstrate industry")
|
|
19
|
-
.version("1.0.
|
|
21
|
+
.version("1.0.1");
|
|
20
22
|
|
|
21
23
|
// 2. Define a Command
|
|
22
24
|
program
|
|
@@ -73,5 +75,14 @@ program
|
|
|
73
75
|
}
|
|
74
76
|
});
|
|
75
77
|
|
|
78
|
+
// 3. Review Command
|
|
79
|
+
program
|
|
80
|
+
.command("review")
|
|
81
|
+
.alias("r")
|
|
82
|
+
.description("Review staged changes using AI")
|
|
83
|
+
.action(async () => {
|
|
84
|
+
await review();
|
|
85
|
+
});
|
|
86
|
+
|
|
76
87
|
// 6. Parse Arguments
|
|
77
88
|
program.parse(process.argv);
|
package/package.json
CHANGED
package/src/utils/engine.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { simpleGit } from "simple-git";
|
|
4
4
|
import OpenAI from "openai";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
5
6
|
import "dotenv/config"; // Loads .env file automatically
|
|
6
7
|
|
|
7
8
|
import * as core from "@actions/core";
|
|
@@ -9,16 +10,6 @@ import * as github from "@actions/github";
|
|
|
9
10
|
|
|
10
11
|
const git = simpleGit();
|
|
11
12
|
|
|
12
|
-
if (!process.env.OPENAI_API_KEY) {
|
|
13
|
-
console.error("❌ Error: OPENAI_API_KEY is missing in .env file.");
|
|
14
|
-
process.exit(1);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const openai = new OpenAI({
|
|
18
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
19
|
-
baseURL: process.env.AI_BASE_URL || "https://api.z.ai/api/paas/v4/",
|
|
20
|
-
});
|
|
21
|
-
|
|
22
13
|
// async function getStagedDiff() {
|
|
23
14
|
// const diff = await git.diff(["--staged"]);
|
|
24
15
|
// return diff;
|
|
@@ -70,6 +61,15 @@ async function generateReview(diff) {
|
|
|
70
61
|
|
|
71
62
|
console.log("🤔 Analyzing changes...");
|
|
72
63
|
|
|
64
|
+
if (!process.env.OPENAI_API_KEY) {
|
|
65
|
+
throw new Error("❌ Error: OPENAI_API_KEY is missing in .env file.");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const openai = new OpenAI({
|
|
69
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
70
|
+
baseURL: process.env.AI_BASE_URL || "https://api.z.ai/api/paas/v4/",
|
|
71
|
+
});
|
|
72
|
+
|
|
73
73
|
const response = await openai.chat.completions.create({
|
|
74
74
|
model: process.env.AI_MODEL || "glm-4.6v-flash",
|
|
75
75
|
messages: [
|
|
@@ -97,7 +97,7 @@ async function generateReview(diff) {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// Main Execution
|
|
100
|
-
async function run() {
|
|
100
|
+
export async function run() {
|
|
101
101
|
try {
|
|
102
102
|
// const diff = await getStagedDiff();
|
|
103
103
|
// 1. SELECT STRATEGY
|
|
@@ -139,4 +139,6 @@ async function run() {
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
143
|
+
run();
|
|
144
|
+
}
|