opencode-sonarqube 1.2.30 → 1.2.32
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 +105 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20674,7 +20674,7 @@ Fix these issues before ${operationType === "commit" ? "committing" : "pushing"}
|
|
|
20674
20674
|
}
|
|
20675
20675
|
if (fixBeforeCommit && autoFix) {
|
|
20676
20676
|
await sendAutoFixPrompt(analysisResult);
|
|
20677
|
-
return { block: shouldBlock, message: "
|
|
20677
|
+
return { block: shouldBlock, message: "Quality gate FAILED. Run sonarqube({ action: 'issues' }) to see problems, then fix them before committing." };
|
|
20678
20678
|
}
|
|
20679
20679
|
const warningMessage = await sendBlockingMessage(analysisResult.issues, shouldBlock, autoFix);
|
|
20680
20680
|
return { block: shouldBlock, message: warningMessage };
|
|
@@ -20682,13 +20682,28 @@ Fix these issues before ${operationType === "commit" ? "committing" : "pushing"}
|
|
|
20682
20682
|
const handleGitOperationCheck = async (output, operationType) => {
|
|
20683
20683
|
const args = output.args;
|
|
20684
20684
|
const command = args?.command ?? "";
|
|
20685
|
+
const workdir = args?.workdir;
|
|
20685
20686
|
const isMatch = operationType === "commit" ? isGitCommit(command) : isGitPush(command);
|
|
20686
20687
|
if (!isMatch)
|
|
20687
20688
|
return { block: false };
|
|
20688
|
-
|
|
20689
|
-
|
|
20690
|
-
|
|
20691
|
-
|
|
20689
|
+
const dir = workdir || getDirectory();
|
|
20690
|
+
safeLog(`[handleGitOperationCheck] workdir=${workdir}, resolved dir=${dir}`);
|
|
20691
|
+
const targetConfigPath = `${dir}/.sonarqube/config.json`;
|
|
20692
|
+
let targetConfig;
|
|
20693
|
+
try {
|
|
20694
|
+
const configFile = Bun.file(targetConfigPath);
|
|
20695
|
+
if (await configFile.exists()) {
|
|
20696
|
+
targetConfig = await configFile.json();
|
|
20697
|
+
safeLog(`[handleGitOperationCheck] Loaded config from ${targetConfigPath}`);
|
|
20698
|
+
}
|
|
20699
|
+
} catch {}
|
|
20700
|
+
if (!targetConfig) {
|
|
20701
|
+
await loadPluginConfig();
|
|
20702
|
+
targetConfig = pluginConfig?.["sonarqube"];
|
|
20703
|
+
safeLog(`[handleGitOperationCheck] Using plugin config (no target config found)`);
|
|
20704
|
+
}
|
|
20705
|
+
safeLog(`[handleGitOperationCheck] targetConfig=${JSON.stringify(targetConfig)}`);
|
|
20706
|
+
const config2 = loadConfig(targetConfig);
|
|
20692
20707
|
safeLog(`[handleGitOperationCheck] ${operationType}: level=${config2?.level}, blockCommit=${config2?.blockCommit}, blockPush=${config2?.blockPush}`);
|
|
20693
20708
|
if (!config2 || config2.level === "off")
|
|
20694
20709
|
return { block: false };
|
|
@@ -20697,7 +20712,6 @@ Fix these issues before ${operationType === "commit" ? "committing" : "pushing"}
|
|
|
20697
20712
|
const shouldBlock = operationType === "commit" ? blockCommit : blockPush;
|
|
20698
20713
|
safeLog(`[handleGitOperationCheck] shouldBlock=${shouldBlock}, blockCommit=${blockCommit}, blockPush=${blockPush}, blockingSeverity=${blockingSeverity}`);
|
|
20699
20714
|
try {
|
|
20700
|
-
const dir = getDirectory();
|
|
20701
20715
|
const state = await getProjectState(dir);
|
|
20702
20716
|
safeLog(`[handleGitOperationCheck] dir=${dir}, projectKey=${state?.projectKey ?? "NONE"}`);
|
|
20703
20717
|
if (!state?.projectKey)
|
|
@@ -20860,8 +20874,55 @@ Git operation completed with changes. Consider running:
|
|
|
20860
20874
|
const result = await handleGitOperationCheck(output, "commit");
|
|
20861
20875
|
safeLog(`[pre-check] commit check result: block=${result.block}, message=${result.message}`);
|
|
20862
20876
|
if (result.block && args) {
|
|
20863
|
-
|
|
20864
|
-
|
|
20877
|
+
const aiMessage = `echo "
|
|
20878
|
+
================================================================================
|
|
20879
|
+
\uD83D\uDEAB COMMIT BLOCKED BY SONARQUBE
|
|
20880
|
+
================================================================================
|
|
20881
|
+
|
|
20882
|
+
WHAT IS SONARQUBE?
|
|
20883
|
+
SonarQube is a code quality tool that analyzes your code for bugs, vulnerabilities,
|
|
20884
|
+
security issues, and code smells. This project has pre-commit blocking enabled,
|
|
20885
|
+
which means commits are blocked if the code quality is not good enough.
|
|
20886
|
+
|
|
20887
|
+
WHY WAS THIS BLOCKED?
|
|
20888
|
+
Your commit was blocked because the SonarQube quality gate FAILED. This means
|
|
20889
|
+
there are code quality issues that need to be fixed before you can commit.
|
|
20890
|
+
|
|
20891
|
+
HOW TO FIX THIS:
|
|
20892
|
+
|
|
20893
|
+
Step 1: See what issues were found
|
|
20894
|
+
Use the sonarqube tool to view the issues:
|
|
20895
|
+
sonarqube({ action: 'issues' })
|
|
20896
|
+
|
|
20897
|
+
Step 2: Understand the issues
|
|
20898
|
+
Each issue shows:
|
|
20899
|
+
- Severity (BLOCKER, CRITICAL, MAJOR, MINOR, INFO)
|
|
20900
|
+
- The file and line number
|
|
20901
|
+
- A description of the problem
|
|
20902
|
+
- Often a suggestion for how to fix it
|
|
20903
|
+
|
|
20904
|
+
Step 3: Fix the issues in your code
|
|
20905
|
+
Edit the files to resolve the issues. Common issues include:
|
|
20906
|
+
- Hardcoded passwords or API keys
|
|
20907
|
+
- SQL injection vulnerabilities
|
|
20908
|
+
- Unused variables
|
|
20909
|
+
- Code duplication
|
|
20910
|
+
- Missing null checks
|
|
20911
|
+
|
|
20912
|
+
Step 4: Try committing again
|
|
20913
|
+
After fixing the issues, try your commit again.
|
|
20914
|
+
|
|
20915
|
+
USEFUL SONARQUBE COMMANDS:
|
|
20916
|
+
- sonarqube({ action: 'issues' }) - See all issues
|
|
20917
|
+
- sonarqube({ action: 'issues', severity: 'critical' }) - See critical+ issues only
|
|
20918
|
+
- sonarqube({ action: 'analyze' }) - Re-run analysis
|
|
20919
|
+
- sonarqube({ action: 'status' }) - Check quality gate status
|
|
20920
|
+
|
|
20921
|
+
IMPORTANT: Do NOT retry the commit without fixing the issues first!
|
|
20922
|
+
================================================================================
|
|
20923
|
+
" && exit 1`;
|
|
20924
|
+
args.command = aiMessage;
|
|
20925
|
+
safeLog(`[pre-check] Commit BLOCKED - command replaced with AI-friendly message`);
|
|
20865
20926
|
await showToast("Commit blocked by SonarQube quality gate!", "error");
|
|
20866
20927
|
}
|
|
20867
20928
|
}
|
|
@@ -20869,8 +20930,42 @@ Git operation completed with changes. Consider running:
|
|
|
20869
20930
|
safeLog(`[pre-check] Detected git push, running quality check...`);
|
|
20870
20931
|
const result = await handleGitOperationCheck(output, "push");
|
|
20871
20932
|
if (result.block && args) {
|
|
20872
|
-
|
|
20873
|
-
|
|
20933
|
+
const aiMessage = `echo "
|
|
20934
|
+
================================================================================
|
|
20935
|
+
\uD83D\uDEAB PUSH BLOCKED BY SONARQUBE
|
|
20936
|
+
================================================================================
|
|
20937
|
+
|
|
20938
|
+
WHAT IS SONARQUBE?
|
|
20939
|
+
SonarQube is a code quality tool that analyzes your code for bugs, vulnerabilities,
|
|
20940
|
+
security issues, and code smells. This project has pre-push blocking enabled,
|
|
20941
|
+
which means pushes are blocked if the code quality is not good enough.
|
|
20942
|
+
|
|
20943
|
+
WHY WAS THIS BLOCKED?
|
|
20944
|
+
Your push was blocked because the SonarQube quality gate FAILED. This means
|
|
20945
|
+
there are code quality issues that need to be fixed before you can push.
|
|
20946
|
+
|
|
20947
|
+
HOW TO FIX THIS:
|
|
20948
|
+
|
|
20949
|
+
Step 1: See what issues were found
|
|
20950
|
+
sonarqube({ action: 'issues' })
|
|
20951
|
+
|
|
20952
|
+
Step 2: Fix the issues in your code
|
|
20953
|
+
|
|
20954
|
+
Step 3: Commit your fixes
|
|
20955
|
+
git add . && git commit -m 'fix: resolve code quality issues'
|
|
20956
|
+
|
|
20957
|
+
Step 4: Try pushing again
|
|
20958
|
+
|
|
20959
|
+
USEFUL SONARQUBE COMMANDS:
|
|
20960
|
+
- sonarqube({ action: 'issues' }) - See all issues
|
|
20961
|
+
- sonarqube({ action: 'analyze' }) - Re-run analysis
|
|
20962
|
+
- sonarqube({ action: 'status' }) - Check quality gate status
|
|
20963
|
+
|
|
20964
|
+
IMPORTANT: Do NOT retry the push without fixing the issues first!
|
|
20965
|
+
================================================================================
|
|
20966
|
+
" && exit 1`;
|
|
20967
|
+
args.command = aiMessage;
|
|
20968
|
+
safeLog(`[pre-check] Push BLOCKED - command replaced with AI-friendly message`);
|
|
20874
20969
|
await showToast("Push blocked by SonarQube quality gate!", "error");
|
|
20875
20970
|
}
|
|
20876
20971
|
}
|