Skip to content

Conversation

@yifancong
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings December 17, 2025 13:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for collapsible sections in bundle analysis reports and implements a fallback mechanism to find baseline artifacts from parent commits when the latest commit lacks them. The changes improve the user experience by automatically expanding reports with significant changes while keeping minor changes collapsed, and by providing clearer feedback when baseline comparisons use fallback commits.

Key Changes

  • Exports formatBytes and calculateDiff utility functions for reuse across modules
  • Implements fallback logic to search up to 5 parent commits when the latest commit doesn't have baseline artifacts
  • Adds collapsible Quick Summary and Detailed Reports sections in PR comments, with automatic expansion based on change significance

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/report.ts Exports utility functions (formatBytes, calculateDiff) and changes 'N/A' to '0' for missing baseline comparisons; removes emoji for changes < 1%
src/github.ts Adds hasArtifactsForCommit and getParentCommit methods; modifies getTargetBranchLatestCommit to return object with fallback information and traverse up to 5 parent commits
src/index.ts Adds fallback tracking fields to ProjectReport; implements collapsible sections with conditional expansion based on change significance (>= 1%); adds Quick Summary table for monorepo overview
src/tests/github.test.ts Updates test to expect object return type from getTargetBranchLatestCommit; adds test case for fallback commit behavior when latest commit has no artifacts
dist/index.js Compiled output reflecting source changes, including new methods and collapsible section logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 424 to 460
// Generate summary table for quick overview
if (reportsWithCurrent.length > 0) {
// Check if any project has significant changes (> 1% or no baseline)
let hasChanges = false;
for (const report of reportsWithCurrent) {
if (!report.current) continue;
if (!report.baseline) {
hasChanges = true; // No baseline means we can't compare, show it
break;
}
const currentSize = report.current.totalSize;
const baselineSize = report.baseline.totalSize;
if (baselineSize === 0 || isNaN(baselineSize)) continue;
const diff = currentSize - baselineSize;
const percent = Math.abs((diff / baselineSize) * 100);
if (percent >= 1) {
hasChanges = true;
break;
}
}

commentBody += generateProjectMarkdown(report.projectName, report.filePath, report.current, report.baseline || undefined, report.baselineCommitHash, report.baselinePRs);
// Use 'open' attribute if there are changes, otherwise keep it collapsed
const detailsTag = hasChanges ? '<details open>\n' : '<details>\n';
commentBody += `${detailsTag}<summary><b>📊 Quick Summary</b></summary>\n\n`;
commentBody += '| Project | Total Size | Change |\n';
commentBody += '|---------|------------|--------|\n';

for (const report of reportsWithCurrent) {
if (!report.current) continue;
const currentSize = report.current.totalSize;
const baselineSize = report.baseline?.totalSize || 0;
const diff = report.baseline ? calculateDiff(currentSize, baselineSize) : { value: '-', emoji: '' };
const sizeStr = formatBytes(currentSize);
commentBody += `| ${report.projectName} | ${sizeStr} | ${diff.emoji} ${diff.value} |\n`;
}

commentBody += '\n</details>\n\n';
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for determining when to show the Quick Summary as open versus collapsed is duplicated. The hasChanges variable is calculated here (lines 427-443) to decide whether to use 'details open' or 'details', but the exact same logic is duplicated in the hasSignificantChanges helper function (lines 464-473). This code duplication makes the code harder to maintain and could lead to inconsistencies if one is updated without the other. Consider extracting this logic to use the hasSignificantChanges function instead.

Copilot uses AI. Check for mistakes.
Comment on lines 158 to 165
export function calculateDiff(current: number, baseline: number): { value: string; emoji: string } {
if (!baseline || baseline === 0 || isNaN(baseline)) {
return { value: 'N/A', emoji: '❓' };
return { value: '0', emoji: '❓' };
}

if (isNaN(current)) {
return { value: 'N/A', emoji: '❓' };
return { value: '0', emoji: '❓' };
}
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the baseline is 0 or NaN, the function returns '0' with a question mark emoji. However, this is semantically incorrect: a value of '0' suggests no change, but the question mark emoji suggests uncertainty or missing data. When baseline data is truly invalid or missing, returning 'N/A' (as before) would be more accurate. The '0' value could be misleading to users who might interpret it as "no change" rather than "unable to calculate".

Copilot uses AI. Check for mistakes.
Comment on lines +464 to +472
const hasSignificantChanges = (report: ProjectReport): boolean => {
if (!report.current) return false;
if (!report.baseline) return true; // No baseline means we can't compare, show it
const currentSize = report.current.totalSize;
const baselineSize = report.baseline.totalSize;
if (baselineSize === 0 || isNaN(baselineSize)) return false;
const diff = currentSize - baselineSize;
const percent = Math.abs((diff / baselineSize) * 100);
return percent >= 1;
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hasSignificantChanges function returns false when baselineSize is 0 or NaN (line 469), but this means that if a project goes from 0 bytes to having actual content, it won't be shown as a significant change. This seems counterintuitive - going from nothing to something should likely be considered a significant change and be displayed to users.

Copilot uses AI. Check for mistakes.
Comment on lines 119 to 121
if (commitResponse.data.parents && commitResponse.data.parents.length > 0) {
return commitResponse.data.parents[0].sha.substring(0, 10);
}
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getParentCommit method always returns the first parent (index 0) of a commit. For merge commits with multiple parents, this may not always be the desired parent to check for artifacts. In a typical Git workflow, merge commits have two parents - the first is usually the target branch, and the second is the merged branch. Depending on the branching strategy, you might want to consider checking both parents or documenting why only the first parent is used.

Copilot uses AI. Check for mistakes.
@yifancong yifancong force-pushed the feat/support-collapsed branch from 4310ddc to 45dda4e Compare December 17, 2025 13:24
@yifancong yifancong changed the title Feat/support collapsed Optimize: collapse the useless info Dec 17, 2025
@github-actions
Copy link

github-actions bot commented Dec 17, 2025

Rsdoctor Bundle Diff Analysis

Found 2 project(s) in monorepo.

📊 Quick Summary
Project Total Size Change
rsbuild-demo 190.4 KB 0
rsbuild-demo2 190.7 KB 0

Generated by Rsdoctor GitHub Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants