Skip to content

optimize: find the parent commits when no latest commit's baseline#19

Merged
yifancong merged 1 commit intotest/mainfrom
optimize/find-parent-commits
Dec 16, 2025
Merged

optimize: find the parent commits when no latest commit's baseline#19
yifancong merged 1 commit intotest/mainfrom
optimize/find-parent-commits

Conversation

@yifancong
Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings December 16, 2025 08:33
@github-actions
Copy link
Copy Markdown

Rsdoctor Bundle Diff Analysis

Found 2 project(s) in monorepo.

📁 rsbuild-demo

Path: examples/rsbuild-demo/dist/.rsdoctor/rsdoctor-data.json

📌 Baseline Commit: a442dd7bb7 | PR: #18

Metric Current Baseline Change
📊 Total Size 190.4 KB 190.4 KB 0 B (0.0%)
📄 JavaScript 188.5 KB 188.5 KB 0 B (0.0%)
🎨 CSS 345.0 B 345.0 B 0 B (0.0%)
🌐 HTML 374.0 B 374.0 B 0 B (0.0%)
📁 Other Assets 1.2 KB 1.2 KB 0 B (0.0%)

📦 Download Diff Report: rsbuild-demo Bundle Diff

📁 rsbuild-demo2

Path: examples/rsbuild-demo2/dist/.rsdoctor/rsdoctor-data.json

📌 Baseline Commit: a442dd7bb7 | PR: #18

Metric Current Baseline Change
📊 Total Size 190.7 KB 190.7 KB 0 B (0.0%)
📄 JavaScript 188.8 KB 188.8 KB 0 B (0.0%)
🎨 CSS 345.0 B 345.0 B 0 B (0.0%)
🌐 HTML 374.0 B 374.0 B 0 B (0.0%)
📁 Other Assets 1.2 KB 1.2 KB 0 B (0.0%)

📦 Download Diff Report: rsbuild-demo2 Bundle Diff

Generated by Rsdoctor GitHub Action

@yifancong yifancong changed the base branch from main to test/main December 16, 2025 08:34
@yifancong yifancong merged commit 5e14053 into test/main Dec 16, 2025
6 checks passed
@yifancong yifancong deleted the optimize/find-parent-commits branch December 16, 2025 08:35
Copy link
Copy Markdown
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 optimizes the baseline commit selection logic by implementing a parent commit traversal mechanism when the latest commit lacks baseline artifacts. Instead of immediately using a commit without artifacts, the code now traverses up to 5 parent commits to find one with available baseline artifacts.

