Skip to content

feat: detect clean rebase on PR synchronize and preserve review labels #1059

@myakove

Description

@myakove

Summary

Detect clean rebases on PR synchronize events and preserve review labels instead of stripping them unnecessarily.

Problem / Motivation

When a PR is synchronized (new commits pushed), the server currently strips all review-related labels (approved-by-*, lgtm-by-*, changes-requested-by-*, commented-by-*). This is correct for actual code changes, but unnecessary for clean rebases where no code was actually modified — just commits replayed on a newer base.

This forces reviewers to re-approve PRs that had no actual changes, wasting time.

Solution

Detect clean rebases by comparing the diff against the base branch before and after the force push. If the diffs are identical, it's a clean rebase.

Detection method: Compare SHA-256 hashes of git diff <merge-base>..<head> before and after the synchronize event. Same hash = clean rebase.

On clean rebase detected:

  1. Preserve review labels: approved-by-*, lgtm-by-*, verified-*
  2. Post a PR comment explaining that a clean rebase was detected and which labels were preserved
  3. Continue all other synchronize processing normally (CI, size check, etc.)

Requirements

  1. Add a clean rebase detection method that compares SHA-256 hashes of git diff <merge-base>..<head> before and after the synchronize event
  2. Modify remove_labels_when_pull_request_sync() to skip label removal when a clean rebase is detected
  3. Post a PR comment listing preserved labels when a clean rebase is detected
  4. Ensure all other synchronize processing (CI, size check, etc.) continues normally regardless of rebase detection

Deliverables

  • Add clean rebase detection method using git diff + SHA-256 hash comparison
  • Modify remove_labels_when_pull_request_sync() to skip label removal on clean rebase
  • Post PR comment listing preserved labels when clean rebase is detected
  • Add tests for clean rebase detection
  • Add tests for label preservation on clean rebase
  • Update README.md (if applicable)
  • Update CLAUDE.md (if codebase structure changes)

Notes

  • The before and after SHAs are available in the webhook synchronize event payload
  • The repository clone is already available during synchronize processing, so git diff can be run locally
  • This optimization is particularly valuable for large PRs with many approvals

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions