@commitguard/cli 0.0.1 → 0.0.3
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/dist/index.mjs +23 -12
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -22,7 +22,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
24
|
//#region package.json
|
|
25
|
-
var version = "0.0.
|
|
25
|
+
var version = "0.0.3";
|
|
26
26
|
var package_default = {
|
|
27
27
|
name: "@commitguard/cli",
|
|
28
28
|
type: "module",
|
|
@@ -230,6 +230,7 @@ function addGitLineNumbers(diff) {
|
|
|
230
230
|
}
|
|
231
231
|
return result.join("\n");
|
|
232
232
|
}
|
|
233
|
+
const MESSAGES = { noGit: "No .git folder found. Run this inside a git repository." };
|
|
233
234
|
|
|
234
235
|
//#endregion
|
|
235
236
|
//#region src/utils/git.ts
|
|
@@ -327,7 +328,7 @@ async function manageGlobalKey() {
|
|
|
327
328
|
} else outro("API key removed. You can set a new one later using `commitguard init` or `commitguard keys`.");
|
|
328
329
|
}
|
|
329
330
|
} else {
|
|
330
|
-
note("To get your free API key, visit https://commitguard.
|
|
331
|
+
note("To get your free API key, visit https://commitguard.ai", "Get your free API key");
|
|
331
332
|
const apiKey = await text({
|
|
332
333
|
message: "Enter your CommitGuard API key:",
|
|
333
334
|
placeholder: "sk_XXXXXXXXXXXXXXXXXXXXXX",
|
|
@@ -352,7 +353,7 @@ async function manageGlobalKey() {
|
|
|
352
353
|
//#region src/utils/api.ts
|
|
353
354
|
async function sendToCommitGuard(diff, eslint, config) {
|
|
354
355
|
const apiKey = process.env.COMMITGUARD_API_KEY || getGlobalKey() || null;
|
|
355
|
-
if (!apiKey) throw new Error("No API key found. Set one globally with \"commitguard keys\" or add COMMITGUARD_API_KEY to your .env file. Get your free API key at https://commitguard.
|
|
356
|
+
if (!apiKey) throw new Error("No API key found. Set one globally with \"commitguard keys\" or add COMMITGUARD_API_KEY to your .env file. Get your free API key at https://commitguard.ai");
|
|
356
357
|
const apiUrl = process.env.COMMITGUARD_API_URL || "https://api.commitguard.ai/v1/analyze";
|
|
357
358
|
const response = await fetch(apiUrl, {
|
|
358
359
|
method: "POST",
|
|
@@ -369,13 +370,19 @@ async function sendToCommitGuard(diff, eslint, config) {
|
|
|
369
370
|
});
|
|
370
371
|
if (!response.ok) {
|
|
371
372
|
const errorText = await response.text();
|
|
372
|
-
|
|
373
|
+
let errorMessage = "Failed to analyze commit";
|
|
374
|
+
if (response.status === 401) errorMessage = "Invalid API key. Check your key with \"commitguard keys\" or get a new one at https://commitguard.ai";
|
|
375
|
+
else if (response.status === 429) errorMessage = "Rate limit exceeded. Please try again later";
|
|
376
|
+
else if (response.status === 500) errorMessage = "CommitGuard service error. Please try again later";
|
|
377
|
+
else if (response.status >= 400 && response.status < 500) errorMessage = `Request error: ${errorText || "Invalid request"}`;
|
|
378
|
+
else errorMessage = `Service unavailable (${response.status}). Please try again later`;
|
|
379
|
+
throw new Error(errorMessage);
|
|
373
380
|
}
|
|
374
381
|
return await response.json();
|
|
375
382
|
}
|
|
376
383
|
async function bypassCommitGuard() {
|
|
377
384
|
const apiKey = process.env.COMMITGUARD_API_KEY || getGlobalKey() || null;
|
|
378
|
-
if (!apiKey) throw new Error("No API key found. Set one globally with \"commitguard keys\" or add COMMITGUARD_API_KEY to your .env file. Get your free API key at https://commitguard.
|
|
385
|
+
if (!apiKey) throw new Error("No API key found. Set one globally with \"commitguard keys\" or add COMMITGUARD_API_KEY to your .env file. Get your free API key at https://commitguard.ai");
|
|
379
386
|
const apiUrl = process.env.COMMITGUARD_API_BYPASS_URL || "https://api.commitguard.ai/v1/bypass";
|
|
380
387
|
const diff = getLastDiff();
|
|
381
388
|
const response = await fetch(apiUrl, {
|
|
@@ -400,6 +407,7 @@ const MAX_CUSTOM_PROMPT_LENGTH = 500;
|
|
|
400
407
|
const CONFIG_DIR = join(homedir(), ".commitguard");
|
|
401
408
|
const PROJECTS_CONFIG_PATH = join(CONFIG_DIR, "projects.json");
|
|
402
409
|
let projectsConfigCache = null;
|
|
410
|
+
const GIT_DIR$1 = ".git";
|
|
403
411
|
function ensureConfigDir() {
|
|
404
412
|
if (!existsSync(CONFIG_DIR)) try {
|
|
405
413
|
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
@@ -418,7 +426,7 @@ function getDefaultConfig() {
|
|
|
418
426
|
severityLevels: {
|
|
419
427
|
critical: true,
|
|
420
428
|
warning: true,
|
|
421
|
-
suggestion:
|
|
429
|
+
suggestion: false
|
|
422
430
|
},
|
|
423
431
|
customRule: ""
|
|
424
432
|
};
|
|
@@ -472,6 +480,10 @@ function loadConfig() {
|
|
|
472
480
|
return loadProjectsConfig()[projectId] || getDefaultConfig();
|
|
473
481
|
}
|
|
474
482
|
async function manageConfig() {
|
|
483
|
+
if (!existsSync(GIT_DIR$1)) {
|
|
484
|
+
cancel(MESSAGES.noGit);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
475
487
|
const projectId = getProjectId();
|
|
476
488
|
const currentConfig = loadConfig();
|
|
477
489
|
intro(`CommitGuard Configuration`);
|
|
@@ -685,11 +697,10 @@ const GIT_DIR = ".git";
|
|
|
685
697
|
const HOOKS_DIR = join(GIT_DIR, "hooks");
|
|
686
698
|
const COMMIT_MSG_HOOK_PATH = join(HOOKS_DIR, "commit-msg");
|
|
687
699
|
const POST_INDEX_HOOK_PATH = join(HOOKS_DIR, "post-index-change");
|
|
688
|
-
const MESSAGES = { noGit: "No .git folder found. Run this inside a git repository." };
|
|
689
700
|
async function installHooks() {
|
|
690
701
|
if (!existsSync(GIT_DIR)) {
|
|
691
702
|
cancel(MESSAGES.noGit);
|
|
692
|
-
|
|
703
|
+
return;
|
|
693
704
|
}
|
|
694
705
|
if (!existsSync(HOOKS_DIR)) mkdirSync(HOOKS_DIR, { recursive: true });
|
|
695
706
|
try {
|
|
@@ -1035,15 +1046,15 @@ const command = process.argv[2];
|
|
|
1035
1046
|
CommitGuard - AI-powered git commit checker v${version}
|
|
1036
1047
|
|
|
1037
1048
|
Usage:
|
|
1038
|
-
commitguard init Initialize CommitGuard in the current
|
|
1039
|
-
commitguard remove Remove CommitGuard from the current
|
|
1040
|
-
commitguard config Configure CommitGuard
|
|
1049
|
+
commitguard init Initialize CommitGuard in the current project
|
|
1050
|
+
commitguard remove Remove CommitGuard from the current project
|
|
1051
|
+
commitguard config Configure CommitGuard prefrences for the current project
|
|
1041
1052
|
commitguard keys Manage your CommitGuard API key
|
|
1042
1053
|
|
|
1043
1054
|
Links:
|
|
1044
1055
|
Documentation: https://commitguard.ai/docs
|
|
1045
1056
|
Dashboard: https://commitguard.ai/dashboard
|
|
1046
|
-
Support:
|
|
1057
|
+
Support: hello@commitguard.ai`);
|
|
1047
1058
|
}
|
|
1048
1059
|
} catch (error) {
|
|
1049
1060
|
consola.error("CommitGuard error:", error);
|