@zohodesk/codestandard-validator 1.1.3 → 1.2.4-exp-1

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.
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+
3
+ var _process;
4
+ const {
5
+ execSync
6
+ } = require('child_process');
7
+ const {
8
+ getModifiedLines
9
+ } = require('@zohodesk/codestandard-analytics');
10
+ const {
11
+ getBranchName
12
+ } = require('../utils/GitActions/gitActions');
13
+ const Logger = console;
14
+ const path = require('path');
15
+ const gitEndPoint = 'https://zgit.csez.zohocorpin.com';
16
+ const compareBranch = ((_process = process) === null || _process === void 0 || (_process = _process.env) === null || _process === void 0 ? void 0 : _process.CHUNK_BRANCH) || 'release';
17
+ const configPath = path.resolve(process.cwd(), 'lint.config.js');
18
+ function getGitProjectId() {
19
+ try {
20
+ const config = require(configPath);
21
+ return config.projectId;
22
+ } catch (err) {
23
+ Logger.log(`Failed to Fetch Chunk Details`);
24
+ process.exit(1);
25
+ }
26
+ }
27
+ const projectId = getGitProjectId();
28
+ const token = process.env.ZGIT_TOKEN;
29
+ const shouldEnable = parserBoolean(process.env.SHOULD_ENABLE_CHUNK);
30
+ function isTestOrUATFile(file) {
31
+ const f = file.replace(/\\/g, "/");
32
+ if (f.endsWith(".spec.js") || f.endsWith(".test.js") || f.endsWith(".spec.ts") || f.endsWith(".test.ts") || f.endsWith(".feature") || f.endsWith(".properties")) {
33
+ return true;
34
+ }
35
+
36
+ // UAT folder check
37
+ if (f.includes("/uat/")) {
38
+ return true;
39
+ }
40
+ return false;
41
+ }
42
+ function parserBoolean(value) {
43
+ let defaultValue = false;
44
+ if (value == null || value == undefined) {
45
+ return defaultValue;
46
+ }
47
+ let AcceptedCase = new Set(["true", true]);
48
+ return AcceptedCase.has(value);
49
+ }
50
+ function requestUtilsCLI(command) {
51
+ return execSync(command, {
52
+ shell: true
53
+ });
54
+ }
55
+ function createBranchDiffChunk(branchName) {
56
+ var command;
57
+ const endPoint = `${gitEndPoint}/api/v4/projects/${projectId.toString()}/repository/compare?from=${compareBranch}&to=${branchName}`;
58
+ try {
59
+ command = `curl --header "PRIVATE-TOKEN:${token}" "${endPoint}"`;
60
+ return parserReleaseDiffRemoteAPI(JSON.parse(requestUtilsCLI(command).toString('utf-8')));
61
+ } catch (error) {
62
+ Logger.log(error);
63
+ Logger.log(`\n INFO : If you are using a VPN and encounter an SSL certification issue, ensure that the proxy is enabled for SSH and shell connections.`);
64
+ Logger.log(`\n Make sure that you have access to this repository`);
65
+ }
66
+ }
67
+ function parserReleaseDiffRemoteAPI(rawresponse) {
68
+ var formatted = [];
69
+ if (rawresponse !== null && rawresponse !== void 0 && rawresponse.diffs) {
70
+ formatted = rawresponse.diffs.map(changeset => {
71
+ if (isTestOrUATFile(changeset.new_path)) {
72
+ return null;
73
+ }
74
+ const {
75
+ modifiedLines,
76
+ removedLines
77
+ } = getModifiedLines(changeset.diff);
78
+ chunkSize.$modifieldLines += modifiedLines.length;
79
+ chunkSize.$removedLines += removedLines.length;
80
+ return {
81
+ file: changeset.new_path,
82
+ diff: {
83
+ modifiedLines,
84
+ removedLines
85
+ }
86
+ };
87
+ }).filter(item => item !== null);
88
+ }
89
+ return formatted;
90
+ }
91
+ function parseCombinedDiff(combinedDiffString) {
92
+ if (!combinedDiffString) {
93
+ return [];
94
+ }
95
+ const fileDiffChunks = combinedDiffString.split(/(?=diff --git a\/)/g);
96
+ const structuredDiffs = fileDiffChunks.map(chunk => {
97
+ const fileHeaderMatch = chunk.match(/^diff --git a\/(.*?) b\/(.*?)\n/);
98
+ if (!fileHeaderMatch) {
99
+ return null;
100
+ }
101
+ const filePath = fileHeaderMatch[1];
102
+ if (isTestOrUATFile(filePath)) {
103
+ return null;
104
+ }
105
+ const {
106
+ modifiedLines,
107
+ removedLines
108
+ } = getModifiedLines(chunk.trim());
109
+ chunkSize.$modifieldLines += modifiedLines.length;
110
+ chunkSize.$removedLines += removedLines.length;
111
+ return {
112
+ file: filePath,
113
+ diff: {
114
+ modifiedLines,
115
+ removedLines
116
+ }
117
+ };
118
+ }).filter(item => item !== null);
119
+ return structuredDiffs;
120
+ }
121
+ function runGitCommand(command) {
122
+ try {
123
+ const output = execSync(command, {
124
+ cwd: process.cwd(),
125
+ encoding: 'utf8',
126
+ stdio: ['pipe', 'pipe', 'ignore'],
127
+ maxBuffer: 10 * 1024 * 1024
128
+ }).trim();
129
+ return parseCombinedDiff(output);
130
+ } catch (error) {
131
+ if (error.status === 128) {
132
+ return `ERROR: Git error executing command: '${command}'. Ensure you are in a Git repository and all references exist.`;
133
+ }
134
+ return undefined;
135
+ }
136
+ }
137
+ function getGitChangesets(currentBranch, releaseBranch, upstreamRemote = 'origin') {
138
+ const stagedDiffCommand = 'git diff --staged';
139
+ const stagedChangeset = {
140
+ git_command: stagedDiffCommand,
141
+ description: 'Changes staged in the index, ready to be committed.',
142
+ actual_output: runGitCommand(stagedDiffCommand)
143
+ };
144
+ const releaseComparison = {
145
+ git_command: "giff diff with release",
146
+ description: `Total difference between the tip of branch '${currentBranch}' and the tip of reference '${releaseBranch}'.`,
147
+ actual_output: createBranchDiffChunk(currentBranch)
148
+ };
149
+ const unpushedDiffCommand = `git diff ${upstreamRemote}/${currentBranch}...HEAD`;
150
+ const unpushedChangeset = {
151
+ git_command: unpushedDiffCommand,
152
+ description: `Changes from all local commits that have not been pushed (diff since common ancestor of HEAD and its upstream).`,
153
+ actual_output: runGitCommand(unpushedDiffCommand)
154
+ };
155
+ return {
156
+ stagedChangeset,
157
+ releaseComparison,
158
+ unpushedChangeset
159
+ };
160
+ }
161
+ if (shouldEnable) {
162
+ const myCurrentBranch = getBranchName();
163
+ const targetRelease = process.env.CHUNK_BRANCH || 'release';
164
+ const chunk_size_env = Number(process.env.CHUNK_SIZE) || 800;
165
+ const remoteName = 'origin';
166
+ const Logger = console;
167
+ const RED = '\x1b[31m';
168
+ const GREEN = '\x1b[32m';
169
+ const RESET = '\x1b[0m';
170
+ (async function () {
171
+ Logger.log(`******************************** Experimental Phase Calculation Chunk Size ********************************`);
172
+ if (!(globalThis !== null && globalThis !== void 0 && globalThis.chunkSize)) {
173
+ globalThis.chunkSize = {
174
+ $modifieldLines: 0,
175
+ $removedLines: 0
176
+ };
177
+ try {
178
+ await getGitChangesets(myCurrentBranch, targetRelease, remoteName);
179
+ if (chunkSize.$modifieldLines <= chunk_size_env) {
180
+ Logger.log(`${GREEN}Your Chunk was ${chunkSize.$modifieldLines} and remaining size ${chunk_size_env - chunkSize.$modifieldLines}${RESET}`);
181
+ } else {
182
+ Logger.log(`${RED}Your Chunk was ${chunkSize.$modifieldLines} which exceeded the allowed limit ${chunk_size_env} ${RESET}`);
183
+ // process.exit(1)
184
+ }
185
+ } catch (e) {
186
+ console.log(e);
187
+ Logger.error("Execution failed. Ensure you are running this in a Node.js environment with the 'child_process' module and 'git' installed.");
188
+ Logger.error(e.message);
189
+ }
190
+ Logger.log(`*************************************************************************************`);
191
+ }
192
+ })();
193
+ }
@@ -102,14 +102,7 @@ async function runLintWorkflow(files, branch) {
102
102
  const execute = new Execution(EsLint, SonarQube, cliobj);
103
103
  await execute.executeLintHandler().finally(async () => {
104
104
  await execute.executeMetricHandler();
105
- /**
106
- * global.analytics.totalIssues = global.analytics.totalIssues + 1;
107
- global.analytics.status = "FAILURE";
108
- global.analytics.message = 'Issues are detected, please review and resolve the errors'
109
- */
110
- // const { issues, hasIssue, totalIssues } = fetchProjectIssuesViaCurl("projectName");
111
105
  });
112
- // Logger.log(Logger.INFO_TYPE,global.analytics)
113
106
  return global.analytics.status == 'FAILURE' ? true : false;
114
107
  }
