ci-tools icon indicating copy to clipboard operation
ci-tools copied to clipboard

fix: use merge-base for accurate change detection in pj-rehearse

Open deepsm007 opened this issue 2 months ago โ€ข 6 comments

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

deepsm007 avatar Dec 15 '25 14:12 deepsm007

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

openshift-ci-robot avatar Dec 15 '25 14:12 openshift-ci-robot

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.

coderabbitai[bot] avatar Dec 15 '25 14:12 coderabbitai[bot]

[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

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

openshift-ci[bot] avatar Dec 15 '25 14:12 openshift-ci[bot]

/test images

deepsm007 avatar Dec 15 '25 15:12 deepsm007

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

openshift-ci[bot] avatar Dec 15 '25 16:12 openshift-ci[bot]

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?

danilo-gemoli avatar Dec 17 '25 11:12 danilo-gemoli