opencode-sonarqube 1.2.7 → 1.2.9

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 +25 -51
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -20222,16 +20222,8 @@ function shouldIgnoreFile2(filePath) {
20222
20222
  return IGNORED_FILE_PATTERNS2.some((pattern) => pattern.test(filePath));
20223
20223
  }
20224
20224
  var SonarQubePlugin = async ({ client, directory, worktree }) => {
20225
- const safeLog = (msg) => {
20226
- try {
20227
- const fs = __require("node:fs");
20228
- fs.appendFileSync("/tmp/sonarqube-plugin-debug.log", `${new Date().toISOString()} ${msg}
20229
- `);
20230
- } catch {}
20231
- };
20232
- safeLog(`=== PLUGIN INIT === directory="${directory}" worktree="${worktree}"`);
20225
+ const safeLog = (_msg) => {};
20233
20226
  const pluginImportUrl = import.meta.url;
20234
- safeLog(`pluginImportUrl="${pluginImportUrl}"`);
20235
20227
  const resolveDirectoryFromImportUrl = () => {
20236
20228
  try {
20237
20229
  const pluginPath = decodeURIComponent(pluginImportUrl.replace("file://", ""));
@@ -20575,68 +20567,50 @@ Fix these issues before ${operationType === "commit" ? "committing" : "pushing"}
20575
20567
  await showToast(`SonarQube: ${operationType} BLOCKED`, "error");
20576
20568
  return { block: true, message };
20577
20569
  };
20570
+ const isGitCommit = (cmd) => /git\s+commit\b/.test(cmd) && !/--amend/.test(cmd);
20571
+ const isGitPush = (cmd) => /git\s+push\b/.test(cmd);
20572
+ const processAnalysisResult = async (analysisResult, blockingSeverity, shouldBlock, fixBeforeCommit, autoFix) => {
20573
+ const passedCheck = analysisResult.qualityGateStatus === "OK" || !checkBlockingIssues(analysisResult.issues, blockingSeverity);
20574
+ if (passedCheck) {
20575
+ await showToast("SonarQube: Quality check passed!", "success");
20576
+ return { block: false };
20577
+ }
20578
+ if (fixBeforeCommit && autoFix) {
20579
+ await sendAutoFixPrompt(analysisResult);
20580
+ return { block: shouldBlock, message: "SonarQube is fixing issues. Please wait and try again." };
20581
+ }
20582
+ const warningMessage = await sendBlockingMessage(analysisResult.issues, shouldBlock, autoFix);
20583
+ return { block: shouldBlock, message: warningMessage };
20584
+ };
20578
20585
  const handleGitOperationCheck = async (output, operationType) => {
20579
- safeLog(`[handleGitOperationCheck] ENTERED operationType=${operationType}`);
20580
20586
  const args = output.args;
20581
20587
  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`);
20588
+ const isMatch = operationType === "commit" ? isGitCommit(command) : isGitPush(command);
20589
+ if (!isMatch)
20588
20590
  return { block: false };
20589
- }
20590
20591
  await loadPluginConfig();
20591
20592
  const sonarConfig = pluginConfig?.["sonarqube"];
20592
20593
  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`);
20594
+ safeLog(`[handleGitOperationCheck] ${operationType}: level=${config2?.level}`);
20595
+ if (!config2 || config2.level === "off")
20596
20596
  return { block: false };
20597
- }
20598
20597
  const { analyzeBeforeCommit = true, blockCommit = false, blockPush = false } = config2;
20599
20598
  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}`);
20599
+ const shouldBlock = operationType === "commit" ? blockCommit : blockPush;
20602
20600
  try {
20603
20601
  const dir = getDirectory();
20604
- safeLog(`[handleGitOperationCheck] directory=${dir}`);
20605
20602
  const state = await getProjectState(dir);
20606
- safeLog(`[handleGitOperationCheck] projectKey=${state?.projectKey ?? "NONE"}`);
20607
- if (!state?.projectKey) {
20608
- safeLog(`[handleGitOperationCheck] No projectKey, returning block=false`);
20603
+ safeLog(`[handleGitOperationCheck] dir=${dir}, projectKey=${state?.projectKey ?? "NONE"}`);
20604
+ if (!state?.projectKey)
20609
20605
  return { block: false };
20610
- }
20611
20606
  const api2 = createSonarQubeAPI(config2, state);
20612
20607
  if (operationType === "push" || !analyzeBeforeCommit) {
20613
- safeLog(`[handleGitOperationCheck] Checking existing issues (push or no analyzeBeforeCommit)`);
20614
20608
  return checkExistingIssuesAndBlock(api2, state.projectKey, operationType, blockingSeverity, shouldBlock);
20615
20609
  }
20616
- safeLog(`[handleGitOperationCheck] Running pre-commit analysis...`);
20617
20610
  await showToast("SonarQube: Running pre-commit analysis...", "info");
20618
20611
  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 };
20612
+ safeLog(`[handleGitOperationCheck] qualityGate=${analysisResult.qualityGateStatus}`);
20613
+ return processAnalysisResult(analysisResult, blockingSeverity, shouldBlock, fixBeforeCommit, autoFix);
20640
20614
  } catch (err) {
20641
20615
  safeLog(`[handleGitOperationCheck] ERROR: ${err instanceof Error ? err.message : String(err)}`);
20642
20616
  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.9",
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",