codeant-cli 0.2.0 → 0.2.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 (67) hide show
  1. package/dist/178.index.js +1 -1
  2. package/dist/239.index.js +1 -1
  3. package/dist/701.index.js +1 -1
  4. package/dist/880.index.js +1 -1
  5. package/dist/935.index.js +1 -1
  6. package/dist/966.index.js +1 -1
  7. package/dist/index.js +4 -4
  8. package/package.json +8 -2
  9. package/src/commands/getBaseUrl.js +25 -0
  10. package/src/commands/login.js +124 -0
  11. package/src/commands/logout.js +30 -0
  12. package/src/commands/review.js +271 -0
  13. package/src/commands/secrets.js +268 -0
  14. package/src/commands/securityAnalysis.js +284 -0
  15. package/src/commands/setBaseUrl.js +37 -0
  16. package/src/commands/staticAnalysis.js +405 -0
  17. package/src/components/ReviewUI.js +410 -0
  18. package/src/components/Welcome.js +144 -0
  19. package/src/index.js +398 -0
  20. package/src/reviewHeadless.js +170 -0
  21. package/src/scm/azure/client.js +21 -0
  22. package/src/scm/azure/getCodeReview.js +20 -0
  23. package/src/scm/azure/getPullRequest.js +30 -0
  24. package/src/scm/azure/index.js +6 -0
  25. package/src/scm/azure/listCodeReviews.js +17 -0
  26. package/src/scm/azure/listPullRequestComments.js +41 -0
  27. package/src/scm/azure/listPullRequests.js +26 -0
  28. package/src/scm/azure/searchComments.js +35 -0
  29. package/src/scm/bitbucket/client.js +18 -0
  30. package/src/scm/bitbucket/getCodeReview.js +3 -0
  31. package/src/scm/bitbucket/getPullRequest.js +26 -0
  32. package/src/scm/bitbucket/index.js +6 -0
  33. package/src/scm/bitbucket/listCodeReviews.js +17 -0
  34. package/src/scm/bitbucket/listPullRequestComments.js +33 -0
  35. package/src/scm/bitbucket/listPullRequests.js +33 -0
  36. package/src/scm/bitbucket/searchComments.js +29 -0
  37. package/src/scm/github/client.js +17 -0
  38. package/src/scm/github/getCodeReview.js +26 -0
  39. package/src/scm/github/getPullRequest.js +27 -0
  40. package/src/scm/github/index.js +6 -0
  41. package/src/scm/github/listCodeReviews.js +17 -0
  42. package/src/scm/github/listPullRequestComments.js +51 -0
  43. package/src/scm/github/listPullRequests.js +32 -0
  44. package/src/scm/github/searchComments.js +30 -0
  45. package/src/scm/gitlab/client.js +16 -0
  46. package/src/scm/gitlab/getCodeReview.js +18 -0
  47. package/src/scm/gitlab/getPullRequest.js +24 -0
  48. package/src/scm/gitlab/index.js +6 -0
  49. package/src/scm/gitlab/listCodeReviews.js +21 -0
  50. package/src/scm/gitlab/listPullRequestComments.js +44 -0
  51. package/src/scm/gitlab/listPullRequests.js +26 -0
  52. package/src/scm/gitlab/searchComments.js +28 -0
  53. package/src/scm/index.js +96 -0
  54. package/src/tools/executeTool.js +31 -0
  55. package/src/tools/globTool.js +9 -0
  56. package/src/tools/grepTool.js +18 -0
  57. package/src/tools/lsTool.js +7 -0
  58. package/src/tools/readTool.js +12 -0
  59. package/src/utils/commonApiHelper.js +143 -0
  60. package/src/utils/config.js +42 -0
  61. package/src/utils/fetchApi.js +42 -0
  62. package/src/utils/gitDiffHelper.js +1203 -0
  63. package/src/utils/reviewApiHelper.js +275 -0
  64. package/src/utils/scmAuth.js +136 -0
  65. package/src/utils/secretsApiHelper.js +134 -0
  66. package/src/utils/securityAnalysisApiHelper.js +119 -0
  67. package/src/utils/staticAnalysisApiHelper.js +119 -0
