fix: use merge-base for accurate change detection in pj-rehearse
When a PR is created from an outdated base branch commit, git diff-tree comparisons can be incorrect because they compare against the old base SHA instead of finding the actual merge point.
This fix uses git merge-base to find the common ancestor between the base SHA and HEAD, ensuring accurate change detection even when:
- The base branch has moved forward significantly
- The PR was created from an outdated commit
- Merge commits exist in the PR history
This resolves the issue where pj-rehearse fails to detect changes until the PR is rebased onto the latest base branch.
/cc @danilo-gemoli @openshift/test-platform
/hold
Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.
For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.
This repository is configured in: automatic mode
Walkthrough
This change modifies the getRevChanges function in pkg/config/release.go to calculate and use a merge-base as the reference point for diff computation. When merge-base succeeds, its trimmed result replaces the original base in the diff comparison; on failure, the function falls back to the original base. This refines change detection when the base branch has advanced.
Changes
| Cohort / File(s) | Summary |
|---|---|
Merge-base calculation for diff refinement pkg/config/release.go |
Adds merge-base calculation to determine moving base for diffs in getRevChanges. Implements error-tolerant handling with fallback to original base; trims whitespace from merge-base result before using it as the left-hand side of diff-tree invocation. Preserves existing filtering, diff invocation, and post-processing logic. |
Estimated code review effort
๐ฏ 3 (Moderate) | โฑ๏ธ ~20 minutes
- Verify merge-base error handling and fallback semantics are correctly implemented
- Confirm whitespace trimming logic handles edge cases properly
- Assess impact on change detection accuracy when base branch has advanced
- Ensure the diff-tree command structure is valid with the merge-base substitution
โจ Finishing touches
- [ ] ๐ Generate docstrings
๐งช Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
๐ Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
๐ฅ Commits
Reviewing files that changed from the base of the PR and between f0f4b3b2a0b32373c13185f7622225246f8b04b5 and 017e948079113a23f5612546c7f27e49b072b065.
๐ Files selected for processing (1)
-
pkg/config/release.go(1 hunks)
๐งฐ Additional context used
๐ Path-based instructions (1)
**
โ๏ธ CodeRabbit configuration file
-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.
Files:
-
pkg/config/release.go
๐ Additional comments (1)
pkg/config/release.go (1)
277-288: LGTM! Robust solution for accurate change detection.The merge-base approach correctly handles the case where the base branch has advanced since the PR was created. The fallback logic (lines 281-284) ensures safe operation when merge-base fails (e.g., shallow clones, no common ancestor), preserving the original behavior. This makes the implementation more robust than the previous version.
Comment @coderabbitai help to get the list of available commands and usage tips.
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: deepsm007
The full list of commands accepted by this bot can be found here.
The pull request process is described here
- ~~OWNERS~~ [deepsm007]
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
/test images
@deepsm007: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:
| Test name | Commit | Details | Required | Rerun command |
|---|---|---|---|---|
| ci/prow/breaking-changes | 017e948079113a23f5612546c7f27e49b072b065 | link | false | /test breaking-changes |
| ci/prow/images | 017e948079113a23f5612546c7f27e49b072b065 | link | true | /test images |
Full PR test history. Your PR dashboard.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.
I'm not sure the code we are changing here is ever exercised by pj-rehearse. If my understanding is correct, this is the relevant part. What do you think?