opencode-sonarqube 1.2.6 → 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.
- package/dist/index.js +41 -28
- 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();
|
|
@@ -20565,25 +20575,40 @@ Fix these issues before ${operationType === "commit" ? "committing" : "pushing"}
|
|
|
20565
20575
|
await showToast(`SonarQube: ${operationType} BLOCKED`, "error");
|
|
20566
20576
|
return { block: true, message };
|
|
20567
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
|
+
};
|
|
20568
20593
|
const handleGitOperationCheck = async (output, operationType) => {
|
|
20569
20594
|
const args = output.args;
|
|
20570
20595
|
const command = args?.command ?? "";
|
|
20571
|
-
const
|
|
20572
|
-
|
|
20573
|
-
const isMatchingOperation = operationType === "commit" && isCommit || operationType === "push" && isPush;
|
|
20574
|
-
if (!isMatchingOperation)
|
|
20596
|
+
const isMatch = operationType === "commit" ? isGitCommit(command) : isGitPush(command);
|
|
20597
|
+
if (!isMatch)
|
|
20575
20598
|
return { block: false };
|
|
20576
20599
|
await loadPluginConfig();
|
|
20577
20600
|
const sonarConfig = pluginConfig?.["sonarqube"];
|
|
20578
20601
|
const config2 = loadConfig(sonarConfig);
|
|
20602
|
+
safeLog(`[handleGitOperationCheck] ${operationType}: level=${config2?.level}`);
|
|
20579
20603
|
if (!config2 || config2.level === "off")
|
|
20580
20604
|
return { block: false };
|
|
20581
20605
|
const { analyzeBeforeCommit = true, blockCommit = false, blockPush = false } = config2;
|
|
20582
20606
|
const { fixBeforeCommit = false, blockingSeverity = "CRITICAL", autoFix = false } = config2;
|
|
20583
|
-
const shouldBlock = operationType === "commit"
|
|
20607
|
+
const shouldBlock = operationType === "commit" ? blockCommit : blockPush;
|
|
20584
20608
|
try {
|
|
20585
20609
|
const dir = getDirectory();
|
|
20586
20610
|
const state = await getProjectState(dir);
|
|
20611
|
+
safeLog(`[handleGitOperationCheck] dir=${dir}, projectKey=${state?.projectKey ?? "NONE"}`);
|
|
20587
20612
|
if (!state?.projectKey)
|
|
20588
20613
|
return { block: false };
|
|
20589
20614
|
const api2 = createSonarQubeAPI(config2, state);
|
|
@@ -20592,22 +20617,10 @@ Fix these issues before ${operationType === "commit" ? "committing" : "pushing"}
|
|
|
20592
20617
|
}
|
|
20593
20618
|
await showToast("SonarQube: Running pre-commit analysis...", "info");
|
|
20594
20619
|
const analysisResult = await runAnalysis(config2, state, { projectKey: state.projectKey }, dir);
|
|
20595
|
-
|
|
20596
|
-
|
|
20597
|
-
|
|
20598
|
-
}
|
|
20599
|
-
const hasBlockingIssues = checkBlockingIssues(analysisResult.issues, blockingSeverity);
|
|
20600
|
-
if (!hasBlockingIssues) {
|
|
20601
|
-
await showToast("SonarQube: Quality check passed!", "success");
|
|
20602
|
-
return { block: false };
|
|
20603
|
-
}
|
|
20604
|
-
if (fixBeforeCommit && autoFix) {
|
|
20605
|
-
await sendAutoFixPrompt(analysisResult);
|
|
20606
|
-
return { block: shouldBlock, message: "SonarQube is fixing issues. Please wait and try again." };
|
|
20607
|
-
}
|
|
20608
|
-
const warningMessage = await sendBlockingMessage(analysisResult.issues, shouldBlock, autoFix);
|
|
20609
|
-
return { block: shouldBlock, message: warningMessage };
|
|
20610
|
-
} catch {
|
|
20620
|
+
safeLog(`[handleGitOperationCheck] qualityGate=${analysisResult.qualityGateStatus}`);
|
|
20621
|
+
return processAnalysisResult(analysisResult, blockingSeverity, shouldBlock, fixBeforeCommit, autoFix);
|
|
20622
|
+
} catch (err) {
|
|
20623
|
+
safeLog(`[handleGitOperationCheck] ERROR: ${err instanceof Error ? err.message : String(err)}`);
|
|
20611
20624
|
return { block: false };
|
|
20612
20625
|
}
|
|
20613
20626
|
};
|