Key changes:

  • Added helper methods to check for artifacts and retrieve parent commits
  • Refactored commit retrieval to defer early returns and enable artifact validation
  • Implemented parent commit traversal with depth limiting and circular reference protection

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/github.ts Added hasArtifactsForCommit and getParentCommit helper methods; refactored getTargetBranchLatestCommit to check for artifacts and traverse parent commits when needed
dist/index.js Compiled JavaScript output matching the TypeScript source changes

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

}
} catch (error) {
// Continue checking other workflow runs
continue;
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The continue statement is redundant here. Since continue is the default behavior at the end of a for loop iteration, it can be removed without changing functionality.

Suggested change
continue;

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 16, 2025

Choose a reason for hiding this comment

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

The getParentCommit method only retrieves the first parent commit. In merge commits with multiple parents, this could lead to unexpected behavior. Consider documenting this assumption or adding logic to handle merge commits appropriately. The method should clarify whether it's intended to follow the first parent (main branch) or if there's specific merge commit handling needed.

Copilot uses AI. Check for mistakes.

let currentCommit = latestCommitHash;
let checkedCommits: string[] = [currentCommit];
const maxDepth = 5;
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The magic number 5 for maxDepth lacks explanation. Consider adding a comment explaining why 5 commits is an appropriate depth limit, or making this configurable. This helps future maintainers understand the rationale behind this value.

Copilot uses AI. Check for mistakes.
Comment on lines +86 to +99

for (const workflowRun of workflowRuns) {
try {
const runArtifacts = await this.listArtifactsForWorkflowRun(workflowRun.id);
if (runArtifacts.artifacts && runArtifacts.artifacts.length > 0) {
return true;
}
} catch (error) {
// Continue checking other workflow runs
continue;
}
}

return false;
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The hasArtifactsForCommit method could potentially make many API calls sequentially, which may impact performance and could hit rate limits. For a commit with many workflow runs, this could be slow. Consider adding pagination limits, caching results, or implementing parallel checks with Promise.all() for better performance.

Suggested change
for (const workflowRun of workflowRuns) {
try {
const runArtifacts = await this.listArtifactsForWorkflowRun(workflowRun.id);
if (runArtifacts.artifacts && runArtifacts.artifacts.length > 0) {
return true;
}
} catch (error) {
// Continue checking other workflow runs
continue;
}
}
return false;
// Check all workflow runs in parallel for artifacts
const artifactChecks = await Promise.all(
workflowRuns.map(async (workflowRun) => {
try {
const runArtifacts = await this.listArtifactsForWorkflowRun(workflowRun.id);
return runArtifacts.artifacts && runArtifacts.artifacts.length > 0;
} catch (error) {
// Treat errors as no artifacts for this run
return false;
}
})
);
return artifactChecks.some(Boolean);

Copilot uses AI. Check for mistakes.
Comment on lines +256 to 283
for (let depth = 0; depth < maxDepth; depth++) {
const parentCommit = await this.getParentCommit(currentCommit);

console.log(`📥 Running: git rev-parse --short=10 origin/${targetBranch}`);
const commitHash = execSync(`git rev-parse --short=10 origin/${targetBranch}`, { encoding: 'utf8' }).trim();
console.log(`✅ Found commit hash from git: ${commitHash}`);
return commitHash;
} catch (gitError) {
console.warn(`❌ Git fetch failed: ${gitError}`);
if (!parentCommit) {
console.log(`⚠️ Reached the beginning of the branch, no more parent commits`);
break;
}

try {
console.log(`📥 Trying alternative: git ls-remote origin ${targetBranch}`);
const remoteRef = execSync(`git ls-remote origin ${targetBranch}`, { encoding: 'utf8' }).trim();
if (remoteRef) {
const commitHash = remoteRef.split('\t')[0].substring(0, 10);
console.log(`✅ Found commit hash from git ls-remote: ${commitHash}`);
return commitHash;
}
} catch (altError) {
console.warn(`❌ Alternative git command failed: ${altError}`);
if (checkedCommits.includes(parentCommit)) {
console.log(`⚠️ Detected circular reference, stopping search`);
break;
}

checkedCommits.push(parentCommit);
console.log(`🔍 Checking parent commit ${parentCommit}...`);

const parentHasArtifacts = await this.hasArtifactsForCommit(parentCommit);

if (parentHasArtifacts) {
console.log(`✅ Found commit ${parentCommit} with baseline artifacts`);
console.log(`\n⚠️ Note: The latest commit (${latestCommitHash}) does not have baseline artifacts.`);
console.log(` Using commit ${parentCommit} for baseline comparison instead.`);
console.log(` If this seems incorrect, please wait a few minutes and try rerunning the workflow.`);
return parentCommit;
}

currentCommit = parentCommit;
}
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The parent commit traversal loop could make up to 5 sequential API calls (getParentCommit) followed by potentially expensive hasArtifactsForCommit checks. This sequential approach could be slow and may hit API rate limits. Consider adding delays between checks, implementing exponential backoff, or optimizing the artifact checking logic to reduce the number of API calls.

Copilot uses AI. Check for mistakes.
@yifancong yifancong review requested due to automatic review settings March 23, 2026 21:27
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