opencode-sonarqube 0.1.3 → 0.1.4

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 +149 -143
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4104,94 +4104,6 @@ var init_types2 = __esm(() => {
4104
4104
  };
4105
4105
  });
4106
4106
 
4107
- // src/utils/logger.ts
4108
- class Logger {
4109
- service;
4110
- minLevel;
4111
- client;
4112
- constructor(service, options) {
4113
- this.service = service;
4114
- this.minLevel = options?.minLevel ?? "info";
4115
- this.client = options?.client;
4116
- }
4117
- shouldLog(level) {
4118
- const levels = ["debug", "info", "warn", "error"];
4119
- return levels.indexOf(level) >= levels.indexOf(this.minLevel);
4120
- }
4121
- formatMessage(level, message, extra) {
4122
- const timestamp = new Date().toISOString();
4123
- const color = LOG_COLORS[level];
4124
- const prefix = `${color}[${this.service}]${RESET}`;
4125
- const levelStr = `${color}${level.toUpperCase()}${RESET}`;
4126
- let formatted = `${prefix} ${timestamp} ${levelStr}: ${message}`;
4127
- if (extra && Object.keys(extra).length > 0) {
4128
- formatted += ` ${JSON.stringify(extra)}`;
4129
- }
4130
- return formatted;
4131
- }
4132
- async log(level, message, extra) {
4133
- if (!this.shouldLog(level))
4134
- return;
4135
- if (this.client) {
4136
- try {
4137
- await this.client.app.log({
4138
- service: this.service,
4139
- level,
4140
- message,
4141
- extra
4142
- });
4143
- return;
4144
- } catch {}
4145
- }
4146
- const formatted = this.formatMessage(level, message, extra);
4147
- switch (level) {
4148
- case "debug":
4149
- console.debug(formatted);
4150
- break;
4151
- case "info":
4152
- console.info(formatted);
4153
- break;
4154
- case "warn":
4155
- console.warn(formatted);
4156
- break;
4157
- case "error":
4158
- console.error(formatted);
4159
- break;
4160
- }
4161
- }
4162
- debug(message, extra) {
4163
- this.log("debug", message, extra);
4164
- }
4165
- info(message, extra) {
4166
- this.log("info", message, extra);
4167
- }
4168
- warn(message, extra) {
4169
- this.log("warn", message, extra);
4170
- }
4171
- error(message, extra) {
4172
- this.log("error", message, extra);
4173
- }
4174
- child(subService) {
4175
- return new Logger(`${this.service}:${subService}`, {
4176
- minLevel: this.minLevel,
4177
- client: this.client
4178
- });
4179
- }
4180
- }
4181
- function createLogger(service, client) {
4182
- return new Logger(service, { client });
4183
- }
4184
- var LOG_COLORS, RESET = "\x1B[0m", logger;
4185
- var init_logger = __esm(() => {
4186
- LOG_COLORS = {
4187
- debug: "\x1B[90m",
4188
- info: "\x1B[36m",
4189
- warn: "\x1B[33m",
4190
- error: "\x1B[31m"
4191
- };
4192
- logger = new Logger("opencode-sonarqube");
4193
- });
4194
-
4195
4107
  // src/utils/state.ts