@@ -0,0 +1,119 @@
1
+ import CommonApiHelper from './commonApiHelper.js';
2
+ import { minimatch } from 'minimatch';
3
+
4
+ /**
5
+ * Transforms git diff data into the format expected by the static analysis API
6
+ *
7
+ * API Input Format:
8
+ * {
9
+ * "filesData": [
10
+ * {
11
+ * "file": str,
12
+ * "code": str
13
+ * }
14
+ * ]
15
+ * }
16
+ */
17
+ class StaticAnalysisApiHelper extends CommonApiHelper {
18
+ /**
19
+ * Transform diff info array to API format
20
+ * Groups by file (without diff ranges for static analysis)
21
+ */
22
+ _transformDiffsToApiFormat(diffs) {
23
+ // Group diffs by filename
24
+ const fileMap = new Map();
25
+
26
+ for (const diff of diffs) {
27
+ const filePath = diff.filename_str;
28
+
29
+ // Skip diffs with missing or invalid filename
30
+ if (!filePath) {
31
+ continue;
32
+ }
33
+
34
+ if (!fileMap.has(filePath)) {
35
+ fileMap.set(filePath, {
36
+ file: filePath,
37
+ code: diff.head_file_str || ''
38
+ });
39
+ }
40
+ }
41
+
42
+ return Array.from(fileMap.values());
43
+ }
44
+
45
+ /**
46
+ * Filter files based on include and exclude glob patterns
47
+ * @param {Array} files - Array of file objects with 'file' property
48
+ * @param {Array} includePatterns - Array of glob pattern strings to include
49
+ * @param {Array} excludePatterns - Array of glob pattern strings to exclude
50
+ */
51
+ _filterFiles(files, includePatterns = [], excludePatterns = []) {
52
+ return files.filter(fileObj => {
53
+ const filePath = fileObj.file;
54
+
55
+ // If include patterns are specified, file must match at least one
56
+ if (includePatterns.length > 0) {
57
+ const matchesInclude = includePatterns.some(pattern => {
58
+ try {
59
+ if (pattern instanceof RegExp) {
60
+ return pattern.test(filePath);
61
+ }
62
+ return minimatch(filePath, pattern, { matchBase: true });
63
+ } catch (e) {
64
+ console.warn(`Invalid include pattern: ${pattern}`, e.message);
65
+ return false;
66
+ }
67
+ });
68
+
69
+ if (!matchesInclude) {
70
+ return false;
71
+ }
72
+ }
73
+
74
+ // If exclude patterns are specified, file must not match any
75
+ if (excludePatterns.length > 0) {
76
+ const matchesExclude = excludePatterns.some(pattern => {
77
+ try {
78
+ if (pattern instanceof RegExp) {
79
+ return pattern.test(filePath);
80
+ }
81
+ return minimatch(filePath, pattern, { matchBase: true });
82
+ } catch (e) {
83
+ console.warn(`Invalid exclude pattern: ${pattern}`, e.message);
84
+ return false;
85
+ }
86
+ });
87
+
88
+ if (matchesExclude) {
89
+ return false;
90
+ }
91
+ }
92
+
93
+ return true;
94
+ });
95
+ }
96
+
97
+ /**
98
+ * Build the complete request body for the static analysis API
99
+ * @param {string} type - Type of scan (staged-only, branch-diff, etc.)
100
+ * @param {Array} includePatterns - Optional array of glob patterns to include files
101
+ * @param {Array} excludePatterns - Optional array of glob patterns to exclude files
102
+ * @param {Object} options - Additional options like lastNCommits
103
+ */
104
+ async buildStaticAnalysisApiRequest(type = 'staged-only', includePatterns = [], excludePatterns = [], options = {}) {
105
+ let files = await this.getFilesForType(type, options);
106
+
107
+ // Handle null/undefined return
108
+ if (!files || !Array.isArray(files)) {
109
+ files = [];
110
+ }
111
+
112
+ // Apply include/exclude filters
113
+ files = this._filterFiles(files, includePatterns, excludePatterns);
114
+
115
+ return { filesData: files };
116
+ }
117
+ }
118
+
119
+ export default StaticAnalysisApiHelper;