@codacy/gate-cli 0.4.1 → 0.5.0

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 (2) hide show
  1. package/bin/gate.js +16 -13
  2. package/package.json +1 -1
package/bin/gate.js CHANGED
@@ -11563,23 +11563,26 @@ function narrowToRecent(files) {
11563
11563
  });
11564
11564
  return recent.length > 0 ? recent : files;
11565
11565
  }
11566
- function readIteration(currentCommit) {
11566
+ function readIteration(currentCommit, contentHash) {
11567
11567
  if (!(0, import_node_fs4.existsSync)(ITERATION_FILE)) return 1;
11568
11568
  try {
11569
11569
  const stored = (0, import_node_fs4.readFileSync)(ITERATION_FILE, "utf-8").trim();
11570
- const [iterStr, storedCommit] = stored.split(":");
11571
- const iter = parseInt(iterStr, 10);
11570
+ const parts = stored.split(":");
11571
+ const iter = parseInt(parts[0], 10);
11572
+ const storedCommit = parts[1] ?? "";
11573
+ const storedContentHash = parts[2] ?? "";
11572
11574
  if (isNaN(iter)) return 1;
11573
- if (storedCommit === currentCommit) return iter;
11574
- return 1;
11575
+ if (storedCommit !== currentCommit) return 1;
11576
+ if (contentHash && storedContentHash && storedContentHash !== contentHash) return 1;
11577
+ return iter;
11575
11578
  } catch {
11576
11579
  return 1;
11577
11580
  }
11578
11581
  }
11579
- function checkMaxIterations(currentCommit, maxIterations = MAX_ITERATIONS) {
11580
- const iteration = readIteration(currentCommit);
11582
+ function checkMaxIterations(currentCommit, maxIterations = MAX_ITERATIONS, contentHash) {
11583
+ const iteration = readIteration(currentCommit, contentHash);
11581
11584
  if (iteration > maxIterations) {
11582
- (0, import_node_fs4.writeFileSync)(ITERATION_FILE, `1:${currentCommit}`);
11585
+ writeIteration(1, currentCommit, contentHash);
11583
11586
  return {
11584
11587
  skip: `Max gate iterations (${maxIterations}) reached \u2014 accepting to prevent infinite loop. Human review required before deploying.`,
11585
11588
  iteration
@@ -11587,9 +11590,9 @@ function checkMaxIterations(currentCommit, maxIterations = MAX_ITERATIONS) {
11587
11590
  }
11588
11591
  return { skip: null, iteration };
11589
11592
  }
11590
- function writeIteration(iteration, commit) {
11593
+ function writeIteration(iteration, commit, contentHash) {
11591
11594
  (0, import_node_fs4.mkdirSync)(GATE_DIR, { recursive: true });
11592
- (0, import_node_fs4.writeFileSync)(ITERATION_FILE, `${iteration}:${commit}`);
11595
+ (0, import_node_fs4.writeFileSync)(ITERATION_FILE, `${iteration}:${commit}:${contentHash ?? ""}`);
11593
11596
  }
11594
11597
 
11595
11598
  // src/lib/static-analysis.ts
@@ -11871,7 +11874,7 @@ async function runAnalyze(opts, globals) {
11871
11874
  }
11872
11875
  const currentCommit = getCurrentCommit();
11873
11876
  const maxIterations = parseInt(opts.maxIterations, 10);
11874
- const { skip: iterSkip, iteration } = checkMaxIterations(currentCommit, maxIterations);
11877
+ const { skip: iterSkip, iteration } = checkMaxIterations(currentCommit, maxIterations, contentHash ?? void 0);
11875
11878
  if (iterSkip) passAndExit(iterSkip);
11876
11879
  const requestBody = {
11877
11880
  static_results: staticResults,
@@ -11922,7 +11925,7 @@ async function runAnalyze(opts, globals) {
11922
11925
  const decision = response.gate_decision ?? "PASS";
11923
11926
  switch (decision) {
11924
11927
  case "FAIL": {
11925
- writeIteration(iteration + 1, currentCommit);
11928
+ writeIteration(iteration + 1, currentCommit, contentHash ?? void 0);
11926
11929
  const assessment = response.assessment;
11927
11930
  const narrative = assessment?.narrative ?? "";
11928
11931
  const findings = response.findings ?? [];
@@ -11979,7 +11982,7 @@ async function runAnalyze(opts, globals) {
11979
11982
  break;
11980
11983
  }
11981
11984
  case "PASS": {
11982
- writeIteration(1, currentCommit);
11985
+ writeIteration(1, currentCommit, contentHash ?? void 0);
11983
11986
  if (contentHash) recordPassHash(contentHash);
11984
11987
  let userSummary = response.user_summary ?? "GATE.md: PASS";
11985
11988
  const viewUrl = response.view_url ?? "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codacy/gate-cli",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "CLI for GATE.md quality gate service",
5
5
  "bin": {
6
6
  "gate": "./bin/gate.js"