@probelabs/visor 0.1.29 → 0.1.30

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.
Files changed (2) hide show
  1. package/dist/index.js +111 -40
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -86257,7 +86257,7 @@ async function handleEvent(octokit, inputs, eventName, context, config) {
86257
86257
  // Handle different GitHub events
86258
86258
  switch (eventName) {
86259
86259
  case 'issue_comment':
86260
- await handleIssueComment(octokit, owner, repo, context, inputs);
86260
+ await handleIssueComment(octokit, owner, repo, context, inputs, config, checksToRun);
86261
86261
  break;
86262
86262
  case 'pull_request':
86263
86263
  // Run the checks that are configured for this event
@@ -86383,7 +86383,7 @@ async function handleIssueEvent(octokit, owner, repo, context, inputs, config, c
86383
86383
  throw error;
86384
86384
  }
86385
86385
  }
86386
- async function handleIssueComment(octokit, owner, repo, context, inputs) {
86386
+ async function handleIssueComment(octokit, owner, repo, context, inputs, actionConfig, _actionChecksToRun) {
86387
86387
  const comment = context.event?.comment;
86388
86388
  const issue = context.event?.issue;
86389
86389
  if (!comment || !issue) {
@@ -86399,33 +86399,42 @@ async function handleIssueComment(octokit, owner, repo, context, inputs) {
86399
86399
  }
86400
86400
  // Process comments on both issues and PRs
86401
86401
  // (issue.pull_request exists for PR comments, doesn't exist for issue comments)
86402
+ const isPullRequest = !!issue.pull_request;
86402
86403
  // Load configuration to get available commands
86403
86404
  const configManager = new config_1.ConfigManager();
86404
86405
  let config;
86405
86406
  const commandRegistry = {};
86406
- try {
86407
- config = await configManager.findAndLoadConfig();
86408
- // Build command registry from config
86409
- if (config.checks) {
86410
- // Add 'review' command that runs all checks
86411
- commandRegistry['review'] = Object.keys(config.checks);
86412
- // Also add individual check names as commands
86413
- for (const [checkId, checkConfig] of Object.entries(config.checks)) {
86414
- // Legacy: check if it has old 'command' property
86415
- if (checkConfig.command) {
86416
- if (!commandRegistry[checkConfig.command]) {
86417
- commandRegistry[checkConfig.command] = [];
86418
- }
86419
- commandRegistry[checkConfig.command].push(checkId);
86407
+ // Use provided config if available (from action), otherwise load it
86408
+ if (actionConfig) {
86409
+ config = actionConfig;
86410
+ }
86411
+ else {
86412
+ try {
86413
+ config = await configManager.findAndLoadConfig();
86414
+ }
86415
+ catch {
86416
+ console.log('Could not load config, using defaults');
86417
+ config = undefined;
86418
+ }
86419
+ }
86420
+ // Build command registry from config
86421
+ if (config?.checks) {
86422
+ // Add 'review' command that runs all checks
86423
+ commandRegistry['review'] = Object.keys(config.checks);
86424
+ // Also add individual check names as commands
86425
+ for (const [checkId, checkConfig] of Object.entries(config.checks)) {
86426
+ // Legacy: check if it has old 'command' property
86427
+ if (checkConfig.command) {
86428
+ if (!commandRegistry[checkConfig.command]) {
86429
+ commandRegistry[checkConfig.command] = [];
86420
86430
  }
86421
- // New: add check name as command
86422
- commandRegistry[checkId] = [checkId];
86431
+ commandRegistry[checkConfig.command].push(checkId);
86423
86432
  }
86433
+ // New: add check name as command
86434
+ commandRegistry[checkId] = [checkId];
86424
86435
  }
86425
86436
  }
86426
- catch {
86427
- console.log('Could not load config, using defaults');
86428
- config = undefined;
86437
+ else {
86429
86438
  // Default commands when no config is available
86430
86439
  commandRegistry['review'] = ['security', 'performance', 'style', 'architecture'];
86431
86440
  }
@@ -86442,22 +86451,40 @@ async function handleIssueComment(octokit, owner, repo, context, inputs) {
86442
86451
  const reviewer = new reviewer_1.PRReviewer(octokit);
86443
86452
  switch (command.type) {
86444
86453
  case 'status':
86445
- const statusPrInfo = await analyzer.fetchPRDiff(owner, repo, prNumber, undefined, 'issue_comment');
86446
- const statusComment = `## 📊 PR Status\n\n` +
86447
- `**Title:** ${statusPrInfo.title}\n` +
86448
- `**Author:** ${statusPrInfo.author}\n` +
86449
- `**Files Changed:** ${statusPrInfo.files.length}\n` +
86450
- `**Additions:** +${statusPrInfo.totalAdditions}\n` +
86451
- `**Deletions:** -${statusPrInfo.totalDeletions}\n` +
86452
- `**Base:** ${statusPrInfo.base} → **Head:** ${statusPrInfo.head}\n\n` +
86453
- `\n---\n\n` +
86454
- `*Powered by [Visor](https://probelabs.com/visor) from [Probelabs](https://probelabs.com)*`;
86455
- await octokit.rest.issues.createComment({
86456
- owner,
86457
- repo,
86458
- issue_number: prNumber,
86459
- body: statusComment,
86460
- });
86454
+ if (isPullRequest) {
86455
+ const statusPrInfo = await analyzer.fetchPRDiff(owner, repo, prNumber, undefined, 'issue_comment');
86456
+ const statusComment = `## 📊 PR Status\n\n` +
86457
+ `**Title:** ${statusPrInfo.title}\n` +
86458
+ `**Author:** ${statusPrInfo.author}\n` +
86459
+ `**Files Changed:** ${statusPrInfo.files.length}\n` +
86460
+ `**Additions:** +${statusPrInfo.totalAdditions}\n` +
86461
+ `**Deletions:** -${statusPrInfo.totalDeletions}\n` +
86462
+ `**Base:** ${statusPrInfo.base} → **Head:** ${statusPrInfo.head}\n\n` +
86463
+ `\n---\n\n` +
86464
+ `*Powered by [Visor](https://probelabs.com/visor) from [Probelabs](https://probelabs.com)*`;
86465
+ await octokit.rest.issues.createComment({
86466
+ owner,
86467
+ repo,
86468
+ issue_number: prNumber,
86469
+ body: statusComment,
86470
+ });
86471
+ }
86472
+ else {
86473
+ const statusComment = `## 📊 Issue Status\n\n` +
86474
+ `**Title:** ${issue.title || 'N/A'}\n` +
86475
+ `**Author:** ${issue.user?.login || 'unknown'}\n` +
86476
+ `**State:** ${issue.state || 'open'}\n` +
86477
+ `**Comments:** ${issue.comments || 0}\n` +
86478
+ `**Created:** ${issue.created_at || 'unknown'}\n` +
86479
+ `\n---\n\n` +
86480
+ `*Powered by [Visor](https://probelabs.com/visor) from [Probelabs](https://probelabs.com)*`;
86481
+ await octokit.rest.issues.createComment({
86482
+ owner,
86483
+ repo,
86484
+ issue_number: prNumber,
86485
+ body: statusComment,
86486
+ });
86487
+ }
86461
86488
  break;
86462
86489
  case 'help':
86463
86490
  await octokit.rest.issues.createComment({
@@ -86474,7 +86501,28 @@ async function handleIssueComment(octokit, owner, repo, context, inputs) {
86474
86501
  // Resolve all dependencies recursively
86475
86502
  const checkIds = resolveDependencies(initialCheckIds, config);
86476
86503
  console.log(`Running checks for command /${command.type} (initial: ${initialCheckIds.join(', ')}, resolved: ${checkIds.join(', ')})`);
86477
- const prInfo = await analyzer.fetchPRDiff(owner, repo, prNumber, undefined, 'issue_comment');
86504
+ // Different handling for PRs vs Issues
86505
+ let prInfo;
86506
+ if (isPullRequest) {
86507
+ // It's a PR comment - fetch the PR diff
86508
+ prInfo = await analyzer.fetchPRDiff(owner, repo, prNumber, undefined, 'issue_comment');
86509
+ }
86510
+ else {
86511
+ // It's an issue comment - create a minimal PRInfo structure for issue assistant
86512
+ prInfo = {
86513
+ number: issue.number,
86514
+ title: issue.title || '',
86515
+ body: issue.body || '',
86516
+ author: issue.user?.login || 'unknown',
86517
+ base: 'main',
86518
+ head: 'issue',
86519
+ files: [],
86520
+ totalAdditions: 0,
86521
+ totalDeletions: 0,
86522
+ fullDiff: '',
86523
+ eventType: 'issue_comment'
86524
+ };
86525
+ }
86478
86526
  // Extract common arguments
86479
86527
  const focus = command.args?.find(arg => arg.startsWith('--focus='))?.split('=')[1];
86480
86528
  const format = command.args?.find(arg => arg.startsWith('--format='))?.split('=')[1];
@@ -86486,11 +86534,34 @@ async function handleIssueComment(octokit, owner, repo, context, inputs) {
86486
86534
  }
86487
86535
  }
86488
86536
  }
86537
+ // Only run checks that are appropriate for the context
86538
+ const filteredCheckIds = checkIds.filter(checkId => {
86539
+ if (!config?.checks?.[checkId])
86540
+ return false;
86541
+ const checkConfig = config.checks[checkId];
86542
+ const checkEvents = checkConfig.on || ['pr_opened', 'pr_updated'];
86543
+ // For issue comments, only run checks that are configured for issue_comment events
86544
+ if (!isPullRequest) {
86545
+ return checkEvents.includes('issue_comment');
86546
+ }
86547
+ // For PR comments, run checks configured for PR events or issue_comment
86548
+ return checkEvents.includes('pr_updated') || checkEvents.includes('issue_comment');
86549
+ });
86550
+ if (filteredCheckIds.length === 0) {
86551
+ console.log(`No checks configured to run for ${isPullRequest ? 'PR' : 'issue'} comments`);
86552
+ await octokit.rest.issues.createComment({
86553
+ owner,
86554
+ repo,
86555
+ issue_number: prNumber,
86556
+ body: `⚠️ No checks are configured to run for ${isPullRequest ? 'PR' : 'issue'} comments with command /${command.type}\n\n*Powered by [Visor](https://probelabs.com/visor)*`,
86557
+ });
86558
+ return;
86559
+ }
86489
86560
  const groupedResults = await reviewer.reviewPR(owner, repo, prNumber, prInfo, {
86490
86561
  focus,
86491
86562
  format,
86492
86563
  config: config,
86493
- checks: checkIds,
86564
+ checks: filteredCheckIds,
86494
86565
  parallelExecution: false,
86495
86566
  });
86496
86567
  // Check if commenting is enabled before posting
@@ -86502,7 +86573,7 @@ async function handleIssueComment(octokit, owner, repo, context, inputs) {
86502
86573
  });
86503
86574
  }
86504
86575
  else {
86505
- console.log('📝 Skipping PR comment (comment-on-pr is disabled)');
86576
+ console.log('📝 Skipping comment (comment-on-pr is disabled)');
86506
86577
  }
86507
86578
  // Calculate total check results from grouped results
86508
86579
  const totalChecks = Object.values(groupedResults).flat().length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@probelabs/visor",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "main": "dist/index.js",
5
5
  "bin": {
6
6
  "visor": "./dist/index.js"