@xcelera/cli 2.1.2 → 2.2.1

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
@@ -9304,14 +9304,15 @@ async function isGitRepository() {
9304
9304
  }
9305
9305
  async function getCommit(hash = 'HEAD') {
9306
9306
  // format: %H: commit hash, %s: subject, %an: author name, %ae: author email, %ai: author date
9307
+ // Use null byte (%x00) as delimiter - cannot appear in commit data
9307
9308
  const commit = await simpleGit().show([
9308
9309
  hash,
9309
9310
  '--no-patch',
9310
- '--format=%H|%s|%an|%ae|%ai'
9311
+ '--format=%H%x00%s%x00%an%x00%ae%x00%ai'
9311
9312
  ]);
9312
9313
  const [resolvedHash, message, author_name, author_email, date] = commit
9313
9314
  .trim()
9314
- .split('|');
9315
+ .split('\0');
9315
9316
  if (!resolvedHash) {
9316
9317
  throw new Error(`No commit found for ${hash}`);
9317
9318
  }
@@ -9331,24 +9332,115 @@ async function inferBuildContext() {
9331
9332
  branch: ('prBranch' in ciEnv && ciEnv.prBranch ? ciEnv.prBranch : ciEnv.branch) ??
9332
9333
  undefined
9333
9334
  };
9334
- const buildContext = {
9335
+ return {
9335
9336
  service: ciEnv.isCi ? ciEnv.service : 'unknown',
9336
9337
  prNumber: 'pr' in ciEnv ? ciEnv.pr : undefined,
9337
9338
  buildNumber: 'build' in ciEnv ? ciEnv.build : undefined,
9338
9339
  buildUrl: 'buildUrl' in ciEnv ? ciEnv.buildUrl : undefined,
9339
9340
  git: gitContext
9340
9341
  };
9341
- console.log('🔍 Inferred build context:');
9342
- if (buildContext.service) {
9343
- console.log(` • service: ${buildContext.service}`);
9342
+ }
9343
+
9344
+ async function runAuditCommand(url, token) {
9345
+ const output = [];
9346
+ const errors = [];
9347
+ try {
9348
+ const buildContext = await inferBuildContext();
9349
+ output.push(...formatBuildContext(buildContext));
9350
+ const response = await requestAudit(url, token, buildContext);
9351
+ if (!response.success) {
9352
+ const { message, details } = response.error;
9353
+ errors.push('❌ Unable to schedule audit :(');
9354
+ errors.push(` ↳ ${message}`);
9355
+ if (details) {
9356
+ errors.push(` ↳ ${details}`);
9357
+ }
9358
+ return { exitCode: 1, output, errors };
9359
+ }
9360
+ const { auditId, status, integrations } = response.data;
9361
+ output.push('✅ Audit scheduled successfully!');
9362
+ if (process.env.DEBUG) {
9363
+ output.push('');
9364
+ output.push(`Audit ID: ${auditId}`);
9365
+ output.push(`Status: ${status}`);
9366
+ if (Object.keys(integrations).length === 0) {
9367
+ output.push('No integrations detected');
9368
+ }
9369
+ }
9370
+ if (integrations?.github) {
9371
+ const githubOutput = formatGitHubIntegrationStatus(integrations.github);
9372
+ output.push(...githubOutput.output);
9373
+ errors.push(...githubOutput.errors);
9374
+ }
9375
+ return { exitCode: 0, output, errors };
9344
9376
  }
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;
9377
+ catch (error) {
9378
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
9379
+ errors.push(`❌ ${errorMessage}`);
9380
+ if (error instanceof Error && error.stack) {
9381
+ errors.push('');
9382
+ errors.push(error.stack);
9383
+ }
9384
+ return { exitCode: 1, output, errors };
9385
+ }
9386
+ }
9387
+ function formatBuildContext(context) {
9388
+ const logs = [];
9389
+ logs.push('🔍 Inferred build context:');
9390
+ if (context.service) {
9391
+ logs.push(` • service: ${context.service}`);
9392
+ }
9393
+ if (context.git) {
9394
+ logs.push(` • repository: ${context.git.owner}/${context.git.repo}`);
9395
+ logs.push(` • branch: ${context.git.branch}`);
9396
+ logs.push(` • commit: ${context.git.commit.hash}`);
9397
+ }
9398
+ logs.push('');
9399
+ return logs;
9400
+ }
9401
+ function formatGitHubIntegrationStatus(context) {
9402
+ const output = [];
9403
+ const errors = [];
9404
+ output.push('');
9405
+ switch (context.status) {
9406
+ case 'success': {
9407
+ output.push('✅ GitHub integration detected!');
9408
+ if (process.env.DEBUG) {
9409
+ output.push(` ↳ installation ID: ${context.installationId}`);
9410
+ output.push(` ↳ check run ID: ${context.checkRunId}`);
9411
+ }
9412
+ break;
9413
+ }
9414
+ case 'skipped': {
9415
+ if (process.env.DEBUG) {
9416
+ const reasonMessage = context.reason === 'no_git_context'
9417
+ ? 'no git context detected; skipping GitHub integration.'
9418
+ : 'GitHub app not installed; skipping GitHub integration.';
9419
+ output.push(`↳ GitHub integration skipped: ${reasonMessage}`);
9420
+ }
9421
+ break;
9422
+ }
9423
+ case 'misconfigured': {
9424
+ errors.push('⚠️ GitHub integration is misconfigured.');
9425
+ if (context.reason === 'no_repo_access') {
9426
+ errors.push('The xcelera.dev GitHub app is installed, but it does not have access to this repository.');
9427
+ errors.push('Please update the GitHub app installation and grant access to this repository.');
9428
+ }
9429
+ if (process.env.DEBUG) {
9430
+ errors.push(` ↳ installation ID: ${context.installationId}`);
9431
+ }
9432
+ break;
9433
+ }
9434
+ case 'error': {
9435
+ errors.push('⚠️ Something went wrong with the GitHub integration.');
9436
+ errors.push('Your audit was scheduled successfully, but we could not create or update the GitHub check run.');
9437
+ break;
9438
+ }
9439
+ }
9440
+ return { output, errors };
9350
9441
  }
9351
9442
 
9443
+ /* istanbul ignore file */
9352
9444
  const options = {
9353
9445
  url: {
9354
9446
  type: 'string',
@@ -9373,6 +9465,7 @@ if (!command) {
9373
9465
  }
9374
9466
  if (command === 'help') {
9375
9467
  printHelp();
9468
+ process.exit(0);
9376
9469
  }
9377
9470
  if (command !== 'audit') {
9378
9471
  console.error('Invalid command. Only "audit" is currently supported.');
@@ -9388,44 +9481,10 @@ if (!token) {
9388
9481
  console.error('A token is required. Use --token or set XCELERA_TOKEN environment variable.');
9389
9482
  process.exit(1);
9390
9483
  }
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
- }
9484
+ const result = await runAuditCommand(url, token);
9485
+ result.output.forEach((line) => console.log(line));
9486
+ result.errors.forEach((line) => console.error(line));
9487
+ process.exit(result.exitCode);
9429
9488
  function printHelp() {
9430
9489
  console.log('Usage: xcelera audit --url <url> [--token <token>]');
9431
9490
  console.log('');