From ad501ac16dbb57ad74fd5b8f4865a5f106a53ccb Mon Sep 17 00:00:00 2001 From: Csaba Apagyi Date: Mon, 12 Jan 2026 16:32:31 +0100 Subject: [PATCH] fix: use merge-base for accurate PR diff in code review example The previous code review example used base.sha...head.sha which incorrectly shows commits added to main after the PR branch was created as 'removed' when the branch is not up to date with main. This change: - Adds fetch-depth: 0 to get full git history - Computes merge-base to find the common ancestor between PR and base branch - Uses git diff with merge-base to show only changes introduced by the PR This ensures the code review focuses on actual PR changes regardless of whether the branch is up to date with main. --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bccb3d9..2281d5b 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ jobs: with: # Explicitly check out the PR's merge commit. ref: refs/pull/${{ github.event.pull_request.number }}/merge + # Fetch full history so git merge-base can find the common ancestor + fetch-depth: 0 - name: Pre-fetch base and head refs for the PR run: | @@ -42,6 +44,15 @@ jobs: ${{ github.event.pull_request.base.ref }} \ +refs/pull/${{ github.event.pull_request.number }}/head + - name: Compute merge-base + id: merge_base + run: | + # Find the common ancestor between the PR branch and base branch. + # This ensures we only review changes introduced by the PR, not + # changes added to main after the PR branch was created. + MERGE_BASE=$(git merge-base origin/${{ github.event.pull_request.base.ref }} HEAD) + echo "sha=$MERGE_BASE" >> "$GITHUB_OUTPUT" + # If you want Codex to build and run code, install any dependencies that # need to be downloaded before the "Run Codex" step because Codex's # default sandbox disables network access. @@ -54,8 +65,8 @@ jobs: prompt: | This is PR #${{ github.event.pull_request.number }} for ${{ github.repository }}. - Review ONLY the changes introduced by the PR, so consider: - git log --oneline ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} + Review ONLY the changes introduced by the PR. Use this to see the diff: + git diff ${{ steps.merge_base.outputs.sha }}..HEAD Suggest any improvements, potential bugs, or issues. Be concise and specific in your feedback.