@xcelera/cli 2.1.1 → 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
@@ -9295,8 +9295,8 @@ async function getRemoteUrl() {
9295
9295
  }
9296
9296
  return remoteUrl;
9297
9297
  }
9298
- catch {
9299
- throw new Error('Could not determine git remote URL. Please ensure you have an origin remote configured.');
9298
+ catch (error) {
9299
+ throw new Error('Could not determine git remote URL. Please ensure you have an origin remote configured.', { cause: error });
9300
9300
  }
9301
9301
  }
9302
9302
  async function isGitRepository() {
@@ -9304,7 +9304,11 @@ 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
- const commit = await simpleGit().show([hash, '--format=%H|%s|%an|%ae|%ai']);
9307
+ const commit = await simpleGit().show([
9308
+ hash,
9309
+ '--no-patch',
9310
+ '--format=%H|%s|%an|%ae|%ai'
9311
+ ]);
9308
9312
  const [resolvedHash, message, author_name, author_email, date] = commit
9309
9313
  .trim()
9310
9314
  .split('|');
@@ -9316,7 +9320,7 @@ async function getCommit(hash = 'HEAD') {
9316
9320
  message: message,
9317
9321
  author: author_name || 'Unknown',
9318
9322
  email: author_email || '',
9319
- date: date || new Date().toISOString()
9323
+ date: date ? new Date(date).toISOString() : new Date().toISOString()
9320
9324
  };
9321
9325
  }
9322
9326
 
@@ -9327,24 +9331,111 @@ async function inferBuildContext() {
9327
9331
  branch: ('prBranch' in ciEnv && ciEnv.prBranch ? ciEnv.prBranch : ciEnv.branch) ??
9328
9332
  undefined
9329
9333
  };
9330
- const buildContext = {
9334
+ return {
9331
9335
  service: ciEnv.isCi ? ciEnv.service : 'unknown',
9332
9336
  prNumber: 'pr' in ciEnv ? ciEnv.pr : undefined,
9333
9337
  buildNumber: 'build' in ciEnv ? ciEnv.build : undefined,
9334
9338
  buildUrl: 'buildUrl' in ciEnv ? ciEnv.buildUrl : undefined,
9335
9339
  git: gitContext
9336
9340
  };
9337
- console.log('🔍 Inferred build context:');
9338
- if (buildContext.service) {
9339
- 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 };
9340
9380
  }
9341
- console.log(` • repository: ${gitContext.owner}/${gitContext.repo}`);
9342
- console.log(` • branch: ${gitContext.branch}`);
9343
- console.log(` • commit: ${gitContext.commit.hash}`);
9344
- console.log('');
9345
- 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 };
9346
9436
  }
9347
9437
 
9438
+ /* istanbul ignore file */
9348
9439
  const options = {
9349
9440
  url: {
9350
9441
  type: 'string',
@@ -9369,6 +9460,7 @@ if (!command) {
9369
9460
  }
9370
9461
  if (command === 'help') {
9371
9462
  printHelp();
9463
+ process.exit(0);
9372
9464
  }
9373
9465
  if (command !== 'audit') {
9374
9466
  console.error('Invalid command. Only "audit" is currently supported.');
@@ -9384,42 +9476,10 @@ if (!token) {
9384
9476
  console.error('A token is required. Use --token or set XCELERA_TOKEN environment variable.');
9385
9477
  process.exit(1);
9386
9478
  }
9387
- try {
9388
- const buildContext = await inferBuildContext();
9389
- const response = await requestAudit(url, token, buildContext);
9390
- if (!response.success) {
9391
- const { message, details } = response.error;
9392
- console.error('❌ Unable to schedule audit :(');
9393
- console.error(` ↳ ${message}`);
9394
- if (details) {
9395
- console.error(` ↳ ${details}`);
9396
- }
9397
- process.exit(1);
9398
- }
9399
- const { auditId, status, integrations } = response.data;
9400
- console.log('✅ Audit scheduled successfully!');
9401
- if (process.env.DEBUG) {
9402
- console.log(`Audit ID: ${auditId}`);
9403
- console.log(`Status: ${status}`);
9404
- }
9405
- if (integrations && integrations.github) {
9406
- console.log('GitHub integration detected');
9407
- const { installationId, hasRepoAccess } = integrations.github;
9408
- if (installationId && !hasRepoAccess) {
9409
- console.log('Warning: The xcelera.dev Github app is installed, but it does not have repository access.');
9410
- }
9411
- if (process.env.DEBUG) {
9412
- console.log(` ↳ installation ID: ${integrations.github.installationId}`);
9413
- console.log(` ↳ check run ID: ${integrations.github.checkRunId}`);
9414
- console.log(` ↳ installation has repo access: ${integrations.github.hasRepoAccess}`);
9415
- }
9416
- }
9417
- }
9418
- catch (error) {
9419
- const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
9420
- console.error(`❌ ${errorMessage}`);
9421
- process.exit(1);
9422
- }
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);
9423
9483
  function printHelp() {
9424
9484
  console.log('Usage: xcelera audit --url <url> [--token <token>]');
9425
9485
  console.log('');