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.
Files changed (127) hide show
  1. package/README.md +34 -167
  2. package/dist/commands/commit/commitFlags.js +7 -0
  3. package/dist/commands/commit/context/buildPrompt.js +13 -10
  4. package/dist/commands/commit/context/summaryPrompt.js +5 -2
  5. package/dist/commands/commit/context/systemPrompt.js +4 -1
  6. package/dist/commands/commit/context/userPrompt.js +4 -1
  7. package/dist/commands/commit/generateCommitMessage.js +14 -17
  8. package/dist/commands/commit/index.js +186 -179
  9. package/dist/commands/commit/summarizeDiff.js +183 -162
  10. package/dist/commands/config.js +24 -9
  11. package/dist/commands/hook/index.js +68 -0
  12. package/dist/commands/middleware/capabilitiesMiddleware/ghCapability.js +20 -20
  13. package/dist/commands/middleware/capabilitiesMiddleware/gitCapability.js +13 -10
  14. package/dist/commands/middleware/capabilitiesMiddleware/index.js +12 -11
  15. package/dist/commands/middleware/hasStagedChangesMiddleware.js +9 -6
  16. package/dist/commands/middleware/setupMiddleware/defaultModels.js +14 -10
  17. package/dist/commands/middleware/setupMiddleware/index.js +65 -71
  18. package/dist/commands/model.js +7 -4
  19. package/dist/commands/passthroughArgs.js +11 -0
  20. package/dist/commands/pr/context/systemPrompt.js +4 -1
  21. package/dist/commands/pr/context/userPrompt.js +4 -1
  22. package/dist/commands/pr/generatePRDetails.js +24 -23
  23. package/dist/commands/pr/getPRContext.js +37 -62
  24. package/dist/commands/pr/index.js +57 -62
  25. package/dist/commands/reset.js +23 -23
  26. package/dist/commands/review/index.js +31 -0
  27. package/dist/commands/setup.js +38 -13
  28. package/dist/config.js +63 -60
  29. package/dist/index.js +30 -67
  30. package/dist/llm/budget.js +10 -0
  31. package/dist/llm/index.js +12 -7
  32. package/dist/llm/providers/anthropic/index.js +30 -30
  33. package/dist/llm/providers/apiKey.js +36 -35
  34. package/dist/llm/providers/apple/client.js +73 -83
  35. package/dist/llm/providers/apple/index.js +64 -72
  36. package/dist/llm/providers/apple/models.js +27 -19
  37. package/dist/llm/providers/base.js +36 -36
  38. package/dist/llm/providers/local/index.js +79 -91
  39. package/dist/llm/providers/openai/index.js +19 -16
  40. package/dist/llm/providers/openaiCompatible.js +59 -62
  41. package/dist/llm/providers/openrouter/index.js +18 -15
  42. package/dist/llm/registry.js +30 -34
  43. package/dist/llm/setup/getAvailableModels.js +15 -9
  44. package/dist/llm/setup/selectModel.js +36 -44
  45. package/dist/llm/tokenCount.js +4 -3
  46. package/dist/package.js +67 -0
  47. package/dist/services/gh/createPullRequest.js +38 -58
  48. package/dist/services/gh/index.js +6 -3
  49. package/dist/services/gh/isAvailable.js +10 -8
  50. package/dist/services/git/executeGitAdd.js +11 -12
  51. package/dist/services/git/executeGitCommit.js +10 -11
  52. package/dist/services/git/getAmendChanges.js +23 -0
  53. package/dist/services/git/getChangedFiles.js +28 -61
  54. package/dist/services/git/getCommitsSinceBaseBranch.js +28 -56
  55. package/dist/services/git/getCurrentBranch.js +10 -8
  56. package/dist/services/git/getDefaultBranch.js +35 -60
  57. package/dist/services/git/getStagedChanges.js +10 -8
  58. package/dist/services/git/getStagedFiles.js +10 -9
  59. package/dist/services/git/hasStagedChanges.js +9 -8
  60. package/dist/services/git/index.js +17 -12
  61. package/dist/services/git/isAvailable.js +10 -8
  62. package/dist/services/git/isGitRepository.js +10 -8
  63. package/dist/utils/commitlint.js +97 -135
  64. package/dist/utils/formatBaseURL.js +7 -6
  65. package/dist/utils/maskApiKey.js +6 -7
  66. package/package.json +14 -4
  67. package/dist/commands/commit/context/buildPrompt.d.ts +0 -4
  68. package/dist/commands/commit/context/summaryPrompt.d.ts +0 -2
  69. package/dist/commands/commit/context/systemPrompt.d.ts +0 -1
  70. package/dist/commands/commit/context/userPrompt.d.ts +0 -1
  71. package/dist/commands/commit/generateCommitMessage.d.ts +0 -1
  72. package/dist/commands/commit/index.d.ts +0 -7
  73. package/dist/commands/commit/summarizeDiff.d.ts +0 -1
  74. package/dist/commands/config.d.ts +0 -1
  75. package/dist/commands/middleware/capabilitiesMiddleware/ghCapability.d.ts +0 -1
  76. package/dist/commands/middleware/capabilitiesMiddleware/gitCapability.d.ts +0 -1
  77. package/dist/commands/middleware/capabilitiesMiddleware/index.d.ts +0 -3
  78. package/dist/commands/middleware/hasStagedChangesMiddleware.d.ts +0 -1
  79. package/dist/commands/middleware/setupMiddleware/defaultModels.d.ts +0 -8
  80. package/dist/commands/middleware/setupMiddleware/index.d.ts +0 -4
  81. package/dist/commands/model.d.ts +0 -1
  82. package/dist/commands/pr/context/systemPrompt.d.ts +0 -1
  83. package/dist/commands/pr/context/userPrompt.d.ts +0 -1
  84. package/dist/commands/pr/generatePRDetails.d.ts +0 -4
  85. package/dist/commands/pr/getPRContext.d.ts +0 -1
  86. package/dist/commands/pr/index.d.ts +0 -10
  87. package/dist/commands/reset.d.ts +0 -3
  88. package/dist/commands/setup.d.ts +0 -3
  89. package/dist/config.d.ts +0 -14
  90. package/dist/index.d.ts +0 -2
  91. package/dist/llm/client.d.ts +0 -24
  92. package/dist/llm/client.js +0 -1
  93. package/dist/llm/index.d.ts +0 -6
  94. package/dist/llm/providers/anthropic/index.d.ts +0 -9
  95. package/dist/llm/providers/apiKey.d.ts +0 -3
  96. package/dist/llm/providers/apple/client.d.ts +0 -3
  97. package/dist/llm/providers/apple/index.d.ts +0 -13
  98. package/dist/llm/providers/apple/models.d.ts +0 -14
  99. package/dist/llm/providers/base.d.ts +0 -30
  100. package/dist/llm/providers/local/index.d.ts +0 -11
  101. package/dist/llm/providers/openai/index.d.ts +0 -10
  102. package/dist/llm/providers/openaiCompatible.d.ts +0 -15
  103. package/dist/llm/providers/openrouter/index.d.ts +0 -9
  104. package/dist/llm/registry.d.ts +0 -8
  105. package/dist/llm/setup/getAvailableModels.d.ts +0 -5
  106. package/dist/llm/setup/selectModel.d.ts +0 -5
  107. package/dist/llm/setup/types.d.ts +0 -13
  108. package/dist/llm/setup/types.js +0 -1
  109. package/dist/llm/tokenCount.d.ts +0 -3
  110. package/dist/services/gh/createPullRequest.d.ts +0 -1
  111. package/dist/services/gh/index.d.ts +0 -4
  112. package/dist/services/gh/isAvailable.d.ts +0 -1
  113. package/dist/services/git/executeGitAdd.d.ts +0 -1
  114. package/dist/services/git/executeGitCommit.d.ts +0 -1
  115. package/dist/services/git/getChangedFiles.d.ts +0 -1
  116. package/dist/services/git/getCommitsSinceBaseBranch.d.ts +0 -1
  117. package/dist/services/git/getCurrentBranch.d.ts +0 -1
  118. package/dist/services/git/getDefaultBranch.d.ts +0 -1
  119. package/dist/services/git/getStagedChanges.d.ts +0 -1
  120. package/dist/services/git/getStagedFiles.d.ts +0 -1
  121. package/dist/services/git/hasStagedChanges.d.ts +0 -1
  122. package/dist/services/git/index.d.ts +0 -13
  123. package/dist/services/git/isAvailable.d.ts +0 -1
  124. package/dist/services/git/isGitRepository.d.ts +0 -1
  125. package/dist/utils/commitlint.d.ts +0 -25
  126. package/dist/utils/formatBaseURL.d.ts +0 -1
  127. 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
