codeant-cli 0.3.3 → 0.3.5

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 (76) hide show
  1. package/package.json +8 -10
  2. package/src/commands/getBaseUrl.js +21 -0
  3. package/src/commands/login.js +120 -0
  4. package/src/commands/logout.js +30 -0
  5. package/src/commands/review.js +294 -0
  6. package/src/commands/secrets.js +107 -0
  7. package/src/commands/setBaseUrl.js +37 -0
  8. package/src/components/ReviewUI.js +410 -0
  9. package/src/components/SecretsUI.js +366 -0
  10. package/src/components/Welcome.js +144 -0
  11. package/src/index.js +390 -0
  12. package/src/reviewHeadless.js +198 -0
  13. package/src/rules/secrets.toml +4994 -0
  14. package/src/scm/azure/client.js +21 -0
  15. package/src/scm/azure/getCodeReview.js +20 -0
  16. package/src/scm/azure/getPullRequest.js +30 -0
  17. package/src/scm/azure/index.js +7 -0
  18. package/src/scm/azure/listCodeReviews.js +17 -0
  19. package/src/scm/azure/listPullRequestComments.js +41 -0
  20. package/src/scm/azure/listPullRequests.js +26 -0
  21. package/src/scm/azure/resolveConversation.js +22 -0
  22. package/src/scm/azure/searchComments.js +35 -0
  23. package/src/scm/bitbucket/client.js +18 -0
  24. package/src/scm/bitbucket/getCodeReview.js +3 -0
  25. package/src/scm/bitbucket/getPullRequest.js +26 -0
  26. package/src/scm/bitbucket/index.js +7 -0
  27. package/src/scm/bitbucket/listCodeReviews.js +17 -0
  28. package/src/scm/bitbucket/listPullRequestComments.js +33 -0
  29. package/src/scm/bitbucket/listPullRequests.js +33 -0
  30. package/src/scm/bitbucket/resolveConversation.js +21 -0
  31. package/src/scm/bitbucket/searchComments.js +29 -0
  32. package/src/scm/github/client.js +17 -0
  33. package/src/scm/github/getCodeReview.js +26 -0
  34. package/src/scm/github/getPullRequest.js +27 -0
  35. package/src/scm/github/index.js +7 -0
  36. package/src/scm/github/listCodeReviews.js +17 -0
  37. package/src/scm/github/listPullRequestComments.js +51 -0
  38. package/src/scm/github/listPullRequests.js +32 -0
  39. package/src/scm/github/resolveConversation.js +85 -0
  40. package/src/scm/github/searchComments.js +30 -0
  41. package/src/scm/gitlab/client.js +16 -0
  42. package/src/scm/gitlab/getCodeReview.js +18 -0
  43. package/src/scm/gitlab/getPullRequest.js +24 -0
  44. package/src/scm/gitlab/index.js +7 -0
  45. package/src/scm/gitlab/listCodeReviews.js +21 -0
  46. package/src/scm/gitlab/listPullRequestComments.js +44 -0
  47. package/src/scm/gitlab/listPullRequests.js +26 -0
  48. package/src/scm/gitlab/resolveConversation.js +14 -0
  49. package/src/scm/gitlab/searchComments.js +28 -0
  50. package/src/scm/index.js +97 -0
  51. package/src/tools/executeTool.js +31 -0
  52. package/src/tools/globTool.js +9 -0
  53. package/src/tools/grepTool.js +18 -0
  54. package/src/tools/lsTool.js +7 -0
  55. package/src/tools/readTool.js +12 -0
  56. package/src/utils/analytics.js +56 -0
  57. package/src/utils/baseUrl.js +11 -0
  58. package/src/utils/commonApiHelper.js +143 -0
  59. package/src/utils/config.js +42 -0
  60. package/src/utils/fetchApi.js +39 -0
  61. package/src/utils/gitDiffHelper.js +1203 -0
  62. package/src/utils/reviewApiHelper.js +291 -0
  63. package/src/utils/scmAuth.js +136 -0
  64. package/src/utils/secretsApiHelper.js +252 -0
  65. package/src/utils/secretsDetector.js +210 -0
  66. package/dist/178.index.js +0 -1
  67. package/dist/239.index.js +0 -1
  68. package/dist/701.index.js +0 -1
  69. package/dist/880.index.js +0 -1
  70. package/dist/935.index.js +0 -1
  71. package/dist/966.index.js +0 -1
  72. package/dist/index.js +0 -28
  73. package/dist/package.json +0 -1
  74. package/dist/review/239.index.js +0 -1
  75. package/dist/review/index.js +0 -8
  76. package/dist/review/package.json +0 -3
