opencode-sonarqube 1.2.6 → 1.2.7
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.
- package/dist/index.js +42 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20229,7 +20229,9 @@ var SonarQubePlugin = async ({ client, directory, worktree }) => {
|
|
|
20229
20229
|
`);
|
|
20230
20230
|
} catch {}
|
|
20231
20231
|
};
|
|
20232
|
+
safeLog(`=== PLUGIN INIT === directory="${directory}" worktree="${worktree}"`);
|
|
20232
20233
|
const pluginImportUrl = import.meta.url;
|
|
20234
|
+
safeLog(`pluginImportUrl="${pluginImportUrl}"`);
|
|
20233
20235
|
const resolveDirectoryFromImportUrl = () => {
|
|
20234
20236
|
try {
|
|
20235
20237
|
const pluginPath = decodeURIComponent(pluginImportUrl.replace("file://", ""));
|
|
@@ -20237,7 +20239,7 @@ var SonarQubePlugin = async ({ client, directory, worktree }) => {
|
|
|
20237
20239
|
const nodeModulesIndex = pathParts.indexOf("node_modules");
|
|
20238
20240
|
if (nodeModulesIndex > 0) {
|
|
20239
20241
|
const projectPath = pathParts.slice(0, nodeModulesIndex).join("/");
|
|
20240
|
-
if (projectPath && projectPath !== "/" && projectPath.length > 1) {
|
|
20242
|
+
if (projectPath && projectPath !== "/" && projectPath.length > 1 && !projectPath.includes(".cache/opencode")) {
|
|
20241
20243
|
return projectPath;
|
|
20242
20244
|
}
|
|
20243
20245
|
}
|
|
@@ -20245,16 +20247,24 @@ var SonarQubePlugin = async ({ client, directory, worktree }) => {
|
|
|
20245
20247
|
return null;
|
|
20246
20248
|
};
|
|
20247
20249
|
const resolveValidDirectory = () => {
|
|
20248
|
-
|
|
20249
|
-
|
|
20250
|
-
return fromImportUrl;
|
|
20251
|
-
if (worktree && worktree !== "/" && worktree.length > 1)
|
|
20250
|
+
if (worktree && worktree !== "/" && worktree.length > 1) {
|
|
20251
|
+
safeLog(`Using worktree: ${worktree}`);
|
|
20252
20252
|
return worktree;
|
|
20253
|
-
|
|
20253
|
+
}
|
|
20254
|
+
if (directory && directory !== "/" && directory.length > 1) {
|
|
20255
|
+
safeLog(`Using directory: ${directory}`);
|
|
20254
20256
|
return directory;
|
|
20257
|
+
}
|
|
20258
|
+
const fromImportUrl = resolveDirectoryFromImportUrl();
|
|
20259
|
+
if (fromImportUrl) {
|
|
20260
|
+
safeLog(`Using fromImportUrl: ${fromImportUrl}`);
|
|
20261
|
+
return fromImportUrl;
|
|
20262
|
+
}
|
|
20255
20263
|
const cwd = process.cwd();
|
|
20256
|
-
if (cwd && cwd !== "/" && cwd.length > 1)
|
|
20264
|
+
if (cwd && cwd !== "/" && cwd.length > 1) {
|
|
20265
|
+
safeLog(`Using cwd: ${cwd}`);
|
|
20257
20266
|
return cwd;
|
|
20267
|
+
}
|
|
20258
20268
|
return process.env["HOME"] || "/Users";
|
|
20259
20269
|
};
|
|
20260
20270
|
const effectiveDirectory = resolveValidDirectory();
|
|
@@ -20566,48 +20576,69 @@ Fix these issues before ${operationType === "commit" ? "committing" : "pushing"}
|
|
|
20566
20576
|
return { block: true, message };
|
|
20567
20577
|
};
|
|
20568
20578
|
const handleGitOperationCheck = async (output, operationType) => {
|
|
20579
|
+
safeLog(`[handleGitOperationCheck] ENTERED operationType=${operationType}`);
|
|
20569
20580
|
const args = output.args;
|
|
20570
20581
|
const command = args?.command ?? "";
|
|
20582
|
+
safeLog(`[handleGitOperationCheck] command=${command.slice(0, 80)}...`);
|
|
20571
20583
|
const isCommit = /git\s+commit\b/.test(command) && !/--amend/.test(command);
|
|
20572
20584
|
const isPush = /git\s+push\b/.test(command);
|
|
20573
20585
|
const isMatchingOperation = operationType === "commit" && isCommit || operationType === "push" && isPush;
|
|
20574
|
-
if (!isMatchingOperation)
|
|
20586
|
+
if (!isMatchingOperation) {
|
|
20587
|
+
safeLog(`[handleGitOperationCheck] NOT matching operation, returning block=false`);
|
|
20575
20588
|
return { block: false };
|
|
20589
|
+
}
|
|
20576
20590
|
await loadPluginConfig();
|
|
20577
20591
|
const sonarConfig = pluginConfig?.["sonarqube"];
|
|
20578
20592
|
const config2 = loadConfig(sonarConfig);
|
|
20579
|
-
|
|
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`);
|
|
20580
20596
|
return { block: false };
|
|
20597
|
+
}
|
|
20581
20598
|
const { analyzeBeforeCommit = true, blockCommit = false, blockPush = false } = config2;
|
|
20582
20599
|
const { fixBeforeCommit = false, blockingSeverity = "CRITICAL", autoFix = false } = config2;
|
|
20583
20600
|
const shouldBlock = operationType === "commit" && blockCommit || operationType === "push" && blockPush;
|
|
20601
|
+
safeLog(`[handleGitOperationCheck] shouldBlock=${shouldBlock}, blockCommit=${blockCommit}, blockingSeverity=${blockingSeverity}`);
|
|
20584
20602
|
try {
|
|
20585
20603
|
const dir = getDirectory();
|
|
20604
|
+
safeLog(`[handleGitOperationCheck] directory=${dir}`);
|
|
20586
20605
|
const state = await getProjectState(dir);
|
|
20587
|
-
|
|
20606
|
+
safeLog(`[handleGitOperationCheck] projectKey=${state?.projectKey ?? "NONE"}`);
|
|
20607
|
+
if (!state?.projectKey) {
|
|
20608
|
+
safeLog(`[handleGitOperationCheck] No projectKey, returning block=false`);
|
|
20588
20609
|
return { block: false };
|
|
20610
|
+
}
|
|
20589
20611
|
const api2 = createSonarQubeAPI(config2, state);
|
|
20590
20612
|
if (operationType === "push" || !analyzeBeforeCommit) {
|
|
20613
|
+
safeLog(`[handleGitOperationCheck] Checking existing issues (push or no analyzeBeforeCommit)`);
|
|
20591
20614
|
return checkExistingIssuesAndBlock(api2, state.projectKey, operationType, blockingSeverity, shouldBlock);
|
|
20592
20615
|
}
|
|
20616
|
+
safeLog(`[handleGitOperationCheck] Running pre-commit analysis...`);
|
|
20593
20617
|
await showToast("SonarQube: Running pre-commit analysis...", "info");
|
|
20594
20618
|
const analysisResult = await runAnalysis(config2, state, { projectKey: state.projectKey }, dir);
|
|
20619
|
+
safeLog(`[handleGitOperationCheck] analysisResult: qualityGate=${analysisResult.qualityGateStatus}, issues=${JSON.stringify(analysisResult.issues)}`);
|
|
20595
20620
|
if (analysisResult.qualityGateStatus === "OK") {
|
|
20621
|
+
safeLog(`[handleGitOperationCheck] Quality gate OK, returning block=false`);
|
|
20596
20622
|
await showToast("SonarQube: Quality check passed!", "success");
|
|
20597
20623
|
return { block: false };
|
|
20598
20624
|
}
|
|
20599
20625
|
const hasBlockingIssues = checkBlockingIssues(analysisResult.issues, blockingSeverity);
|
|
20626
|
+
safeLog(`[handleGitOperationCheck] hasBlockingIssues=${hasBlockingIssues}`);
|
|
20600
20627
|
if (!hasBlockingIssues) {
|
|
20628
|
+
safeLog(`[handleGitOperationCheck] No blocking issues, returning block=false`);
|
|
20601
20629
|
await showToast("SonarQube: Quality check passed!", "success");
|
|
20602
20630
|
return { block: false };
|
|
20603
20631
|
}
|
|
20604
20632
|
if (fixBeforeCommit && autoFix) {
|
|
20633
|
+
safeLog(`[handleGitOperationCheck] Auto-fixing issues...`);
|
|
20605
20634
|
await sendAutoFixPrompt(analysisResult);
|
|
20606
20635
|
return { block: shouldBlock, message: "SonarQube is fixing issues. Please wait and try again." };
|
|
20607
20636
|
}
|
|
20637
|
+
safeLog(`[handleGitOperationCheck] BLOCKING! shouldBlock=${shouldBlock}`);
|
|
20608
20638
|
const warningMessage = await sendBlockingMessage(analysisResult.issues, shouldBlock, autoFix);
|
|
20609
20639
|
return { block: shouldBlock, message: warningMessage };
|
|
20610
|
-
} catch {
|
|
20640
|
+
} catch (err) {
|
|
20641
|
+
safeLog(`[handleGitOperationCheck] ERROR: ${err instanceof Error ? err.message : String(err)}`);
|
|
20611
20642
|
return { block: false };
|
|
20612
20643
|
}
|
|
20613
20644
|
};
|