- export const getCommitsSinceBaseBranch = (baseBranch) => {
4
- try {
5
- // Try first with origin/baseBranch
6
- try {
7
- const mergeBase = execSync(`git merge-base HEAD origin/${baseBranch}`)
8
- .toString()
9
- .trim();
10
- const commitMessages = execSync(`git log --pretty=format:"%s" ${mergeBase}..HEAD`)
11
- .toString()
12
- .trim();
13
- if (commitMessages) {
14
- return commitMessages.split("\n").filter(Boolean);
15
- }
16
- }
17
- catch (error) {
18
- // If origin/baseBranch doesn't exist, try with just baseBranch
19
- console.log(chalk.yellow(`No origin/${baseBranch} found, trying with local ${baseBranch} branch...`));
20
- }
21
- // Try with local branch
22
- try {
23
- const mergeBase = execSync(`git merge-base HEAD ${baseBranch}`)
24
- .toString()
25
- .trim();
26
- const commitMessages = execSync(`git log --pretty=format:"%s" ${mergeBase}..HEAD`)
27
- .toString()
28
- .trim();
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
- export const getCurrentBranch = () => {
4
- try {
5
- return execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
6
- }
7
- catch (error) {
8
- console.error(chalk.red("Error getting current branch:"), error);
9
- throw new Error("Failed to get current branch");
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
- export const getDefaultBranch = () => {
4
- try {
5
- // First check for a default branch set in git config
6
- try {
7
- const defaultBranch = execSync("git config init.defaultBranch")
8
- .toString()
9
- .trim();
10
- if (defaultBranch) {
11
- return defaultBranch;
12
- }
13
- }
14
- catch (error) {
15
- // Continue if git config doesn't have default branch
16
- }
17
- // Next, check if GitHub CLI can tell us the default branch
18
- try {
19
- const repoInfo = execSync("gh repo view --json defaultBranchRef --jq .defaultBranchRef.name")
20
- .toString()
21
- .trim();
22
- if (repoInfo) {
23
- return repoInfo;
24
- }
25
- }
26
- catch (error) {
27
- // Continue if gh command fails
28
- }
29
- // Try to find default branch in remote branches list
30
- const branches = execSync("git branch -r").toString().trim().split("\n");
31
- // Common default branch names, in order of likelihood
32
- const mainPatterns = [
33
- /origin\/main$/,
34
- /origin\/master$/,
35
- /origin\/develop$/,
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
- export const getStagedChanges = () => {
4
- try {
5
- return execSync("git diff --staged --function-context").toString();
6
- }
7
- catch (error) {
8
- console.error(chalk.red("Error getting staged changes:"), error);
9
- throw new Error("Failed to get staged changes");
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
- export const getStagedFiles = () => {
4
- try {
5
- const result = execSync("git diff --staged --name-only").toString();
6
- return result.split("\n").filter(Boolean);
7
- }
8
- catch (error) {
9
- console.error(chalk.red("Error getting staged files:"), error);
10
- throw new Error("Failed to get staged files");
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
- export const hasStagedChanges = () => {
3
- try {
4
- const output = execSync('git diff --staged --quiet || echo "has-changes"').toString();
5
- return output.includes("has-changes");
6
- }
7
- catch (error) {
8
- return true; // Assume there are changes if we can't check
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
- export const git = {
13
- add: executeGitAdd,
14
- commit: executeGitCommit,
15
- getChangedFiles,
16
- getCommitsSinceBaseBranch,
17
- getCurrentBranch,
18
- getDefaultBranch,
19
- hasStagedChanges,
20
- getStagedChanges,
21
- getStagedFiles,
22
- isAvailable,
23
- isGitRepository,
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
- export const isAvailable = () => {
3
- try {
4
- execSync("git --version", { stdio: "ignore" });
5
- return true;
6
- }
7
- catch (error) {
8
- return false;
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
- export const isGitRepository = () => {
3
- try {
4
- execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore" });
5
- return true;
6
- }
7
- catch (error) {
8
- return false;
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 };
@@ -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
- * Check if a commitlint configuration exists in the repository
6
- */
7
- export function hasCommitlintConfig() {
8
- const possibleConfigFiles = [
9
- ".commitlintrc",
10
- ".commitlintrc.json",
11
- ".commitlintrc.yaml",
12
- ".commitlintrc.yml",
13
- ".commitlintrc.js",
14
- "commitlint.config.js",
15
- "package.json",
16
- ];
17
- // Temporary
18
- readCommitlintConfig();
19
- // Check if any of the possible config files exist
20
- return possibleConfigFiles.some((file) => {
21
- try {
22
- if (file === "package.json") {
23
- const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
24
- return packageJson.commitlint !== undefined;
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
- * Read commitlint config file (using @commitlint/load) and print it out
35
- */
36
- export async function readCommitlintConfig() {
37
- const config = await loadConfig();
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
- * Get the commitlint configuration format rules as a string
43
- */
44
- export function getCommitlintRules() {
45
- try {
46
- // Try to get the rules using commitlint CLI if available
47
- try {
48
- const rulesOutput = execSync("npx commitlint --print-config", {
49
- stdio: ["ignore", "pipe", "ignore"],
50
- }).toString();
51
- const config = JSON.parse(rulesOutput);
52
- return formatCommitlintRules(config);
53
- }
54
- catch (error) {
55
- // If CLI approach fails, try to find and parse config files manually
56
- // This is a simplified approach - in a real implementation, you'd want to handle
57
- // all possible config files and formats
58
- if (fs.existsSync("commitlint.config.js")) {
59
- // We can't directly require the JS file in ESM, so we'll return a generic message
60
- return "Follow the conventional commit format (type(scope): message)";
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
- * Format commitlint rules into a human-readable string
77
- */
56
+ * Format commitlint rules into a human-readable string
57
+ */
78
58
  function formatCommitlintRules(config) {
79
- let rulesDescription = "Follow these commit message rules:\n";
80
- if (!config.rules) {
81
- return "Follow the conventional commit format (type(scope): message)";
82
- }
83
- // Extract type-enum rule if it exists
84
- if (config.rules["type-enum"] &&
85
- Array.isArray(config.rules["type-enum"][2])) {
86
- const allowedTypes = config.rules["type-enum"][2];
87
- rulesDescription += `- Commit type must be one of: ${allowedTypes.join(", ")}\n`;
88
- }
89
- // Extract other common rules
90
- if (config.rules["scope-enum"] &&
91
- Array.isArray(config.rules["scope-enum"][2])) {
92
- const allowedScopes = config.rules["scope-enum"][2];
93
- rulesDescription += `- Scope must be one of: ${allowedScopes.join(", ")}\n`;
94
- }
95
- if (config.rules["subject-case"]) {
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
- * Validate a commit message against commitlint rules
108
- * @param message The commit message to validate
109
- * @returns An object with success status and error message if applicable
110
- */
111
- export async function validateCommitMessage(message) {
112
- if (!hasCommitlintConfig()) {
113
- // If no commitlint config exists, consider it valid
114
- return { valid: true };
115
- }
116
- // Using CLI approach
117
- try {
118
- // Create a temporary file with the message
119
- const tempFile = `/tmp/gitpt-commit-msg-${Date.now()}`;
120
- fs.writeFileSync(tempFile, message);
121
- try {
122
- execSync(`npx commitlint < ${tempFile}`, { stdio: "ignore" });
123
- fs.unlinkSync(tempFile);
124
- return { valid: true };
125
- }
126
- catch (error) {
127
- // It's likely a validation error, capture the output
128
- try {
129
- const errorOutput = execSync(`npx commitlint < ${tempFile} 2>&1 || true`).toString();
130
- fs.unlinkSync(tempFile);
131
- return {
132
- valid: false,
133
- errors: errorOutput,
134
- };
135
- }
136
- catch (e) {
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
- export const formatBaseURL = (baseURL) => {
2
- // If it doesn't end with /v1, add it
3
- if (!baseURL.endsWith("/v1")) {
4
- return `${baseURL}/v1`;
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 };
@@ -1,8 +1,7 @@
1
- export const maskApiKey = (apiKey) => {
2
- if (apiKey.length <= 10) {
3
- return "*".repeat(apiKey.length);
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 };