From a39f0435dc59f81efbc9b5de5bfeb274234e24c3 Mon Sep 17 00:00:00 2001 From: Bastian Gutschke Date: Fri, 13 Jun 2025 06:49:17 +0200 Subject: [PATCH] feat: use dynamic fetch depth based on PR commit count - Replace fixed depth of 20 with dynamic calculation - Use Math.max(commitCount, 20) to ensure minimum context --- src/github/operations/branch.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/github/operations/branch.ts b/src/github/operations/branch.ts index 3379648..f0b1a95 100644 --- a/src/github/operations/branch.ts +++ b/src/github/operations/branch.ts @@ -45,9 +45,16 @@ export async function setupBranch( const branchName = prData.headRefName; - // Execute git commands to checkout PR branch (shallow fetch for performance) - // Fetch the branch with a depth of 20 to avoid fetching too much history, while still allowing for some context - await $`git fetch origin --depth=20 ${branchName}`; + // Determine optimal fetch depth based on PR commit count, with a minimum of 20 + const commitCount = prData.commits.totalCount; + const fetchDepth = Math.max(commitCount, 20); + + console.log( + `PR #${entityNumber}: ${commitCount} commits, using fetch depth ${fetchDepth}`, + ); + + // Execute git commands to checkout PR branch (dynamic depth based on PR size) + await $`git fetch origin --depth=${fetchDepth} ${branchName}`; await $`git checkout ${branchName}`; console.log(`Successfully checked out PR branch for PR #${entityNumber}`);