115
108
  module.exports = {
@@ -17,9 +17,6 @@ const {
17
17
  const {
18
18
  Logger
19
19
  } = require('../../utils/Logger/Logger');
20
- const {
21
- checkIfPluginsAreInstalled
22
- } = require('../../utils/PluginsInstallation/checkIfPluginsAreInstalled');
23
20
  const {
24
21
  getBranchName
25
22
  } = require('../../utils/GitActions/gitActions');
@@ -189,15 +186,6 @@ async function calculateGitDiffForFile(branch_name, file) {
189
186
  });
190
187
  });
191
188
  }
192
- /**
193
- * @function {areAllPluginsInstalled} - method whether plugin is installed or not
194
- * @returns {Boolean} - return boolean based on plugin installed or not
195
- */
196
-
197
- function areAllPluginsInstalled() {
198
- let unInstalledPlugins = checkIfPluginsAreInstalled().uninstalledPlugins;
199
- return unInstalledPlugins.length === 0 ? true : false;
200
- }
201
189
 
202
190
  /**
203
191
  * @function {isOnlyWarningsPresentInFile} - method that checks if only eslint warnings are present in a file
@@ -226,143 +214,136 @@ async function preCommitHook_default() {
226
214
  Logger.log(Logger.INFO_TYPE, 'Looks like you have merged. So skipping pre commit check');
227
215
  process.exit(0);
228
216
  } catch (error) {
229
- if (areAllPluginsInstalled()) {
230
- let staged_files = [];
231
- let eslintConfigFiles = ['.eslintrc.js'];
232
- let exemptionFiles = [];
233
- let current_branch = '';
234
- let hasEslintErrorsInChangedLines = false;
235
- let hasEslintErrorsInFiles = false;
236
- let areFilesStaged = false;
237
- let shouldAbortCommit = false;
238
- try {
239
- current_branch = await getBranchName();
240
- } catch {
241
- Logger.log(Logger.INFO_TYPE, "Error fetching current branch");
242
- }
243
- try {
244
- staged_files = await getStagedFiles();
245
- if (!staged_files.length == 0) {
246
- const {
247
- JsFiles: staged_filesJS,
248
- CssFiles
249
- } = filterFiles(staged_files, eslintConfigFiles, true);
217
+ let staged_files = [];
218
+ let eslintConfigFiles = ['.eslintrc.js'];
219
+ let exemptionFiles = [];
220
+ let current_branch = '';
221
+ let hasEslintErrorsInChangedLines = false;
222
+ let hasEslintErrorsInFiles = false;
223
+ let areFilesStaged = false;
224
+ let shouldAbortCommit = false;
225
+ try {
226
+ current_branch = await getBranchName();
227
+ } catch {
228
+ Logger.log(Logger.INFO_TYPE, "Error fetching current branch");
229
+ }
230
+ try {
231
+ staged_files = await getStagedFiles();
232
+ if (!staged_files.length == 0) {
233
+ const {
234
+ JsFiles: staged_filesJS,
235
+ CssFiles
236
+ } = filterFiles(staged_files, eslintConfigFiles, true);
250
237
 
251
- // staged_filesJS = filterFiles(staged_filesJS,exemptionFiles) //this is the code for giving exemption to a file during pre commit
252
- // if(staged_filesJS.length === 0){
253
- // Logger.log(Logger.SUCCESS_TYPE,`Commit Successful`)
254
- // process.exit(0)
255
- // }
238
+ // staged_filesJS = filterFiles(staged_filesJS,exemptionFiles) //this is the code for giving exemption to a file during pre commit
239
+ // if(staged_filesJS.length === 0){
240
+ // Logger.log(Logger.SUCCESS_TYPE,`Commit Successful`)
241
+ // process.exit(0)
242
+ // }
256
243
 
257
- // CssFiles not Enabled For while
258
- areFilesStaged = true;
259
- var stagedFiles = [...staged_filesJS];
260
- for (let file in stagedFiles) {
261
- let currentFileName = stagedFiles[file];
262
- let changedLinesArray = [];
263
- let eslintErrorsInChangedLines = new Set();
264
- let isOnlyEslintWarningsPresentInFile = false;
265
- if (getSupportedLanguage().includes(path.extname(stagedFiles[file]))) {
266
- try {
267
- var errorsInFile = await lintFiles(stagedFiles[file]);
268
- // eslintErrorsInFile = impactBasedPrecommit == false ? filterWarningInFile(errorsInFile) : errorsInFile
269
- if (stagedFiles[file] && typeof stagedFiles[file] == 'string') {
270
- if (!errorsInFile.length == 0) {
271
- //Calculating changed lines in a file and storing them in respective arrays
272
- if (impactBasedPrecommit) {
273
- //git diff is computed and stored in an array
274
- let git_diff = await calculateGitDiffForFile(current_branch, stagedFiles[file]);
275
- changedLinesArray = git_diff.filter(line => line.startsWith('@@'));
276
- let changedLinesStartArray = [];
277
- let changedLinesEndArray = [];
278
- for (let number of changedLinesArray) {
279
- let changesStartLine = parseInt(number.split(' ')[2].split(',')[0]);
280
- changedLinesStartArray.push(changesStartLine);
281
- let changesEndLine = number.split(' ')[2].split(',')[1];
282
- if (changesEndLine === undefined) {
283
- changedLinesEndArray.push(changesStartLine);
284
- } else {
285
- changedLinesEndArray.push(changesStartLine + parseInt(changesEndLine) - 1);
286
- }
244
+ // CssFiles not Enabled For while
245
+ areFilesStaged = true;
246
+ var stagedFiles = [...staged_filesJS, ...CssFiles];
247
+ for (let file in stagedFiles) {
248
+ let currentFileName = stagedFiles[file];
249
+ let changedLinesArray = [];
250
+ let eslintErrorsInChangedLines = new Set();
251
+ let isOnlyEslintWarningsPresentInFile = false;
252
+ if (getSupportedLanguage().includes(path.extname(stagedFiles[file]))) {
253
+ try {
254
+ var errorsInFile = await lintFiles(stagedFiles[file]);
255
+ // eslintErrorsInFile = impactBasedPrecommit == false ? filterWarningInFile(errorsInFile) : errorsInFile
256
+ if (stagedFiles[file] && typeof stagedFiles[file] == 'string') {
257
+ if (!errorsInFile.length == 0) {
258
+ //Calculating changed lines in a file and storing them in respective arrays
259
+ if (impactBasedPrecommit) {
260
+ //git diff is computed and stored in an array
261
+ let git_diff = await calculateGitDiffForFile(current_branch, stagedFiles[file]);
262
+ changedLinesArray = git_diff.filter(line => line.startsWith('@@'));
263
+ let changedLinesStartArray = [];
264
+ let changedLinesEndArray = [];
265
+ for (let number of changedLinesArray) {
266
+ let changesStartLine = parseInt(number.split(' ')[2].split(',')[0]);
267
+ changedLinesStartArray.push(changesStartLine);
268
+ let changesEndLine = number.split(' ')[2].split(',')[1];
269
+ if (changesEndLine === undefined) {
270
+ changedLinesEndArray.push(changesStartLine);
271
+ } else {
272
+ changedLinesEndArray.push(changesStartLine + parseInt(changesEndLine) - 1);
287
273
  }
288
- for (let error = 1; error < errorsInFile.length - 2; error++) {
289
- //errorsInFile[error].trim() - 69:26 error => Do not hardcode content. Use I18N key instead no-hardcoding/no-hardcoding,
290
- //errorsInFile[error].trim().split(' ')[0] => 69:26
291
- //errorsInFile[error].trim().split(' ')[0].split(':')[0] => 69
274
+ }
275
+ for (let error = 1; error < errorsInFile.length - 2; error++) {
276
+ //errorsInFile[error].trim() - 69:26 error => Do not hardcode content. Use I18N key instead no-hardcoding/no-hardcoding,
277
+ //errorsInFile[error].trim().split(' ')[0] => 69:26
278
+ //errorsInFile[error].trim().split(' ')[0].split(':')[0] => 69
292
279
 
293
- let eslintErrorLineNumber = errorsInFile[error].trim().split(' ')[0].split(':')[0];
294
- if (MandatoryListRules.some(ruleId => errorsInFile[error].trim().includes(ruleId))) {
280
+ let eslintErrorLineNumber = errorsInFile[error].trim().split(' ')[0].split(':')[0];
281
+ if (MandatoryListRules.some(ruleId => errorsInFile[error].trim().includes(ruleId))) {
282
+ eslintErrorsInChangedLines.add(errorsInFile[error]);
283
+ }
284
+ for (let lineNumber in changedLinesStartArray) {
285
+ if (eslintErrorLineNumber >= changedLinesStartArray[lineNumber] && eslintErrorLineNumber <= changedLinesEndArray[lineNumber]) {
295
286
  eslintErrorsInChangedLines.add(errorsInFile[error]);
296
287
  }
297
- for (let lineNumber in changedLinesStartArray) {
298
- if (eslintErrorLineNumber >= changedLinesStartArray[lineNumber] && eslintErrorLineNumber <= changedLinesEndArray[lineNumber]) {
299
- eslintErrorsInChangedLines.add(errorsInFile[error]);
300
- }
301
- }
302
288
  }
303
- if (eslintErrorsInChangedLines.size > 0) {
304
- isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(Array.from(eslintErrorsInChangedLines));
305
- Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${currentFileName}\x1b[0m`);
306
- for (let eslintError of Array.from(eslintErrorsInChangedLines)) {
307
- Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${eslintError.trimEnd()}\x1b[0m`);
308
- }
309
- if (shouldWarningsAbortCommit) {
310
- hasEslintErrorsInChangedLines = true;
311
- shouldAbortCommit = true;
312
- } else if (!shouldWarningsAbortCommit && isOnlyEslintWarningsPresentInFile) {
313
- hasEslintErrorsInChangedLines = false;
314
- } else if (!shouldWarningsAbortCommit && !isOnlyEslintWarningsPresentInFile) {
315
- hasEslintErrorsInChangedLines = true;
316
- shouldAbortCommit = true;
317
- }
289
+ }
290
+ if (eslintErrorsInChangedLines.size > 0) {
291
+ isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(Array.from(eslintErrorsInChangedLines));
292
+ Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${currentFileName}\x1b[0m`);
293
+ for (let eslintError of Array.from(eslintErrorsInChangedLines)) {
294
+ Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${eslintError.trimEnd()}\x1b[0m`);
318
295
  }
319
- } else {
320
- if (errorsInFile.length > 0) {
321
- let startIndex = 1;
322
- let endIndex = errorsInFile.length - 2;
323
- let listOsEslintErrors = errorsInFile.slice(startIndex, endIndex);
324
- isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(listOsEslintErrors);
325
- Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${currentFileName}\x1b[0m`);
326
- for (let eslintError of listOsEslintErrors) {
327
- Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${eslintError.trimEnd()}\x1b[0m`);
328
- }
329
- if (shouldWarningsAbortCommit) {
330
- hasEslintErrorsInFiles = true;
331
- shouldAbortCommit = true;
332
- } else if (!shouldWarningsAbortCommit && isOnlyEslintWarningsPresentInFile) {
333
- hasEslintErrorsInFiles = false;
334
- } else if (!shouldWarningsAbortCommit && !isOnlyEslintWarningsPresentInFile) {
335
- hasEslintErrorsInFiles = true;
336
- shouldAbortCommit = true;
337
- }
296
+ if (shouldWarningsAbortCommit) {
297
+ hasEslintErrorsInChangedLines = true;
298
+ shouldAbortCommit = true;
299
+ } else if (!shouldWarningsAbortCommit && isOnlyEslintWarningsPresentInFile) {
300
+ hasEslintErrorsInChangedLines = false;
301
+ } else if (!shouldWarningsAbortCommit && !isOnlyEslintWarningsPresentInFile) {
302
+ hasEslintErrorsInChangedLines = true;
303
+ shouldAbortCommit = true;
304
+ }
305
+ }
306
+ } else {
307
+ if (errorsInFile.length > 0) {
308
+ let startIndex = 1;
309
+ let endIndex = errorsInFile.length - 2;
310
+ let listOsEslintErrors = errorsInFile.slice(startIndex, endIndex);
311
+ isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(listOsEslintErrors);
312
+ Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${currentFileName}\x1b[0m`);
313
+ for (let eslintError of listOsEslintErrors) {
314
+ Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${eslintError.trimEnd()}\x1b[0m`);
315
+ }
316
+ if (shouldWarningsAbortCommit) {
317
+ hasEslintErrorsInFiles = true;
318
+ shouldAbortCommit = true;
319
+ } else if (!shouldWarningsAbortCommit && isOnlyEslintWarningsPresentInFile) {
320
+ hasEslintErrorsInFiles = false;
321
+ } else if (!shouldWarningsAbortCommit && !isOnlyEslintWarningsPresentInFile) {
322
+ hasEslintErrorsInFiles = true;
323
+ shouldAbortCommit = true;
338
324
  }
339
325
  }
340
326
  }
341
327
  }
342
- } catch (err) {
343
- Logger.log(Logger.FAILURE_TYPE, err);
344
- Logger.log(Logger.FAILURE_TYPE, "Error in executing lint command");
345
328
  }
329
+ } catch (err) {
330
+ Logger.log(Logger.FAILURE_TYPE, err);
331
+ Logger.log(Logger.FAILURE_TYPE, "Error in executing lint command");
346
332
  }
347
333
  }
348
- } else if (staged_files.length === 0) {
349
- Logger.log(Logger.INFO_TYPE, 'No files have been staged. Stage your files before committing');
350
334
  }
351
- } catch {
352
- Logger.log(Logger.INFO_TYPE, 'Error executing pre commit hook');
353
- }
354
- if (shouldAbortCommit) {
355
- Logger.log(Logger.FAILURE_TYPE, `There are linter errors/warnings present. So commit is aborted.`);
356
- process.exit(1);
357
- } else if (shouldAbortCommit === false && staged_files.length !== 0) {
358
- Logger.log(Logger.SUCCESS_TYPE, `Commit Successful`);
359
- process.exit(0);
335
+ } else if (staged_files.length === 0) {
336
+ Logger.log(Logger.INFO_TYPE, 'No files have been staged. Stage your files before committing');
360
337
  }
361
- } else {
362
- Logger.log(Logger.FAILURE_TYPE, 'Commit failed since some lint plugins are not installed');
363
- Logger.log(Logger.INFO_TYPE, `Kindly execute the command \x1b[37mnpx ZDPrecommit setupPlugins \x1b[33mfrom the location where package.json is present to install the plugins`);
364
- Logger.log(Logger.INFO_TYPE, 'Execute the command and kindly try committing again.');
338
+ } catch {
339
+ Logger.log(Logger.INFO_TYPE, 'Error executing pre commit hook');
340
+ }
341
+ if (shouldAbortCommit) {
342
+ Logger.log(Logger.FAILURE_TYPE, `There are linter errors/warnings present. So commit is aborted.`);
365
343
  process.exit(1);
344
+ } else if (shouldAbortCommit === false && staged_files.length !== 0) {
345
+ Logger.log(Logger.SUCCESS_TYPE, `Commit Successful`);
346
+ process.exit(0);
366
347
  }
367
348
  }
368
349
  }
@@ -24,11 +24,12 @@ const {
24
24
  const {
25
25
  ensurePluginsInstalled
26
26
  } = require('./Precommit/guard');
27
- const config = require(path.join(process.cwd(), 'lint.config.js'));
28
- process.env.SONARQUBE_EXTERNAL = config.metric_token;
29
- process.env.SONARQUBE = config.meticHandler_api_token;
30
- process.env.ZGIT_TOKEN = config.token;
31
- process.env.TOOL_TOKEN = config.toolToken;
27
+ const {
28
+ initConfig,
29
+ getConfigPathExecute
30
+ } = require('../utils/General/Config');
31
+ require("../chunk/chunk_Restriction");
32
+ initConfig(getConfigPathExecute());
32
33
  async function hooks() {
33
34
  var jsonFilePath = path.join(__dirname, '..', '..', 'jsonUtils', 'fsUtils.json');
34
35
  let latestCommit = getLastCommitHash();
@@ -47,10 +48,10 @@ async function hooks() {
47
48
  } = getPluginsToInstall();
48
49
  await executeMethodsThatReturnBooleanValue('Some issue occurred in installing plugins', installPlugins, uninstalledPlugins);
49
50
  }
50
- if (process.env.CLIPRECOMMIT && Boolean(process.env.CLIPRECOMMIT) == true) {
51
- require('./Precommit/pre-commit-default');
52
- } else {
51
+ if (process.env.PUSHTOSONARQUBE && Boolean(process.env.PUSHTOSONARQUBE) == true) {
53
52
  require('./Precommit/commit');
53
+ } else {
54
+ require('./Precommit/pre-commit-default');
54
55
  }
55
56
  }
56
57
  hooks();
@@ -15,27 +15,23 @@ const {
15
15
  const {
16
16
  executeMethodsThatReturnBooleanValue
17
17
  } = require('../utils/General/wrapperFunctionToExecuteAFunction');
18
- const {
19
- arePluginsInstalled
20
- } = require('../utils/PluginsInstallation/arePluginsInstalled');
21
18
  const {
22
19
  isGitInitialized
23
20
  } = require('../utils/GitActions/gitActions');
24
21
  const {
25
22
  writeFsPaths
26
23
  } = require('../utils/General/writeProjectDetailsToJson');
27
- const path = require('path');
24
+ const {
25
+ initConfig,
26
+ getConfigPathPostInstall
27
+ } = require('../utils/General/Config');
28
+
28
29
  /**
29
30
  * @function {postInstall} - This methods setup husky and configuration for executing project
30
31
  * @returns {void}
31
32
  */
