Skip to content

fix: use merge-base for accurate PR diff in code review example - #64

Open
thisismydesign wants to merge 3 commits into
openai:mainfrom
thisismydesign:fix/code-review-merge-base
Open

fix: use merge-base for accurate PR diff in code review example#64
thisismydesign wants to merge 3 commits into
openai:mainfrom
thisismydesign:fix/code-review-merge-base

Conversation

@thisismydesign

@thisismydesign thisismydesign commented Jan 12, 2026

Copy link
Copy Markdown

The code review example prompts Codex with git log --oneline base.sha...head.sha. For git log, ... is the symmetric difference, so when the PR branch is behind its base branch the list also includes every commit added to the base since the branch point. Codex then treats those as part of the PR and reports the base's changes as "removed".

This switches the prompt to git diff base.sha...head.sha. For git diff, ... means "diff from the merge-base to head", which is exactly the PR's own changes regardless of whether the branch is up to date with its base. The refs are already fetched by the pre-fetch step, so no extra history or steps are needed.

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.
@github-actions

github-actions Bot commented Jan 12, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@thisismydesign

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jan 12, 2026
Comment thread README.md Outdated
# 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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we accomplish this with gh to avoid fetch-depth: 0?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@bolinfest Managed to solve it without fetch-depth: 0

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