@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/action.js CHANGED
@@ -36530,8 +36530,8 @@ async function getRemoteUrl() {
36530
36530
  }
36531
36531
  return remoteUrl;
36532
36532
  }
36533
- catch {
36534
- throw new Error('Could not determine git remote URL. Please ensure you have an origin remote configured.');
36533
+ catch (error) {
36534
+ throw new Error('Could not determine git remote URL. Please ensure you have an origin remote configured.', { cause: error });
36535
36535
  }
36536
36536
  }
36537
36537
  async function isGitRepository() {
@@ -36539,7 +36539,11 @@ async function isGitRepository() {
36539
36539
  }
36540
36540
  async function getCommit(hash = 'HEAD') {
36541
36541
  // format: %H: commit hash, %s: subject, %an: author name, %ae: author email, %ai: author date
36542
- const commit = await simpleGit().show([hash, '--format=%H|%s|%an|%ae|%ai']);
36542
+ const commit = await simpleGit().show([
36543
+ hash,
36544
+ '--no-patch',
36545
+ '--format=%H|%s|%an|%ae|%ai'
36546
+ ]);
36543
36547
  const [resolvedHash, message, author_name, author_email, date] = commit
36544
36548
  .trim()
36545
36549
  .split('|');
@@ -36551,7 +36555,7 @@ async function getCommit(hash = 'HEAD') {
36551
36555
  message: message,
36552
36556
  author: author_name || 'Unknown',
36553
36557
  email: author_email || '',
36554
- date: date || new Date().toISOString()
36558
+ date: date ? new Date(date).toISOString() : new Date().toISOString()
36555
36559
  };
36556
36560
  }
36557
36561
 
@@ -36562,62 +36566,124 @@ async function inferBuildContext() {
36562
36566
  branch: ('prBranch' in ciEnv && ciEnv.prBranch ? ciEnv.prBranch : ciEnv.branch) ??
36563
36567
  undefined
36564
36568
  };
36565
- const buildContext = {
36569
+ return {
36566
36570
  service: ciEnv.isCi ? ciEnv.service : 'unknown',
36567
36571
  prNumber: 'pr' in ciEnv ? ciEnv.pr : undefined,
36568
36572
  buildNumber: 'build' in ciEnv ? ciEnv.build : undefined,
36569
36573
  buildUrl: 'buildUrl' in ciEnv ? ciEnv.buildUrl : undefined,
36570
36574
  git: gitContext
36571
36575
  };
36572
- console.log('🔍 Inferred build context:');
36573
- if (buildContext.service) {
36574
- console.log(` • service: ${buildContext.service}`);
36575
- }
36576
- console.log(` • repository: ${gitContext.owner}/${gitContext.repo}`);
36577
- console.log(` • branch: ${gitContext.branch}`);
36578
- console.log(` • commit: ${gitContext.commit.hash}`);
36579
- console.log('');
36580
- return buildContext;
36581
36576
  }
36582
36577
 
36583
- run();
36584
- async function run() {
36578
+ async function runAuditCommand(url, token) {
36579
+ const output = [];
36580
+ const errors = [];
36585
36581
  try {
36586
- const url = coreExports.getInput('url', { required: true });
36587
- const token = coreExports.getInput('token', { required: true });
36588
36582
  const buildContext = await inferBuildContext();
36589
- coreExports.debug(`Calling xcelera audit API with URL: ${url}`);
36583
+ output.push(...formatBuildContext(buildContext));
36590
36584
  const response = await requestAudit(url, token, buildContext);
36591
36585
  if (!response.success) {
36592
36586
  const { message, details } = response.error;
36593
- coreExports.setFailed('❌ Unable to schedule audit :(');
36594
- coreExports.error(message);
36587
+ errors.push('❌ Unable to schedule audit :(');
36588
+ errors.push(` ↳ ${message}`);
36595
36589
  if (details) {
36596
- coreExports.error(` ↳ ${details}`);
36590
+ errors.push(` ↳ ${details}`);
36597
36591
  }
36598
- coreExports.setOutput('status', 'failed');
36599
- return;
36592
+ return { exitCode: 1, output, errors };
36600
36593
  }
36601
36594
  const { auditId, status, integrations } = response.data;
36602
- coreExports.info('✅ Audit scheduled successfully!');
36603
- coreExports.debug(`Audit ID: ${auditId}`);
36604
- coreExports.debug(`Status: ${status}`);
36605
- if (integrations && integrations.github) {
36606
- coreExports.info('GitHub integration detected');
36607
- const { installationId, hasRepoAccess } = integrations.github;
36608
- if (installationId && !hasRepoAccess) {
36609
- coreExports.warning('The xcelera.dev Github app is installed, but it does not have repository access.');
36595
+ output.push('✅ Audit scheduled successfully!');
36596
+ if (process.env.DEBUG) {
36597
+ output.push('');
36598
+ output.push(`Audit ID: ${auditId}`);
36599
+ output.push(`Status: ${status}`);
36600
+ if (Object.keys(integrations).length === 0) {
36601
+ output.push('No integrations detected');
36610
36602
  }
36611
- coreExports.debug(` ↳ installation ID: ${integrations.github.installationId}`);
36612
- coreExports.debug(` ↳ check run ID: ${integrations.github.checkRunId}`);
36613
- coreExports.debug(` ↳ installation has repo access: ${integrations.github.hasRepoAccess}`);
36614
36603
  }
36604
+ if (integrations?.github) {
36605
+ const githubOutput = formatGitHubIntegrationStatus(integrations.github);
36606
+ output.push(...githubOutput.output);
36607
+ errors.push(...githubOutput.errors);
36608
+ }
36609
+ return { exitCode: 0, output, errors };
36615
36610
  }
36616
36611
  catch (error) {
36617
36612
  const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
36618
- coreExports.error(`❌ ${errorMessage}`);
36619
- coreExports.setFailed(errorMessage);
36613
+ errors.push(`❌ ${errorMessage}`);
36614
+ return { exitCode: 1, output, errors };
36615
+ }
36616
+ }
36617
+ function formatBuildContext(context) {
36618
+ const logs = [];
36619
+ logs.push('🔍 Inferred build context:');
36620
+ if (context.service) {
36621
+ logs.push(` • service: ${context.service}`);
36622
+ }
36623
+ if (context.git) {
36624
+ logs.push(` • repository: ${context.git.owner}/${context.git.repo}`);
36625
+ logs.push(` • branch: ${context.git.branch}`);
36626
+ logs.push(` • commit: ${context.git.commit.hash}`);
36627
+ }
36628
+ logs.push('');
36629
+ return logs;
36630
+ }
36631
+ function formatGitHubIntegrationStatus(context) {
36632
+ const output = [];
36633
+ const errors = [];
36634
+ output.push('');
36635
+ switch (context.status) {
36636
+ case 'success': {
36637
+ output.push('✅ GitHub integration detected!');
36638
+ if (process.env.DEBUG) {
36639
+ output.push(` ↳ installation ID: ${context.installationId}`);
36640
+ output.push(` ↳ check run ID: ${context.checkRunId}`);
36641
+ }
36642
+ break;
36643
+ }
36644
+ case 'skipped': {
36645
+ if (process.env.DEBUG) {
36646
+ const reasonMessage = context.reason === 'no_git_context'
36647
+ ? 'no git context detected; skipping GitHub integration.'
36648
+ : 'GitHub app not installed; skipping GitHub integration.';
36649
+ output.push(`↳ GitHub integration skipped: ${reasonMessage}`);
36650
+ }
36651
+ break;
36652
+ }
36653
+ case 'misconfigured': {
36654
+ errors.push('⚠️ GitHub integration is misconfigured.');
36655
+ if (context.reason === 'no_repo_access') {
36656
+ errors.push('The xcelera.dev GitHub app is installed, but it does not have access to this repository.');
36657
+ errors.push('Please update the GitHub app installation and grant access to this repository.');
36658
+ }
36659
+ if (process.env.DEBUG) {
36660
+ errors.push(` ↳ installation ID: ${context.installationId}`);
36661
+ }
36662
+ break;
36663
+ }
36664
+ case 'error': {
36665
+ errors.push('⚠️ Something went wrong with the GitHub integration.');
36666
+ errors.push('Your audit was scheduled successfully, but we could not create or update the GitHub check run.');
36667
+ break;
36668
+ }
36669
+ }
36670
+ return { output, errors };
36671
+ }
36672
+
36673
+ /* istanbul ignore file */
36674
+ run();
36675
+ async function run() {
36676
+ const url = coreExports.getInput('url', { required: true });
36677
+ const token = coreExports.getInput('token', { required: true });
36678
+ const result = await runAuditCommand(url, token);
36679
+ result.output.forEach((line) => coreExports.info(line));
36680
+ result.errors.forEach((line) => coreExports.error(line));
36681
+ if (result.exitCode !== 0) {
36682
+ coreExports.setFailed('Audit command failed');
36620
36683
  coreExports.setOutput('status', 'failed');
36621
36684
  }
36685
+ else {
36686
+ coreExports.setOutput('status', 'success');
36687
+ }
36622
36688
  }
36623
36689
  //# sourceMappingURL=action.js.map