32
33
  async function postInstall() {
33
- var actualNodeMoulesPath = path.resolve(process.cwd(), '..', '..', '..');
34
- const config = require(path.join(actualNodeMoulesPath, 'lint.config.js'));
35
- process.env.SONARQUBE_EXTERNAL = config.metric_token;
36
- process.env.SONARQUBE = config.meticHandler_api_token;
37
- process.env.ZGIT_TOKEN = config.token;
38
- process.env.TOOL_TOKEN = config.toolToken;
34
+ initConfig(getConfigPathPostInstall());
39
35
  try {
40
36
  await executeMethodsThatReturnBooleanValue('Some issue in writing node_modules path to json', writeFsPaths, null);
41
37
  isGitInitialized() ? await executeMethodsThatReturnBooleanValue('Some issue occurred in setting up husky.', setupHusky, null) : null;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ const path = require('path');
4
+ function initConfig(actualConfigPath) {
5
+ const config = require(path.join(actualConfigPath, 'lint.config.js'));
6
+ process.env.SONARQUBE_EXTERNAL = config.metric_token;
7
+ process.env.SONARQUBE = config.meticHandler_api_token;
8
+ process.env.ZGIT_TOKEN = config.token;
9
+ process.env.TOOL_TOKEN = config.toolToken;
10
+ }
11
+ function getConfigPathPostInstall() {
12
+ return path.resolve(process.cwd(), '..', '..', '..');
13
+ }
14
+ function getConfigPathExecute() {
15
+ return path.resolve(process.cwd());
16
+ }
17
+ module.exports = {
18
+ initConfig,
19
+ getConfigPathExecute,
20
+ getConfigPathPostInstall
21
+ };
@@ -1,9 +1,5 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.encrypt = exports.decrypt = void 0;
7
3
  const caesarCipher = (str, shift) => {
8
4
  return str.split("").map(char => {
9
5
  let code = char.charCodeAt();
@@ -16,6 +12,8 @@ const caesarCipher = (str, shift) => {
16
12
  }).join("");
17
13
  };
18
14
  const encrypt = (plaintext, shift) => caesarCipher(plaintext, shift);
19
- exports.encrypt = encrypt;
20
15
  const decrypt = (ciphertext, shift) => caesarCipher(ciphertext, 26 - shift);
21
- exports.decrypt = decrypt;
16
+ module.exports = {
17
+ encrypt,
18
+ decrypt
19
+ };
@@ -78,7 +78,7 @@ async function fetchProjectIssuesViaCurl(componentKey) {
78
78
  _Logger.Logger.log(_Logger.Logger.INFO_TYPE, `\n Fetching issues (curl) for component: ${componentKey}`);
79
79
  const url = buildIssuesSearchUrl(componentKey);
80
80
  try {
81
- const token = process.env.SONARQUBE; //'sqa_1f6675c05f63c4784dc741ce751efa0066d2693c' || decrypt(getAPIToken(), ); // sonarqube
81
+ const token = process.env.SONARQUBE;
82
82
  const command = `curl --tlsv1.2 -s -u "${token}:" "${url}"`;
83
83
  const output = execSync(command).toString();
84
84
  const json = JSON.parse(output.toString());
package/changeLog.md CHANGED
@@ -41,4 +41,9 @@
41
41
 
42
42
  # 1.1.3 - SonarQube Enable
43
43
 
44
- 1. Remote Installtion flow moved to before and handled process.exit removed
44
+ 1. Remote Installtion flow moved to before and handled process.exit removed
45
+
46
+ # 1.1.4 - Minor Bug Fixes
47
+
48
+ 1. ProjectId api revamp
49
+ 2. code standard analytics bin bind to code standard validator bin
package/jest.config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
2
  testEnvironment: 'node',
3
3
  clearMocks: true,
4
- setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
4
+ setupFilesAfterEnv: ['<rootDir>/jest.setup.js']
5
5
  };