@@ -0,0 +1,143 @@
1
+ import GitDiffHelper from './gitDiffHelper.js';
2
+
3
+ /**
4
+ * Common base class for API helpers that transform git diff data
5
+ * Contains shared functionality for filtering and retrieving files
6
+ */
7
+ class CommonApiHelper {
8
+ constructor(workspacePath) {
9
+ this.workspacePath = workspacePath;
10
+ this.gitHelper = new GitDiffHelper(workspacePath);
11
+ }
12
+
13
+ async init() {
14
+ await this.gitHelper.init();
15
+ }
16
+
17
+ /**
18
+ * Get staged files formatted for the API
19
+ * This is used for pre-commit hooks
20
+ */
21
+ async getStagedFilesForApi() {
22
+ const diffs = await this.gitHelper.getDiffBasedOnReviewConfig({ type: 'staged-only' });
23
+ return this._transformDiffsToApiFormat(diffs);
24
+ }
25
+
26
+ /**
27
+ * Get all changed files formatted for the API
28
+ */
29
+ async getChangedFilesForApi() {
30
+ const diffs = await this.gitHelper.getDiffBasedOnReviewConfig({ type: 'branch-diff' });
31
+ return this._transformDiffsToApiFormat(diffs);
32
+ }
33
+
34
+ /**
35
+ * Get uncommitted files formatted for the API
36
+ */
37
+ async getUncommittedFilesForApi() {
38
+ const diffs = await this.gitHelper.getDiffBasedOnReviewConfig({ type: 'uncommitted' });
39
+ return this._transformDiffsToApiFormat(diffs);
40
+ }
41
+
42
+ /**
43
+ * Get last commit files formatted for the API
44
+ */
45
+ async getLastCommitFilesForApi() {
46
+ const diffs = await this.gitHelper.getDiffBasedOnReviewConfig({ type: 'last-commit' });
47
+ return this._transformDiffsToApiFormat(diffs);
48
+ }
49
+
50
+ /**
51
+ * Get last n commits files formatted for the API
52
+ * @param {number} n - Number of commits to include
53
+ */
54
+ async getLastNCommitsFilesForApi(n = 1) {
55
+ const diffs = await this.gitHelper.getDiffBasedOnReviewConfig({
56
+ type: 'last-n-commits',
57
+ commits: n
58
+ });
59
+
60
+ return this._transformDiffsToApiFormat(diffs);
61
+ }
62
+
63
+ /**
64
+ * Transform diff info array to API format
65
+ * Must be implemented by subclasses
66
+ */
67
+ _transformDiffsToApiFormat(diffs) {
68
+ throw new Error('_transformDiffsToApiFormat must be implemented by subclass');
69
+ }
70
+
71
+
72
+ /**
73
+ * Get committed (unpushed) files formatted for the API
74
+ */
75
+ async getCommittedFilesForApi() {
76
+ const diffs = await this.gitHelper.getDiffBasedOnReviewConfig({ type: 'committed' });
77
+ return this._transformDiffsToApiFormat(diffs);
78
+ }
79
+
80
+ /**
81
+ * Get all changes (committed + uncommitted) formatted for the API
82
+ */
83
+ async getAllChangesForApi() {
84
+ const diffs = await this.gitHelper.getDiffBasedOnReviewConfig({ type: 'all' });
85
+ return this._transformDiffsToApiFormat(diffs);
86
+ }
87
+
88
+ /**
89
+ * Get diff against a specific base branch formatted for the API
90
+ */
91
+ async getBaseBranchDiffForApi(branch) {
92
+ const diffs = await this.gitHelper.getDiffBasedOnReviewConfig({ type: 'base-branch', baseBranch: branch });
93
+ return this._transformDiffsToApiFormat(diffs);
94
+ }
95
+
96
+ /**
97
+ * Get diff against a specific base commit formatted for the API
98
+ */
99
+ async getBaseCommitDiffForApi(commit) {
100
+ const diffs = await this.gitHelper.getDiffBasedOnReviewConfig({ type: 'base-commit', baseCommit: commit });
101
+ return this._transformDiffsToApiFormat(diffs);
102
+ }
103
+
104
+ /**
105
+ * Get files based on scan type
106
+ * Returns the raw array - child classes handle filtering and wrapping
107
+ * @param {string} type - Type of scan (staged-only, branch-diff, etc.)
108
+ * @param {Object} options - Additional options
109
+ * @param {number} options.lastNCommits - Number of commits for last-n-commits type
110
+ * @param {string} options.baseBranch - Base branch for base-branch type
111
+ * @param {string} options.baseCommit - Base commit for base-commit type
112
+ */
113
+ async getFilesForType(type = 'all', options = {}) {
114
+ switch (type) {
115
+ case 'staged-only':
116
+ return await this.getStagedFilesForApi();
117
+ case 'branch-diff':
118
+ return await this.getChangedFilesForApi();
119
+ case 'uncommitted':
120
+ return await this.getUncommittedFilesForApi();
121
+ case 'committed':
122
+ return await this.getCommittedFilesForApi();
123
+ case 'all':
124
+ return await this.getAllChangesForApi();
125
+ case 'last-commit':
126
+ return await this.getLastCommitFilesForApi();
127
+ case 'last-n-commits':
128
+ return await this.getLastNCommitsFilesForApi(options.lastNCommits || 1);
129
+ case 'base-branch':
130
+ return await this.getBaseBranchDiffForApi(options.baseBranch);
131
+ case 'base-commit':
132
+ return await this.getBaseCommitDiffForApi(options.baseCommit);
133
+ default:
134
+ return await this.getAllChangesForApi();
135
+ }
136
+ }
137
+
138
+ getGitRoot() {
139
+ return this.gitHelper.getGitRoot();
140
+ }
141
+ }
142
+
143
+ export default CommonApiHelper;
@@ -0,0 +1,42 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import os from 'os';
4
+
5
+ const CONFIG_DIR = path.join(os.homedir(), '.codeant');
6
+ const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
7
+
8
+ const ensureConfigDir = () => {
9
+ if (!fs.existsSync(CONFIG_DIR)) {
10
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
11
+ }
12
+ };
13
+
14
+ const loadConfig = () => {
15
+ try {
16
+ if (fs.existsSync(CONFIG_FILE)) {
17
+ const data = fs.readFileSync(CONFIG_FILE, 'utf-8');
18
+ return JSON.parse(data);
19
+ }
20
+ } catch (err) {
21
+ console.error('Error loading config:', err.message);
22
+ }
23
+ return {};
24
+ };
25
+
26
+ const saveConfig = (config) => {
27
+ ensureConfigDir();
28
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
29
+ };
30
+
31
+ const getConfigValue = (key) => {
32
+ const config = loadConfig();
33
+ return config[key];
34
+ };
35
+
36
+ const setConfigValue = (key, value) => {
37
+ const config = loadConfig();
38
+ config[key] = value;
39
+ saveConfig(config);
40
+ };
41
+
42
+ export { loadConfig, saveConfig, getConfigValue, setConfigValue, CONFIG_FILE };
@@ -0,0 +1,39 @@
1
+ import { getConfigValue } from './config.js';
2
+ import { getBaseUrl } from './baseUrl.js';
3
+
4
+ const fetchApi = async (endpoint, method = 'GET', body = null) => {
5
+ const url = endpoint.startsWith('http') ? endpoint : `${getBaseUrl()}${endpoint}`;
6
+
7
+ const options = {
8
+ method,
9
+ headers: {
10
+ 'Content-Type': 'application/json',
11
+ },
12
+ };
13
+
14
+ // Add auth token from config or env
15
+ const token = process.env.CODEANT_API_TOKEN || getConfigValue('apiKey');
16
+ if (token) {
17
+ options.headers['Authorization'] = `Bearer ${token}`;
18
+ }
19
+
20
+ if (body && method !== 'GET') {
21
+ options.body = JSON.stringify(body);
22
+ }
23
+
24
+ try {
25
+ const response = await fetch(url, options);
26
+ const data = await response.json();
27
+
28
+ if (!response.ok) {
29
+ throw new Error(data.message || `HTTP error ${response.status}`);
30
+ }
31
+
32
+ return data;
33
+ } catch (err) {
34
+ console.error(`API Error: ${err.message}`);
35
+ throw err;
36
+ }
37
+ };
38
+
39
+ export { fetchApi };