gitpt 1.6.1 → 1.7.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/README.md +34 -167
- package/dist/commands/commit/commitFlags.js +7 -0
- package/dist/commands/commit/context/buildPrompt.js +13 -10
- package/dist/commands/commit/context/summaryPrompt.js +5 -2
- package/dist/commands/commit/context/systemPrompt.js +4 -1
- package/dist/commands/commit/context/userPrompt.js +4 -1
- package/dist/commands/commit/generateCommitMessage.js +14 -17
- package/dist/commands/commit/index.js +186 -179
- package/dist/commands/commit/summarizeDiff.js +183 -162
- package/dist/commands/config.js +24 -9
- package/dist/commands/hook/index.js +68 -0
- package/dist/commands/middleware/capabilitiesMiddleware/ghCapability.js +20 -20
- package/dist/commands/middleware/capabilitiesMiddleware/gitCapability.js +13 -10
- package/dist/commands/middleware/capabilitiesMiddleware/index.js +12 -11
- package/dist/commands/middleware/hasStagedChangesMiddleware.js +9 -6
- package/dist/commands/middleware/setupMiddleware/defaultModels.js +14 -10
- package/dist/commands/middleware/setupMiddleware/index.js +65 -71
- package/dist/commands/model.js +7 -4
- package/dist/commands/passthroughArgs.js +11 -0
- package/dist/commands/pr/context/systemPrompt.js +4 -1
- package/dist/commands/pr/context/userPrompt.js +4 -1
- package/dist/commands/pr/generatePRDetails.js +24 -23
- package/dist/commands/pr/getPRContext.js +37 -62
- package/dist/commands/pr/index.js +57 -62
- package/dist/commands/reset.js +23 -23
- package/dist/commands/review/index.js +31 -0
- package/dist/commands/setup.js +38 -13
- package/dist/config.js +63 -60
- package/dist/index.js +30 -67
- package/dist/llm/budget.js +10 -0
- package/dist/llm/index.js +12 -7
- package/dist/llm/providers/anthropic/index.js +30 -30
- package/dist/llm/providers/apiKey.js +36 -35
- package/dist/llm/providers/apple/client.js +73 -83
- package/dist/llm/providers/apple/index.js +64 -72
- package/dist/llm/providers/apple/models.js +27 -19
- package/dist/llm/providers/base.js +36 -36
- package/dist/llm/providers/local/index.js +79 -91
- package/dist/llm/providers/openai/index.js +19 -16
- package/dist/llm/providers/openaiCompatible.js +59 -62
- package/dist/llm/providers/openrouter/index.js +18 -15
- package/dist/llm/registry.js +30 -34
- package/dist/llm/setup/getAvailableModels.js +15 -9
- package/dist/llm/setup/selectModel.js +36 -44
- package/dist/llm/tokenCount.js +4 -3
- package/dist/package.js +67 -0
- package/dist/services/gh/createPullRequest.js +38 -58
- package/dist/services/gh/index.js +6 -3
- package/dist/services/gh/isAvailable.js +10 -8
- package/dist/services/git/executeGitAdd.js +11 -12
- package/dist/services/git/executeGitCommit.js +10 -11
- package/dist/services/git/getAmendChanges.js +23 -0
- package/dist/services/git/getChangedFiles.js +28 -61
- package/dist/services/git/getCommitsSinceBaseBranch.js +28 -56
- package/dist/services/git/getCurrentBranch.js +10 -8
- package/dist/services/git/getDefaultBranch.js +35 -60
- package/dist/services/git/getStagedChanges.js +10 -8
- package/dist/services/git/getStagedFiles.js +10 -9
- package/dist/services/git/hasStagedChanges.js +9 -8
- package/dist/services/git/index.js +17 -12
- package/dist/services/git/isAvailable.js +10 -8
- package/dist/services/git/isGitRepository.js +10 -8
- package/dist/utils/commitlint.js +97 -135
- package/dist/utils/formatBaseURL.js +7 -6
- package/dist/utils/maskApiKey.js +6 -7
- package/package.json +14 -4
- package/dist/commands/commit/context/buildPrompt.d.ts +0 -4
- package/dist/commands/commit/context/summaryPrompt.d.ts +0 -2
- package/dist/commands/commit/context/systemPrompt.d.ts +0 -1
- package/dist/commands/commit/context/userPrompt.d.ts +0 -1
- package/dist/commands/commit/generateCommitMessage.d.ts +0 -1
- package/dist/commands/commit/index.d.ts +0 -7
- package/dist/commands/commit/summarizeDiff.d.ts +0 -1
- package/dist/commands/config.d.ts +0 -1
- package/dist/commands/middleware/capabilitiesMiddleware/ghCapability.d.ts +0 -1
- package/dist/commands/middleware/capabilitiesMiddleware/gitCapability.d.ts +0 -1
- package/dist/commands/middleware/capabilitiesMiddleware/index.d.ts +0 -3
- package/dist/commands/middleware/hasStagedChangesMiddleware.d.ts +0 -1
- package/dist/commands/middleware/setupMiddleware/defaultModels.d.ts +0 -8
- package/dist/commands/middleware/setupMiddleware/index.d.ts +0 -4
- package/dist/commands/model.d.ts +0 -1
- package/dist/commands/pr/context/systemPrompt.d.ts +0 -1
- package/dist/commands/pr/context/userPrompt.d.ts +0 -1
- package/dist/commands/pr/generatePRDetails.d.ts +0 -4
- package/dist/commands/pr/getPRContext.d.ts +0 -1
- package/dist/commands/pr/index.d.ts +0 -10
- package/dist/commands/reset.d.ts +0 -3
- package/dist/commands/setup.d.ts +0 -3
- package/dist/config.d.ts +0 -14
- package/dist/index.d.ts +0 -2
- package/dist/llm/client.d.ts +0 -24
- package/dist/llm/client.js +0 -1
- package/dist/llm/index.d.ts +0 -6
- package/dist/llm/providers/anthropic/index.d.ts +0 -9
- package/dist/llm/providers/apiKey.d.ts +0 -3
- package/dist/llm/providers/apple/client.d.ts +0 -3
- package/dist/llm/providers/apple/index.d.ts +0 -13
- package/dist/llm/providers/apple/models.d.ts +0 -14
- package/dist/llm/providers/base.d.ts +0 -30
- package/dist/llm/providers/local/index.d.ts +0 -11
- package/dist/llm/providers/openai/index.d.ts +0 -10
- package/dist/llm/providers/openaiCompatible.d.ts +0 -15
- package/dist/llm/providers/openrouter/index.d.ts +0 -9
- package/dist/llm/registry.d.ts +0 -8
- package/dist/llm/setup/getAvailableModels.d.ts +0 -5
- package/dist/llm/setup/selectModel.d.ts +0 -5
- package/dist/llm/setup/types.d.ts +0 -13
- package/dist/llm/setup/types.js +0 -1
- package/dist/llm/tokenCount.d.ts +0 -3
- package/dist/services/gh/createPullRequest.d.ts +0 -1
- package/dist/services/gh/index.d.ts +0 -4
- package/dist/services/gh/isAvailable.d.ts +0 -1
- package/dist/services/git/executeGitAdd.d.ts +0 -1
- package/dist/services/git/executeGitCommit.d.ts +0 -1
- package/dist/services/git/getChangedFiles.d.ts +0 -1
- package/dist/services/git/getCommitsSinceBaseBranch.d.ts +0 -1
- package/dist/services/git/getCurrentBranch.d.ts +0 -1
- package/dist/services/git/getDefaultBranch.d.ts +0 -1
- package/dist/services/git/getStagedChanges.d.ts +0 -1
- package/dist/services/git/getStagedFiles.d.ts +0 -1
- package/dist/services/git/hasStagedChanges.d.ts +0 -1
- package/dist/services/git/index.d.ts +0 -13
- package/dist/services/git/isAvailable.d.ts +0 -1
- package/dist/services/git/isGitRepository.d.ts +0 -1
- package/dist/utils/commitlint.d.ts +0 -25
- package/dist/utils/formatBaseURL.d.ts +0 -1
- package/dist/utils/maskApiKey.d.ts +0 -1
|
@@ -1,59 +1,31 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { execSync } from "child_process";
|
|
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
|
-
if (commitMessages) {
|
|
30
|
-
return commitMessages.split("\n").filter(Boolean);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
// If that fails too, fallback to simple branch comparison
|
|
35
|
-
console.log(chalk.yellow(`Merge base with ${baseBranch} not found, comparing branches directly...`));
|
|
36
|
-
}
|
|
37
|
-
// Direct branch comparison
|
|
38
|
-
try {
|
|
39
|
-
const commitMessages = execSync(`git log --pretty=format:"%s" ${baseBranch}..HEAD`)
|
|
40
|
-
.toString()
|
|
41
|
-
.trim();
|
|
42
|
-
if (commitMessages) {
|
|
43
|
-
return commitMessages.split("\n").filter(Boolean);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
console.log(chalk.yellow(`Could not compare with ${baseBranch}, using recent commits...`));
|
|
48
|
-
}
|
|
49
|
-
// Last resort: get most recent commits
|
|
50
|
-
const commitMessages = execSync('git log --pretty=format:"%s" -n 10')
|
|
51
|
-
.toString()
|
|
52
|
-
.trim();
|
|
53
|
-
return commitMessages.split("\n").filter(Boolean);
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
console.error(chalk.yellow("Could not get commits. Using empty list."));
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
3
|
+
//#region src/services/git/getCommitsSinceBaseBranch.ts
|
|
4
|
+
var getCommitsSinceBaseBranch = (baseBranch) => {
|
|
5
|
+
try {
|
|
6
|
+
try {
|
|
7
|
+
const commitMessages = execSync(`git log --pretty=format:"%s" ${execSync(`git merge-base HEAD origin/${baseBranch}`).toString().trim()}..HEAD`).toString().trim();
|
|
8
|
+
if (commitMessages) return commitMessages.split("\n").filter(Boolean);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
console.log(chalk.yellow(`No origin/${baseBranch} found, trying with local ${baseBranch} branch...`));
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const commitMessages = execSync(`git log --pretty=format:"%s" ${execSync(`git merge-base HEAD ${baseBranch}`).toString().trim()}..HEAD`).toString().trim();
|
|
14
|
+
if (commitMessages) return commitMessages.split("\n").filter(Boolean);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.log(chalk.yellow(`Merge base with ${baseBranch} not found, comparing branches directly...`));
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const commitMessages = execSync(`git log --pretty=format:"%s" ${baseBranch}..HEAD`).toString().trim();
|
|
20
|
+
if (commitMessages) return commitMessages.split("\n").filter(Boolean);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.log(chalk.yellow(`Could not compare with ${baseBranch}, using recent commits...`));
|
|
23
|
+
}
|
|
24
|
+
return execSync("git log --pretty=format:\"%s\" -n 10").toString().trim().split("\n").filter(Boolean);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(chalk.yellow("Could not get commits. Using empty list."));
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
59
29
|
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { getCommitsSinceBaseBranch };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { execSync } from "child_process";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
//#region src/services/git/getCurrentBranch.ts
|
|
4
|
+
var getCurrentBranch = () => {
|
|
5
|
+
try {
|
|
6
|
+
return execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
|
|
7
|
+
} catch (error) {
|
|
8
|
+
console.error(chalk.red("Error getting current branch:"), error);
|
|
9
|
+
throw new Error("Failed to get current branch");
|
|
10
|
+
}
|
|
11
11
|
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { getCurrentBranch };
|
|
@@ -1,63 +1,38 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { execSync } from "child_process";
|
|
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
|
-
/origin\/dev$/,
|
|
37
|
-
/origin\/trunk$/,
|
|
38
|
-
];
|
|
39
|
-
// Try each pattern in order
|
|
40
|
-
for (const pattern of mainPatterns) {
|
|
41
|
-
const defaultBranch = branches.find((b) => pattern.test(b.trim()));
|
|
42
|
-
if (defaultBranch) {
|
|
43
|
-
return defaultBranch.trim().replace(/^origin\//, "");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// Check for a branch that has 'HEAD -> origin/' in it, indicating the default branch
|
|
47
|
-
const headBranch = branches.find((b) => b.includes("HEAD -> origin/"));
|
|
48
|
-
if (headBranch) {
|
|
49
|
-
const match = headBranch.match(/HEAD -> origin\/([^,\s]+)/);
|
|
50
|
-
if (match && match[1]) {
|
|
51
|
-
return match[1];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// Fallback to 'main' as most GitHub repos use this now
|
|
55
|
-
console.log(chalk.yellow('Could not determine default branch, using "main"'));
|
|
56
|
-
return "main";
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
// If we can't determine, default to main
|
|
60
|
-
console.log(chalk.yellow('Error detecting default branch, using "main"'));
|
|
61
|
-
return "main";
|
|
62
|
-
}
|
|
3
|
+
//#region src/services/git/getDefaultBranch.ts
|
|
4
|
+
var getDefaultBranch = () => {
|
|
5
|
+
try {
|
|
6
|
+
try {
|
|
7
|
+
const defaultBranch = execSync("git config init.defaultBranch").toString().trim();
|
|
8
|
+
if (defaultBranch) return defaultBranch;
|
|
9
|
+
} catch (error) {}
|
|
10
|
+
try {
|
|
11
|
+
const repoInfo = execSync("gh repo view --json defaultBranchRef --jq .defaultBranchRef.name").toString().trim();
|
|
12
|
+
if (repoInfo) return repoInfo;
|
|
13
|
+
} catch (error) {}
|
|
14
|
+
const branches = execSync("git branch -r").toString().trim().split("\n");
|
|
15
|
+
for (const pattern of [
|
|
16
|
+
/origin\/main$/,
|
|
17
|
+
/origin\/master$/,
|
|
18
|
+
/origin\/develop$/,
|
|
19
|
+
/origin\/dev$/,
|
|
20
|
+
/origin\/trunk$/
|
|
21
|
+
]) {
|
|
22
|
+
const defaultBranch = branches.find((b) => pattern.test(b.trim()));
|
|
23
|
+
if (defaultBranch) return defaultBranch.trim().replace(/^origin\//, "");
|
|
24
|
+
}
|
|
25
|
+
const headBranch = branches.find((b) => b.includes("HEAD -> origin/"));
|
|
26
|
+
if (headBranch) {
|
|
27
|
+
const match = headBranch.match(/HEAD -> origin\/([^,\s]+)/);
|
|
28
|
+
if (match && match[1]) return match[1];
|
|
29
|
+
}
|
|
30
|
+
console.log(chalk.yellow("Could not determine default branch, using \"main\""));
|
|
31
|
+
return "main";
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.log(chalk.yellow("Error detecting default branch, using \"main\""));
|
|
34
|
+
return "main";
|
|
35
|
+
}
|
|
63
36
|
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { getDefaultBranch };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { execSync } from "child_process";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
//#region src/services/git/getStagedChanges.ts
|
|
4
|
+
var getStagedChanges = () => {
|
|
5
|
+
try {
|
|
6
|
+
return execSync("git diff --staged --function-context").toString();
|
|
7
|
+
} catch (error) {
|
|
8
|
+
console.error(chalk.red("Error getting staged changes:"), error);
|
|
9
|
+
throw new Error("Failed to get staged changes");
|
|
10
|
+
}
|
|
11
11
|
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { getStagedChanges };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { execSync } from "child_process";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
3
|
+
//#region src/services/git/getStagedFiles.ts
|
|
4
|
+
var getStagedFiles = () => {
|
|
5
|
+
try {
|
|
6
|
+
return execSync("git diff --staged --name-only").toString().split("\n").filter(Boolean);
|
|
7
|
+
} catch (error) {
|
|
8
|
+
console.error(chalk.red("Error getting staged files:"), error);
|
|
9
|
+
throw new Error("Failed to get staged files");
|
|
10
|
+
}
|
|
12
11
|
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { getStagedFiles };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { execSync } from "child_process";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
2
|
+
//#region src/services/git/hasStagedChanges.ts
|
|
3
|
+
var hasStagedChanges = () => {
|
|
4
|
+
try {
|
|
5
|
+
return execSync("git diff --staged --quiet || echo \"has-changes\"").toString().includes("has-changes");
|
|
6
|
+
} catch (error) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
10
9
|
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { hasStagedChanges };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { executeGitAdd } from "./executeGitAdd.js";
|
|
2
2
|
import { executeGitCommit } from "./executeGitCommit.js";
|
|
3
3
|
import { getChangedFiles } from "./getChangedFiles.js";
|
|
4
|
+
import { getAmendChanges } from "./getAmendChanges.js";
|
|
4
5
|
import { getCommitsSinceBaseBranch } from "./getCommitsSinceBaseBranch.js";
|
|
5
6
|
import { getCurrentBranch } from "./getCurrentBranch.js";
|
|
6
7
|
import { getDefaultBranch } from "./getDefaultBranch.js";
|
|
@@ -9,16 +10,20 @@ import { getStagedFiles } from "./getStagedFiles.js";
|
|
|
9
10
|
import { hasStagedChanges } from "./hasStagedChanges.js";
|
|
10
11
|
import { isAvailable } from "./isAvailable.js";
|
|
11
12
|
import { isGitRepository } from "./isGitRepository.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
//#region src/services/git/index.ts
|
|
14
|
+
var git = {
|
|
15
|
+
add: executeGitAdd,
|
|
16
|
+
commit: executeGitCommit,
|
|
17
|
+
getAmendChanges,
|
|
18
|
+
getChangedFiles,
|
|
19
|
+
getCommitsSinceBaseBranch,
|
|
20
|
+
getCurrentBranch,
|
|
21
|
+
getDefaultBranch,
|
|
22
|
+
hasStagedChanges,
|
|
23
|
+
getStagedChanges,
|
|
24
|
+
getStagedFiles,
|
|
25
|
+
isAvailable,
|
|
26
|
+
isGitRepository
|
|
24
27
|
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { git };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { execSync } from "child_process";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
//#region src/services/git/isAvailable.ts
|
|
3
|
+
var isAvailable = () => {
|
|
4
|
+
try {
|
|
5
|
+
execSync("git --version", { stdio: "ignore" });
|
|
6
|
+
return true;
|
|
7
|
+
} catch (error) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
10
|
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { isAvailable };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { execSync } from "child_process";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
//#region src/services/git/isGitRepository.ts
|
|
3
|
+
var isGitRepository = () => {
|
|
4
|
+
try {
|
|
5
|
+
execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore" });
|
|
6
|
+
return true;
|
|
7
|
+
} catch (error) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
10
|
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { isGitRepository };
|
package/dist/utils/commitlint.js
CHANGED
|
@@ -1,148 +1,110 @@
|
|
|
1
|
-
import loadConfig from "@commitlint/load";
|
|
2
1
|
import { execSync } from "child_process";
|
|
2
|
+
import loadConfig from "@commitlint/load";
|
|
3
3
|
import fs from "fs";
|
|
4
|
+
//#region src/utils/commitlint.ts
|
|
4
5
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return fs.existsSync(file);
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
6
|
+
* Check if a commitlint configuration exists in the repository
|
|
7
|
+
*/
|
|
8
|
+
function hasCommitlintConfig() {
|
|
9
|
+
const possibleConfigFiles = [
|
|
10
|
+
".commitlintrc",
|
|
11
|
+
".commitlintrc.json",
|
|
12
|
+
".commitlintrc.yaml",
|
|
13
|
+
".commitlintrc.yml",
|
|
14
|
+
".commitlintrc.js",
|
|
15
|
+
"commitlint.config.js",
|
|
16
|
+
"package.json"
|
|
17
|
+
];
|
|
18
|
+
readCommitlintConfig();
|
|
19
|
+
return possibleConfigFiles.some((file) => {
|
|
20
|
+
try {
|
|
21
|
+
if (file === "package.json") return JSON.parse(fs.readFileSync("package.json", "utf8")).commitlint !== void 0;
|
|
22
|
+
return fs.existsSync(file);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
32
27
|
}
|
|
33
28
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// console.log(config);
|
|
39
|
-
return config.rules;
|
|
29
|
+
* Read commitlint config file (using @commitlint/load) and print it out
|
|
30
|
+
*/
|
|
31
|
+
async function readCommitlintConfig() {
|
|
32
|
+
return (await loadConfig()).rules;
|
|
40
33
|
}
|
|
41
34
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
if (fs.existsSync(".commitlintrc.json")) {
|
|
63
|
-
const config = JSON.parse(fs.readFileSync(".commitlintrc.json", "utf8"));
|
|
64
|
-
return formatCommitlintRules(config);
|
|
65
|
-
}
|
|
66
|
-
// Default to conventional commits format if we can't parse the config
|
|
67
|
-
return "Follow the conventional commit format (type(scope): message)";
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
// If all else fails, return a generic message
|
|
72
|
-
return "Follow the conventional commit format (type(scope): message)";
|
|
73
|
-
}
|
|
35
|
+
* Get the commitlint configuration format rules as a string
|
|
36
|
+
*/
|
|
37
|
+
function getCommitlintRules() {
|
|
38
|
+
try {
|
|
39
|
+
try {
|
|
40
|
+
const rulesOutput = execSync("npx commitlint --print-config", { stdio: [
|
|
41
|
+
"ignore",
|
|
42
|
+
"pipe",
|
|
43
|
+
"ignore"
|
|
44
|
+
] }).toString();
|
|
45
|
+
return formatCommitlintRules(JSON.parse(rulesOutput));
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (fs.existsSync("commitlint.config.js")) return "Follow the conventional commit format (type(scope): message)";
|
|
48
|
+
if (fs.existsSync(".commitlintrc.json")) return formatCommitlintRules(JSON.parse(fs.readFileSync(".commitlintrc.json", "utf8")));
|
|
49
|
+
return "Follow the conventional commit format (type(scope): message)";
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
return "Follow the conventional commit format (type(scope): message)";
|
|
53
|
+
}
|
|
74
54
|
}
|
|
75
55
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
56
|
+
* Format commitlint rules into a human-readable string
|
|
57
|
+
*/
|
|
78
58
|
function formatCommitlintRules(config) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
rulesDescription += `- Subject must follow case rules\n`;
|
|
97
|
-
}
|
|
98
|
-
if (config.rules["subject-max-length"]) {
|
|
99
|
-
const maxLength = config.rules["subject-max-length"][2];
|
|
100
|
-
rulesDescription += `- Subject must be no longer than ${maxLength} characters\n`;
|
|
101
|
-
}
|
|
102
|
-
rulesDescription +=
|
|
103
|
-
"- Use a single commit message, not multiple messages separated by blank lines or markdown formatting";
|
|
104
|
-
return rulesDescription;
|
|
59
|
+
let rulesDescription = "Follow these commit message rules:\n";
|
|
60
|
+
if (!config.rules) return "Follow the conventional commit format (type(scope): message)";
|
|
61
|
+
if (config.rules["type-enum"] && Array.isArray(config.rules["type-enum"][2])) {
|
|
62
|
+
const allowedTypes = config.rules["type-enum"][2];
|
|
63
|
+
rulesDescription += `- Commit type must be one of: ${allowedTypes.join(", ")}\n`;
|
|
64
|
+
}
|
|
65
|
+
if (config.rules["scope-enum"] && Array.isArray(config.rules["scope-enum"][2])) {
|
|
66
|
+
const allowedScopes = config.rules["scope-enum"][2];
|
|
67
|
+
rulesDescription += `- Scope must be one of: ${allowedScopes.join(", ")}\n`;
|
|
68
|
+
}
|
|
69
|
+
if (config.rules["subject-case"]) rulesDescription += `- Subject must follow case rules\n`;
|
|
70
|
+
if (config.rules["subject-max-length"]) {
|
|
71
|
+
const maxLength = config.rules["subject-max-length"][2];
|
|
72
|
+
rulesDescription += `- Subject must be no longer than ${maxLength} characters\n`;
|
|
73
|
+
}
|
|
74
|
+
rulesDescription += "- Use a single commit message, not multiple messages separated by blank lines or markdown formatting";
|
|
75
|
+
return rulesDescription;
|
|
105
76
|
}
|
|
106
77
|
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
// If we still can't get error output, fall back to basic pattern check
|
|
138
|
-
fs.unlinkSync(tempFile);
|
|
139
|
-
return { valid: true };
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
// If all else fails, just do a basic regex check
|
|
145
|
-
console.warn("Warning: Could not validate with commitlint, performing basic validation");
|
|
146
|
-
return { valid: true };
|
|
147
|
-
}
|
|
78
|
+
* Validate a commit message against commitlint rules
|
|
79
|
+
* @param message The commit message to validate
|
|
80
|
+
* @returns An object with success status and error message if applicable
|
|
81
|
+
*/
|
|
82
|
+
async function validateCommitMessage(message) {
|
|
83
|
+
if (!hasCommitlintConfig()) return { valid: true };
|
|
84
|
+
try {
|
|
85
|
+
const tempFile = `/tmp/gitpt-commit-msg-${Date.now()}`;
|
|
86
|
+
fs.writeFileSync(tempFile, message);
|
|
87
|
+
try {
|
|
88
|
+
execSync(`npx commitlint < ${tempFile}`, { stdio: "ignore" });
|
|
89
|
+
fs.unlinkSync(tempFile);
|
|
90
|
+
return { valid: true };
|
|
91
|
+
} catch (error) {
|
|
92
|
+
try {
|
|
93
|
+
const errorOutput = execSync(`npx commitlint < ${tempFile} 2>&1 || true`).toString();
|
|
94
|
+
fs.unlinkSync(tempFile);
|
|
95
|
+
return {
|
|
96
|
+
valid: false,
|
|
97
|
+
errors: errorOutput
|
|
98
|
+
};
|
|
99
|
+
} catch (e) {
|
|
100
|
+
fs.unlinkSync(tempFile);
|
|
101
|
+
return { valid: true };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.warn("Warning: Could not validate with commitlint, performing basic validation");
|
|
106
|
+
return { valid: true };
|
|
107
|
+
}
|
|
148
108
|
}
|
|
109
|
+
//#endregion
|
|
110
|
+
export { getCommitlintRules, hasCommitlintConfig, validateCommitMessage };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return baseURL;
|
|
1
|
+
//#region src/utils/formatBaseURL.ts
|
|
2
|
+
var formatBaseURL = (baseURL) => {
|
|
3
|
+
const trimmed = baseURL.replace(/\/+$/, "");
|
|
4
|
+
if (!trimmed.endsWith("/v1")) return `${trimmed}/v1`;
|
|
5
|
+
return trimmed;
|
|
7
6
|
};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { formatBaseURL };
|
package/dist/utils/maskApiKey.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const firstFour = apiKey.substring(0, 4);
|
|
6
|
-
const lastFour = apiKey.substring(apiKey.length - 4);
|
|
7
|
-
return `${firstFour}...${lastFour}`;
|
|
1
|
+
//#region src/utils/maskApiKey.ts
|
|
2
|
+
var maskApiKey = (apiKey) => {
|
|
3
|
+
if (apiKey.length <= 10) return "*".repeat(apiKey.length);
|
|
4
|
+
return `${apiKey.substring(0, 4)}...${apiKey.substring(apiKey.length - 4)}`;
|
|
8
5
|
};
|
|
6
|
+
//#endregion
|
|
7
|
+
export { maskApiKey };
|