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