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