@xcelera/cli 2.1.2 → 2.2.0

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/cli.js CHANGED
@@ -9331,24 +9331,111 @@ async function inferBuildContext() {
9331
9331
  branch: ('prBranch' in ciEnv && ciEnv.prBranch ? ciEnv.prBranch : ciEnv.branch) ??
9332
9332
  undefined
9333
9333
  };
9334
- const buildContext = {
9334
+ return {
9335
9335
  service: ciEnv.isCi ? ciEnv.service : 'unknown',
9336
9336
  prNumber: 'pr' in ciEnv ? ciEnv.pr : undefined,
9337
9337
  buildNumber: 'build' in ciEnv ? ciEnv.build : undefined,
9338
9338
  buildUrl: 'buildUrl' in ciEnv ? ciEnv.buildUrl : undefined,
9339
9339
  git: gitContext
9340
9340
  };
9341
- console.log('🔍 Inferred build context:');
9342
- if (buildContext.service) {
9343
- console.log(` • service: ${buildContext.service}`);
9341
+ }
9342
+
9343
+ async function runAuditCommand(url, token) {
9344
+ const output = [];
9345
+ const errors = [];
9346
+ try {
9347
+ const buildContext = await inferBuildContext();
9348
+ output.push(...formatBuildContext(buildContext));
9349
+ const response = await requestAudit(url, token, buildContext);
9350
+ if (!response.success) {
9351
+ const { message, details } = response.error;
9352
+ errors.push('❌ Unable to schedule audit :(');
9353
+ errors.push(` ↳ ${message}`);
9354
+ if (details) {
9355
+ errors.push(` ↳ ${details}`);
9356
+ }
9357
+ return { exitCode: 1, output, errors };
9358
+ }
9359
+ const { auditId, status, integrations } = response.data;
9360
+ output.push('✅ Audit scheduled successfully!');
9361
+ if (process.env.DEBUG) {
9362
+ output.push('');
9363
+ output.push(`Audit ID: ${auditId}`);
9364
+ output.push(`Status: ${status}`);
9365
+ if (Object.keys(integrations).length === 0) {
9366
+ output.push('No integrations detected');
9367
+ }
9368
+ }
9369
+ if (integrations?.github) {
9370
+ const githubOutput = formatGitHubIntegrationStatus(integrations.github);
9371
+ output.push(...githubOutput.output);
9372
+ errors.push(...githubOutput.errors);
9373
+ }
9374
+ return { exitCode: 0, output, errors };
9375
+ }
9376
+ catch (error) {
9377
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
9378
+ errors.push(`❌ ${errorMessage}`);
9379
+ return { exitCode: 1, output, errors };
9344
9380
  }
9345
- console.log(` • repository: ${gitContext.owner}/${gitContext.repo}`);
9346
- console.log(` • branch: ${gitContext.branch}`);
9347
- console.log(` • commit: ${gitContext.commit.hash}`);
9348
- console.log('');
9349
- return buildContext;
9381
+ }
9382
+ function formatBuildContext(context) {
9383
+ const logs = [];
9384
+ logs.push('🔍 Inferred build context:');
9385
+ if (context.service) {
9386
+ logs.push(` • service: ${context.service}`);
9387
+ }
9388
+ if (context.git) {
9389
+ logs.push(` • repository: ${context.git.owner}/${context.git.repo}`);
9390
+ logs.push(` • branch: ${context.git.branch}`);
9391
+ logs.push(` • commit: ${context.git.commit.hash}`);
9392
+ }
9393
+ logs.push('');
9394
+ return logs;
9395
+ }
9396
+ function formatGitHubIntegrationStatus(context) {
9397
+ const output = [];
9398
+ const errors = [];
9399
+ output.push('');
9400
+ switch (context.status) {
9401
+ case 'success': {
9402
+ output.push('✅ GitHub integration detected!');
9403
+ if (process.env.DEBUG) {
9404
+ output.push(` ↳ installation ID: ${context.installationId}`);
9405
+ output.push(` ↳ check run ID: ${context.checkRunId}`);
9406
+ }
9407
+ break;
9408
+ }
9409
+ case 'skipped': {
9410
+ if (process.env.DEBUG) {
9411
+ const reasonMessage = context.reason === 'no_git_context'
9412
+ ? 'no git context detected; skipping GitHub integration.'
9413
+ : 'GitHub app not installed; skipping GitHub integration.';
9414
+ output.push(`↳ GitHub integration skipped: ${reasonMessage}`);
9415
+ }
9416
+ break;
9417
+ }
9418
+ case 'misconfigured': {
9419
+ errors.push('⚠️ GitHub integration is misconfigured.');
9420
+ if (context.reason === 'no_repo_access') {
9421
+ errors.push('The xcelera.dev GitHub app is installed, but it does not have access to this repository.');
9422
+ errors.push('Please update the GitHub app installation and grant access to this repository.');
9423
+ }
9424
+ if (process.env.DEBUG) {
9425
+ errors.push(` ↳ installation ID: ${context.installationId}`);
9426
+ }
9427
+ break;
9428
+ }
9429
+ case 'error': {
9430
+ errors.push('⚠️ Something went wrong with the GitHub integration.');
9431
+ errors.push('Your audit was scheduled successfully, but we could not create or update the GitHub check run.');
9432
+ break;
9433
+ }
9434
+ }
9435
+ return { output, errors };
9350
9436
  }
9351
9437
 
9438
+ /* istanbul ignore file */
9352
9439
  const options = {
9353
9440
  url: {
9354
9441
  type: 'string',
@@ -9373,6 +9460,7 @@ if (!command) {
9373
9460
  }
9374
9461
  if (command === 'help') {
9375
9462
  printHelp();
9463
+ process.exit(0);
9376
9464
  }
9377
9465
  if (command !== 'audit') {
9378
9466
  console.error('Invalid command. Only "audit" is currently supported.');
@@ -9388,44 +9476,10 @@ if (!token) {
9388
9476
  console.error('A token is required. Use --token or set XCELERA_TOKEN environment variable.');
9389
9477
  process.exit(1);
9390
9478
  }
9391
- try {
9392
- const buildContext = await inferBuildContext();
9393
- const response = await requestAudit(url, token, buildContext);
9394
- if (!response.success) {
9395
- const { message, details } = response.error;
9396
- console.error('❌ Unable to schedule audit :(');
9397
- console.error(` ↳ ${message}`);
9398
- if (details) {
9399
- console.error(` ↳ ${details}`);
9400
- }
9401
- process.exit(1);
9402
- }
9403
- const { auditId, status, integrations } = response.data;
9404
- console.log('✅ Audit scheduled successfully!');
9405
- if (process.env.DEBUG) {
9406
- console.log('');
9407
- console.log(`Audit ID: ${auditId}`);
9408
- console.log(`Status: ${status}`);
9409
- }
9410
- if (integrations && integrations.github) {
9411
- console.log('');
9412
- console.log('GitHub integration detected');
9413
- const { installationId, hasRepoAccess } = integrations.github;
9414
- if (installationId && !hasRepoAccess) {
9415
- console.log('Warning: The xcelera.dev Github app is installed, but it does not have repository access.');
9416
- }
9417
- if (process.env.DEBUG) {
9418
- console.log(` ↳ installation ID: ${integrations.github.installationId}`);
9419
- console.log(` ↳ check run ID: ${integrations.github.checkRunId}`);
9420
- console.log(` ↳ installation has repo access: ${integrations.github.hasRepoAccess}`);
9421
- }
9422
- }
9423
- }
9424
- catch (error) {
9425
- const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
9426
- console.error(`❌ ${errorMessage}`);
9427
- process.exit(1);
9428
- }
9479
+ const result = await runAuditCommand(url, token);
9480
+ result.output.forEach((line) => console.log(line));
9481
+ result.errors.forEach((line) => console.error(line));
9482
+ process.exit(result.exitCode);
9429
9483
  function printHelp() {
9430
9484
  console.log('Usage: xcelera audit --url <url> [--token <token>]');
9431
9485
  console.log('');