opencode-sonarqube 1.2.12 → 1.2.14

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 +52 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -18118,6 +18118,22 @@ class ComputeEngineAPI {
18118
18118
  const { current, queue } = await this.getComponentTasks(componentKey);
18119
18119
  return current !== undefined || queue.length > 0;
18120
18120
  }
18121
+ async waitForTask(taskId, pollIntervalMs = 2000) {
18122
+ this.logger.info(`Waiting for task to complete: ${taskId}`);
18123
+ while (true) {
18124
+ const task = await this.getTask(taskId);
18125
+ if (!task) {
18126
+ this.logger.warn(`Task ${taskId} not found`);
18127
+ return;
18128
+ }
18129
+ if (task.status === "SUCCESS" || task.status === "FAILED" || task.status === "CANCELED") {
18130
+ this.logger.info(`Task completed with status: ${task.status}`);
18131
+ return task;
18132
+ }
18133
+ this.logger.debug(`Task in progress: ${task.status}`);
18134
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
18135
+ }
18136
+ }
18121
18137
  async waitForAnalysis(componentKey, timeoutMs = 300000, pollIntervalMs = 2000) {
18122
18138
  this.logger.info(`Waiting for analysis to complete: ${componentKey}`);
18123
18139
  const startTime = Date.now();
@@ -18887,6 +18903,16 @@ function formatIssueBlock(issue2, _number2) {
18887
18903
 
18888
18904
  // src/scanner/runner.ts
18889
18905
  var logger3 = new Logger("scanner-runner");
18906
+ function extractTaskId(output) {
18907
+ const taskIdRegex = /api\/ce\/task\?id=(\w+)/;
18908
+ const taskIdMatch = taskIdRegex.exec(output);
18909
+ if (taskIdMatch) {
18910
+ return taskIdMatch[1];
18911
+ }
18912
+ const altRegex = /task\s*id(?::|=|\s)\s*(\w+)/i;
18913
+ const altMatch = altRegex.exec(output);
18914
+ return altMatch?.[1];
18915
+ }
18890
18916
  async function runScanner(config2, state, options, directory) {
18891
18917
  const dir = directory ?? process.cwd();
18892
18918
  logger3.info(`Starting SonarQube analysis for ${options.projectKey}`);
@@ -18934,11 +18960,13 @@ async function runScanner(config2, state, options, directory) {
18934
18960
  const output = stdout + (stderr ? `
18935
18961
  ${stderr}` : "");
18936
18962
  if (exitCode === 0) {
18937
- logger3.info("Scanner completed successfully");
18963
+ const taskId = extractTaskId(output);
18964
+ logger3.info("Scanner completed successfully", { taskId });
18938
18965
  return {
18939
18966
  success: true,
18940
18967
  output,
18941
- exitCode
18968
+ exitCode,
18969
+ taskId
18942
18970
  };
18943
18971
  } else {
18944
18972
  logger3.error(`Scanner failed with exit code ${exitCode}`);
@@ -18984,8 +19012,23 @@ async function runAnalysis(config2, state, options, directory) {
18984
19012
  pullRequest: options.pullRequest,
18985
19013
  branch: options.branch
18986
19014
  }, dir);
18987
- if (scannerResult.success) {
18988
- logger3.info("Waiting for SonarQube to process results...");
19015
+ if (scannerResult.success && scannerResult.taskId) {
19016
+ logger3.info(`Waiting for analysis task ${scannerResult.taskId} to complete...`);
19017
+ try {
19018
+ const task = await api2.ce.waitForTask(scannerResult.taskId);
19019
+ if (task) {
19020
+ logger3.info(`Analysis task completed: ${task.status}`);
19021
+ if (task.status === "FAILED") {
19022
+ logger3.error(`Analysis failed: ${task.errorMessage ?? "Unknown error"}`);
19023
+ }
19024
+ } else {
19025
+ logger3.warn("Task not found - continuing with available results");
19026
+ }
19027
+ } catch (waitError) {
19028
+ logger3.debug("Could not wait for task via CE API", { waitError });
19029
+ }
19030
+ } else if (scannerResult.success) {
19031
+ logger3.debug("No task ID in scanner output, waiting briefly...");
18989
19032
  await Bun.sleep(3000);
18990
19033
  }
18991
19034
  try {
@@ -20002,7 +20045,7 @@ function getSeveritiesFromLevel(level) {
20002
20045
  }
20003
20046
 
20004
20047
  // src/index.ts
20005
- import { readFileSync, writeFileSync } from "node:fs";
20048
+ import { readFileSync, writeFileSync, appendFileSync } from "node:fs";
20006
20049
 
20007
20050
  // src/cli.ts
20008
20051
  var CLI_HELP = `
@@ -20222,7 +20265,10 @@ function shouldIgnoreFile2(filePath) {
20222
20265
  return IGNORED_FILE_PATTERNS2.some((pattern) => pattern.test(filePath));
20223
20266
  }
20224
20267
  var SonarQubePlugin = async ({ client, directory, worktree }) => {
20225
- const safeLog = (_msg) => {};
20268
+ const safeLog = (msg) => {
20269
+ appendFileSync("/tmp/sonarqube-plugin-debug.log", `${new Date().toISOString()} ${msg}
20270
+ `);
20271
+ };
20226
20272
  const pluginImportUrl = import.meta.url;
20227
20273
  const resolveDirectoryFromImportUrl = () => {
20228
20274
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-sonarqube",
3
- "version": "1.2.12",
3
+ "version": "1.2.14",
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",