4196
4108
  function getStatePath(directory) {
4197
4109
  return `${directory}/${STATE_DIR}/${STATE_FILE}`;
@@ -4285,8 +4197,20 @@ ${entry}
4285
4197
  var logger4, STATE_DIR = ".sonarqube", STATE_FILE = "project.json";
4286
4198
  var init_state = __esm(() => {
4287
4199
  init_types2();
4288
- init_logger();
4289
- logger4 = new Logger("state-manager");
4200
+ logger4 = {
4201
+ info: (msg, extra) => {
4202
+ console.log(`[SONARQUBE-STATE] ${msg}`, extra ? JSON.stringify(extra) : "");
4203
+ },
4204
+ warn: (msg, extra) => {
4205
+ console.warn(`[SONARQUBE-STATE] ${msg}`, extra ? JSON.stringify(extra) : "");
4206
+ },
4207
+ error: (msg, extra) => {
4208
+ console.error(`[SONARQUBE-STATE] ${msg}`, extra ? JSON.stringify(extra) : "");
4209
+ },
4210
+ debug: (msg, extra) => {
4211
+ console.log(`[SONARQUBE-STATE] ${msg}`, extra ? JSON.stringify(extra) : "");
4212
+ }
4213
+ };
4290
4214
  });
4291
4215
 
4292
4216
  // node_modules/@opencode-ai/plugin/node_modules/zod/v4/classic/external.js
@@ -16611,8 +16535,17 @@ function tool(input) {
16611
16535
  tool.schema = exports_external;
16612
16536
  // src/utils/config.ts
16613
16537
  init_types2();
16614
- init_logger();
16615
- var configLogger = new Logger("sonarqube-config");
16538
+ var configLogger = {
16539
+ info: (msg, extra) => {
16540
+ console.log(`[SONARQUBE-CONFIG] ${msg}`, extra ? JSON.stringify(extra) : "");
16541
+ },
16542
+ warn: (msg, extra) => {
16543
+ console.warn(`[SONARQUBE-CONFIG] ${msg}`, extra ? JSON.stringify(extra) : "");
16544
+ },
16545
+ error: (msg, extra) => {
16546
+ console.error(`[SONARQUBE-CONFIG] ${msg}`, extra ? JSON.stringify(extra) : "");
16547
+ }
16548
+ };
16616
16549
  var DEFAULT_CONFIG = {
16617
16550
  level: "enterprise",
16618
16551
  autoAnalyze: true,
@@ -16701,8 +16634,94 @@ function sanitizeProjectKey(input) {
16701
16634
  return input.toLowerCase().replaceAll(/[^a-z0-9-_]/g, "-").replaceAll(/-+/g, "-").replaceAll(/(?:^-)|(?:-$)/g, "").slice(0, 400);
16702
16635
  }
16703
16636
 
16637
+ // src/utils/logger.ts
16638
+ var LOG_COLORS = {
16639
+ debug: "\x1B[90m",
16640
+ info: "\x1B[36m",
16641
+ warn: "\x1B[33m",
16642
+ error: "\x1B[31m"
16643
+ };
16644
+ var RESET = "\x1B[0m";
16645
+
16646
+ class Logger {
16647
+ service;
16648
+ minLevel;
16649
+ client;
16650
+ constructor(service, options) {
16651
+ this.service = service;
16652
+ this.minLevel = options?.minLevel ?? "info";
16653
+ this.client = options?.client;
16654
+ }
16655
+ shouldLog(level) {
16656
+ const levels = ["debug", "info", "warn", "error"];
16657
+ return levels.indexOf(level) >= levels.indexOf(this.minLevel);
16658
+ }
16659
+ formatMessage(level, message, extra) {
16660
+ const timestamp = new Date().toISOString();
16661
+ const color = LOG_COLORS[level];
16662
+ const prefix = `${color}[${this.service}]${RESET}`;
16663
+ const levelStr = `${color}${level.toUpperCase()}${RESET}`;
16664
+ let formatted = `${prefix} ${timestamp} ${levelStr}: ${message}`;
16665
+ if (extra && Object.keys(extra).length > 0) {
16666
+ formatted += ` ${JSON.stringify(extra)}`;
16667
+ }
16668
+ return formatted;
16669
+ }
16670
+ async log(level, message, extra) {
16671
+ if (!this.shouldLog(level))
16672
+ return;
16673
+ if (this.client) {
16674
+ try {
16675
+ await this.client.app.log({
16676
+ service: this.service,
16677
+ level,
16678
+ message,
16679
+ extra
16680
+ });
16681
+ return;
16682
+ } catch {}
16683
+ }
16684
+ const formatted = this.formatMessage(level, message, extra);
16685
+ switch (level) {
16686
+ case "debug":
16687
+ console.debug(formatted);
16688
+ break;
16689
+ case "info":
16690
+ console.info(formatted);
16691
+ break;
16692
+ case "warn":
16693
+ console.warn(formatted);
16694
+ break;
16695
+ case "error":
16696
+ console.error(formatted);
16697
+ break;
16698
+ }
16699
+ }
16700
+ debug(message, extra) {
16701
+ this.log("debug", message, extra);
16702
+ }
16703
+ info(message, extra) {
16704
+ this.log("info", message, extra);
16705
+ }
16706
+ warn(message, extra) {
16707
+ this.log("warn", message, extra);
16708
+ }
16709
+ error(message, extra) {
16710
+ this.log("error", message, extra);
16711
+ }
16712
+ child(subService) {
16713
+ return new Logger(`${this.service}:${subService}`, {
16714
+ minLevel: this.minLevel,
16715
+ client: this.client
16716
+ });
16717
+ }
16718
+ }
16719
+ var logger = new Logger("opencode-sonarqube");
16720
+ function createLogger(service, client) {
16721
+ return new Logger(service, { client });
16722
+ }
16723
+
16704
16724
  // src/scanner/config.ts
16705
- init_logger();
16706
16725
  var logger2 = new Logger("scanner-config");
16707
16726
  async function checkProjectFiles(directory) {
16708
16727
  const checks3 = await Promise.all([
@@ -16970,7 +16989,6 @@ async function writePropertiesFile(options, config2, directory) {
16970
16989
  }
16971
16990
  // src/api/client.ts
16972
16991
  init_types2();
16973
- init_logger();
16974
16992
  function buildUrl(baseUrl, endpoint, params) {
16975
16993
  let url2 = `${baseUrl}${endpoint}`;
16976
16994
  if (!params) {
@@ -17057,11 +17075,10 @@ function buildAuthHeader(auth) {
17057
17075
  class SonarQubeClient {
17058
17076
  baseUrl;
17059
17077
  auth;
17060
- logger;
17061
- constructor(config2, logger3) {
17078
+ constructor(config2, _logger) {
17062
17079
  this.baseUrl = normalizeUrl(config2.url);
17063
17080
  this.auth = config2.auth;
17064
- this.logger = logger3 ?? new Logger("sonarqube-client");
17081
+ console.log(`[SONARQUBE-CLIENT] Created client for ${this.baseUrl}`);
17065
17082
  }
17066
17083
  async request(endpoint, options = {}) {
17067
17084
  const { method = "GET", params, body } = options;
@@ -17074,36 +17091,36 @@ class SonarQubeClient {
17074
17091
  if (requestBody) {
17075
17092
  headers["Content-Type"] = "application/x-www-form-urlencoded";
17076
17093
  }
17077
- this.logger.info(`>>> API Request: ${method} ${endpoint}`, {
17094
+ console.log(`[SONARQUBE-API] >>> ${method} ${endpoint}`, JSON.stringify({
17078
17095
  url: url2,
17079
- params: JSON.stringify(params),
17096
+ params,
17080
17097
  hasBody: !!body,
17081
17098
  bodyKeys: body ? Object.keys(body) : []
17082
- });
17099
+ }));
17083
17100
  try {
17084
17101
  const response = await fetch(url2, {
17085
17102
  method,
17086
17103
  headers,
17087
17104
  body: requestBody
17088
17105
  });
17089
- this.logger.info(`<<< API Response: ${method} ${endpoint}`, {
17106
+ console.log(`[SONARQUBE-API] <<< ${method} ${endpoint}`, JSON.stringify({
17090
17107
  status: response.status,
17091
17108
  ok: response.ok
17092
- });
17109
+ }));
17093
17110
  if (!response.ok) {
17094
- this.logger.error(`API Error: ${method} ${endpoint}`, {
17111
+ console.error(`[SONARQUBE-API] ERROR: ${method} ${endpoint}`, JSON.stringify({
17095
17112
  status: response.status,
17096
17113
  url: url2
17097
- });
17114
+ }));
17098
17115
  await handleResponseError(response);
17099
17116
  }
17100
17117
  const text = await response.text();
17101
17118
  return parseResponseBody(text);
17102
17119
  } catch (error45) {
17103
- this.logger.error(`API Exception: ${method} ${endpoint}`, {
17120
+ console.error(`[SONARQUBE-API] EXCEPTION: ${method} ${endpoint}`, JSON.stringify({
17104
17121
  error: String(error45),
17105
17122
  url: url2
17106
- });
17123
+ }));
17107
17124
  handleFetchError(error45, this.baseUrl);
17108
17125
  }
17109
17126
  }
@@ -17169,8 +17186,6 @@ function createClientWithCredentials(url2, user, password, logger3) {
17169
17186
  }
17170
17187
  // src/api/projects.ts
17171
17188
  init_types2();
17172
- init_logger();
17173
-
17174
17189
  class ProjectsAPI {
17175
17190
  client;
17176
17191
  logger;
@@ -17271,8 +17286,6 @@ class ProjectsAPI {
17271
17286
  }
17272
17287
  }
17273
17288
  // src/api/issues.ts
17274
- init_logger();
17275
-
17276
17289
  class IssuesAPI {
17277
17290
  client;
17278
17291
  logger;
@@ -17422,7 +17435,6 @@ class IssuesAPI {
17422
17435
  }
17423
17436
  // src/api/quality-gate.ts
17424
17437
  init_types2();
17425
- init_logger();
17426
17438
  var METRIC_KEYS = {
17427
17439
  coverage: "coverage",
17428
17440
  newCoverage: "new_coverage",
@@ -17759,8 +17771,6 @@ class QualityGateAPI {
17759
17771
  }
17760
17772
  }
17761
17773
  // src/api/rules.ts
17762
- init_logger();
17763
-
17764
17774
  class RulesAPI {
17765
17775
  client;
17766
17776
  logger;
@@ -17864,8 +17874,6 @@ class RulesAPI {
17864
17874
  }
17865
17875
  }
17866
17876
  // src/api/sources.ts
17867
- init_logger();
17868
-
17869
17877
  class SourcesAPI {
17870
17878
  client;
17871
17879
  logger;
@@ -18004,8 +18012,6 @@ class SourcesAPI {
18004
18012
  }
18005
18013
  }
18006
18014
  // src/api/duplications.ts
18007
- init_logger();
18008
-
18009
18015
  class DuplicationsAPI {
18010
18016
  client;
18011
18017
  logger;
@@ -18114,8 +18120,6 @@ class DuplicationsAPI {
18114
18120
  }
18115
18121
  }
18116
18122
  // src/api/ce.ts
18117
- init_logger();
18118
-
18119
18123
  class ComputeEngineAPI {
18120
18124
  client;
18121
18125
  logger;
@@ -18231,8 +18235,6 @@ class ComputeEngineAPI {
18231
18235
  }
18232
18236
  }
18233
18237
  // src/api/analyses.ts
18234
- init_logger();
18235
-
18236
18238
  class ProjectAnalysesAPI {
18237
18239
  client;
18238
18240
  logger;
@@ -18301,8 +18303,6 @@ class ProjectAnalysesAPI {
18301
18303
  }
18302
18304
  }
18303
18305
  // src/api/profiles.ts
18304
- init_logger();
18305
-
18306
18306
  class QualityProfilesAPI {
18307
18307
  client;
18308
18308
  logger;
@@ -18395,8 +18395,6 @@ class QualityProfilesAPI {
18395
18395
  }
18396
18396
  }
18397
18397
  // src/api/branches.ts
18398
- init_logger();
18399
-
18400
18398
  class BranchesAPI {
18401
18399
  client;
18402
18400
  logger;
@@ -18519,7 +18517,6 @@ class BranchesAPI {
18519
18517
  }
18520
18518
  }
18521
18519
  // src/api/metrics.ts
18522
- init_logger();
18523
18520
  var COMMON_METRICS = [
18524
18521
  "ncloc",
18525
18522
  "lines",
@@ -18679,8 +18676,6 @@ class MetricsAPI {
18679
18676
  }
18680
18677
  }
18681
18678
  // src/api/components.ts
18682
- init_logger();
18683
-
18684
18679
  class ComponentsAPI {
18685
18680
  client;
18686
18681
  logger;
@@ -18794,8 +18789,6 @@ class ComponentsAPI {
18794
18789
  }
18795
18790
  }
18796
18791
  // src/api/index.ts
18797
- init_logger();
18798
-
18799
18792
  class SonarQubeAPI {
18800
18793
  client;
18801
18794
  projects;
@@ -18857,18 +18850,17 @@ function createSonarQubeAPIWithToken(url2, token, logger3) {
18857
18850
  return new SonarQubeAPI(client, logger3);
18858
18851
  }
18859
18852
  function createSonarQubeAPI(config2, state, logger3) {
18860
- const apiLogger = logger3 ?? new Logger("sonarqube-api");
18861
- apiLogger.info(">>> createSonarQubeAPI called", {
18853
+ console.log(`[SONARQUBE-API] >>> createSonarQubeAPI called`, JSON.stringify({
18862
18854
  url: config2.url,
18863
18855
  projectKey: state.projectKey,
18864
18856
  projectKeyLength: state.projectKey?.length,
18865
18857
  hasToken: !!state.projectToken,
18866
18858
  tokenLength: state.projectToken?.length
18867
- });
18859
+ }));
18868
18860
  if (!state.projectToken) {
18869
- apiLogger.error("createSonarQubeAPI: projectToken is missing!");
18861
+ console.error(`[SONARQUBE-API] createSonarQubeAPI: projectToken is missing!`);
18870
18862
  }
18871
- return createSonarQubeAPIWithToken(config2.url, state.projectToken, apiLogger);
18863
+ return createSonarQubeAPIWithToken(config2.url, state.projectToken, logger3);
18872
18864
  }
18873
18865
 
18874
18866
  // src/utils/severity.ts
@@ -18972,7 +18964,6 @@ function formatIssueBlock(issue2, _number2) {
18972
18964
  }
18973
18965
 
18974
18966
  // src/scanner/runner.ts
18975
- init_logger();
18976
18967
  var logger3 = new Logger("scanner-runner");
18977
18968
  async function runScanner(config2, state, options, directory) {
18978
18969
  const dir = directory ?? process.cwd();
@@ -19147,8 +19138,17 @@ function shouldBlockOnResult(result, level) {
19147
19138
  // src/bootstrap/index.ts
19148
19139
  init_types2();
19149
19140
  init_state();
19150
- init_logger();
19151
- var logger5 = new Logger("bootstrap");
19141
+ var logger5 = {
19142
+ info: (msg, extra) => {
19143
+ console.log(`[SONARQUBE-BOOTSTRAP] ${msg}`, extra ? JSON.stringify(extra) : "");
19144
+ },
19145
+ warn: (msg, extra) => {
19146
+ console.warn(`[SONARQUBE-BOOTSTRAP] ${msg}`, extra ? JSON.stringify(extra) : "");
19147
+ },
19148
+ error: (msg, extra) => {
19149
+ console.error(`[SONARQUBE-BOOTSTRAP] ${msg}`, extra ? JSON.stringify(extra) : "");
19150
+ }
19151
+ };
19152
19152
  var QUALITY_GATE_MAPPING = {
19153
19153
  enterprise: "Sonar way",
19154
19154
  standard: "Sonar way",
@@ -19308,7 +19308,6 @@ async function configureProjectSettings(client, projectKey, languages, config2)
19308
19308
  }
19309
19309
 
19310
19310
  // src/hooks/index.ts
19311
- init_logger();
19312
19311
  var logger6 = new Logger("sonarqube-hooks");
19313
19312
  var editedFiles = new Set;
19314
19313
  var lastAnalysisTime = 0;
@@ -19469,7 +19468,6 @@ function createHooks(getConfig, getDirectory) {
19469
19468
 
19470
19469
  // src/tools/sonarqube.ts
19471
19470
  init_zod();
19472
- init_logger();
19473
19471
  var logger7 = new Logger("sonarqube-tool");
19474
19472
  var SonarQubeToolArgsSchema = exports_external2.object({
19475
19473
  action: exports_external2.enum(["analyze", "issues", "newissues", "status", "init", "setup", "validate", "hotspots", "duplications", "rule", "history", "profile", "branches", "metrics", "worstfiles"]).describe("Action to perform: analyze (run scanner), issues (all issues), newissues (only new code issues), status (quality gate), init/setup (initialize), validate (enterprise check), hotspots (security review), duplications (code duplicates), rule (explain rule), history (past analyses), profile (quality profile), branches (branch status), metrics (detailed metrics), worstfiles (files with most issues)"),
@@ -20070,10 +20068,18 @@ function getSeveritiesFromLevel(level) {
20070
20068
  }
20071
20069
 
20072
20070
  // src/index.ts
20073
- init_logger();
20074
- init_logger();
20075
20071
  init_types2();
20076
- var debugLog = new Logger("sonarqube-debug");
20072
+ var debugLog = {
20073
+ info: (msg, extra) => {
20074
+ console.log(`[SONARQUBE-DEBUG] ${msg}`, extra ? JSON.stringify(extra) : "");
20075
+ },
20076
+ warn: (msg, extra) => {
20077
+ console.warn(`[SONARQUBE-DEBUG] ${msg}`, extra ? JSON.stringify(extra) : "");
20078
+ },
20079
+ error: (msg, extra) => {
20080
+ console.error(`[SONARQUBE-DEBUG] ${msg}`, extra ? JSON.stringify(extra) : "");
20081
+ }
20082
+ };
20077
20083
  var IGNORED_FILE_PATTERNS2 = [
20078
20084
  /node_modules/,
20079
20085
  /\.git/,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-sonarqube",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
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",