opencode-sonarqube 1.2.7 → 1.2.8

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/dist/index.js +24 -42
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -20575,68 +20575,50 @@ Fix these issues before ${operationType === "commit" ? "committing" : "pushing"}
20575
20575
  await showToast(`SonarQube: ${operationType} BLOCKED`, "error");
20576
20576
  return { block: true, message };
20577
20577
  };
20578
+ const isGitCommit = (cmd) => /git\s+commit\b/.test(cmd) && !/--amend/.test(cmd);
20579
+ const isGitPush = (cmd) => /git\s+push\b/.test(cmd);
20580
+ const processAnalysisResult = async (analysisResult, blockingSeverity, shouldBlock, fixBeforeCommit, autoFix) => {
20581
+ const passedCheck = analysisResult.qualityGateStatus === "OK" || !checkBlockingIssues(analysisResult.issues, blockingSeverity);
20582
+ if (passedCheck) {
20583
+ await showToast("SonarQube: Quality check passed!", "success");
20584
+ return { block: false };
20585
+ }
20586
+ if (fixBeforeCommit && autoFix) {
20587
+ await sendAutoFixPrompt(analysisResult);
20588
+ return { block: shouldBlock, message: "SonarQube is fixing issues. Please wait and try again." };
20589
+ }
20590
+ const warningMessage = await sendBlockingMessage(analysisResult.issues, shouldBlock, autoFix);
20591
+ return { block: shouldBlock, message: warningMessage };
20592
+ };
20578
20593
  const handleGitOperationCheck = async (output, operationType) => {
20579
- safeLog(`[handleGitOperationCheck] ENTERED operationType=${operationType}`);
20580
20594
  const args = output.args;
20581
20595
  const command = args?.command ?? "";
20582
- safeLog(`[handleGitOperationCheck] command=${command.slice(0, 80)}...`);
20583
- const isCommit = /git\s+commit\b/.test(command) && !/--amend/.test(command);
20584
- const isPush = /git\s+push\b/.test(command);
20585
- const isMatchingOperation = operationType === "commit" && isCommit || operationType === "push" && isPush;
20586
- if (!isMatchingOperation) {
20587
- safeLog(`[handleGitOperationCheck] NOT matching operation, returning block=false`);
20596
+ const isMatch = operationType === "commit" ? isGitCommit(command) : isGitPush(command);
20597
+ if (!isMatch)
20588
20598
  return { block: false };
20589
- }
20590
20599
  await loadPluginConfig();
20591
20600
  const sonarConfig = pluginConfig?.["sonarqube"];
20592
20601
  const config2 = loadConfig(sonarConfig);
20593
- safeLog(`[handleGitOperationCheck] config loaded: level=${config2?.level}, blockCommit=${config2?.blockCommit}`);
20594
- if (!config2 || config2.level === "off") {
20595
- safeLog(`[handleGitOperationCheck] config off or missing, returning block=false`);
20602
+ safeLog(`[handleGitOperationCheck] ${operationType}: level=${config2?.level}`);
20603
+ if (!config2 || config2.level === "off")
20596
20604
  return { block: false };
20597
- }
20598
20605
  const { analyzeBeforeCommit = true, blockCommit = false, blockPush = false } = config2;
20599
20606
  const { fixBeforeCommit = false, blockingSeverity = "CRITICAL", autoFix = false } = config2;
20600
- const shouldBlock = operationType === "commit" && blockCommit || operationType === "push" && blockPush;
20601
- safeLog(`[handleGitOperationCheck] shouldBlock=${shouldBlock}, blockCommit=${blockCommit}, blockingSeverity=${blockingSeverity}`);
20607
+ const shouldBlock = operationType === "commit" ? blockCommit : blockPush;
20602
20608
  try {
20603
20609
  const dir = getDirectory();
20604
- safeLog(`[handleGitOperationCheck] directory=${dir}`);
20605
20610
  const state = await getProjectState(dir);
20606
- safeLog(`[handleGitOperationCheck] projectKey=${state?.projectKey ?? "NONE"}`);
20607
- if (!state?.projectKey) {
20608
- safeLog(`[handleGitOperationCheck] No projectKey, returning block=false`);
20611
+ safeLog(`[handleGitOperationCheck] dir=${dir}, projectKey=${state?.projectKey ?? "NONE"}`);
20612
+ if (!state?.projectKey)
20609
20613
  return { block: false };
20610
- }
20611
20614
  const api2 = createSonarQubeAPI(config2, state);
20612
20615
  if (operationType === "push" || !analyzeBeforeCommit) {
20613
- safeLog(`[handleGitOperationCheck] Checking existing issues (push or no analyzeBeforeCommit)`);
20614
20616
  return checkExistingIssuesAndBlock(api2, state.projectKey, operationType, blockingSeverity, shouldBlock);
20615
20617
  }
20616
- safeLog(`[handleGitOperationCheck] Running pre-commit analysis...`);
20617
20618
  await showToast("SonarQube: Running pre-commit analysis...", "info");
20618
20619
  const analysisResult = await runAnalysis(config2, state, { projectKey: state.projectKey }, dir);
20619
- safeLog(`[handleGitOperationCheck] analysisResult: qualityGate=${analysisResult.qualityGateStatus}, issues=${JSON.stringify(analysisResult.issues)}`);
20620
- if (analysisResult.qualityGateStatus === "OK") {
20621
- safeLog(`[handleGitOperationCheck] Quality gate OK, returning block=false`);
20622
- await showToast("SonarQube: Quality check passed!", "success");
20623
- return { block: false };
20624
- }
20625
- const hasBlockingIssues = checkBlockingIssues(analysisResult.issues, blockingSeverity);
20626
- safeLog(`[handleGitOperationCheck] hasBlockingIssues=${hasBlockingIssues}`);
20627
- if (!hasBlockingIssues) {
20628
- safeLog(`[handleGitOperationCheck] No blocking issues, returning block=false`);
20629
- await showToast("SonarQube: Quality check passed!", "success");
20630
- return { block: false };
20631
- }
20632
- if (fixBeforeCommit && autoFix) {
20633
- safeLog(`[handleGitOperationCheck] Auto-fixing issues...`);
20634
- await sendAutoFixPrompt(analysisResult);
20635
- return { block: shouldBlock, message: "SonarQube is fixing issues. Please wait and try again." };
20636
- }
20637
- safeLog(`[handleGitOperationCheck] BLOCKING! shouldBlock=${shouldBlock}`);
20638
- const warningMessage = await sendBlockingMessage(analysisResult.issues, shouldBlock, autoFix);
20639
- return { block: shouldBlock, message: warningMessage };
20620
+ safeLog(`[handleGitOperationCheck] qualityGate=${analysisResult.qualityGateStatus}`);
20621
+ return processAnalysisResult(analysisResult, blockingSeverity, shouldBlock, fixBeforeCommit, autoFix);
20640
20622
  } catch (err) {
20641
20623
  safeLog(`[handleGitOperationCheck] ERROR: ${err instanceof Error ? err.message : String(err)}`);
20642
20624
  return { block: false };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-sonarqube",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "OpenCode Plugin for SonarQube integration - Enterprise-level code quality from the start",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",