Improve rule change detection for merge commits#3988
Closed
eric-sim-sublime wants to merge 2 commits intomainfrom
Closed
Improve rule change detection for merge commits#3988eric-sim-sublime wants to merge 2 commits intomainfrom
eric-sim-sublime wants to merge 2 commits intomainfrom
Conversation
The previous logic used git merge-base to find a comparison point, but this breaks when the PR contains merge commits from main. When comparing files at HEAD (a merge commit) vs the calculated merge-base, it would incorrectly detect all of main's recent changes as PR changes. This fix uses git's three-dot diff syntax (origin/main...HEAD) which automatically finds the correct merge-base and compares only the changes introduced by the PR branch, regardless of merge commits. Changes: - Use 'git diff origin/main...HEAD --find-renames' to find changed files - For each file, search for the old file with same rule ID (handles renames) - Compare source fields using 'git show' directly - Remove unnecessary sr-main checkout step (no longer needed) - Handles all merge commit scenarios (HEAD, middle of history, multiple merges) Benefits: - Correctly detects only PR changes even with merge commits - Handles file renames by searching for matching rule IDs - More efficient (no need to checkout entire base branch) - More robust (uses git's built-in three-dot diff) Fixes issue where PRs with merge commits incorrectly triggered tests for hundreds of unchanged rules (e.g., PR #3982 detected 774 rules when 0 changed). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Test Rules Sync - Action RequiredThis PR was not automatically synced to test-rules because the author is not a member of the To enable syncing, an organization member can comment Once triggered, the rules will be synced on the next scheduled run (every 10 minutes). |
Validates: - Modified rule source detection - File renames (via rule ID matching) - Metadata-only changes (correctly ignored) - Merge commits (only PR changes detected) - New files detection Run with: bash .github/scripts/test_rule_detection.sh
| @@ -0,0 +1,264 @@ | |||
| #!/bin/bash | |||
Member
There was a problem hiding this comment.
Is this meant to be committed?
| done | ||
| else | ||
| # Use three-dot diff to compare only PR changes, handling merge commits correctly | ||
| git fetch origin "${GITHUB_BASE_REF}:refs/remotes/origin/${GITHUB_BASE_REF}" 2>/dev/null || true |
Member
There was a problem hiding this comment.
GITHUB_BASE_REF:
The name of the base ref or target branch of the pull request in a workflow run. This is only set when the event that triggers a workflow run is either pull_request or pull_request_target. For example, main.
This workflow runs for:
push:
branches: [ "main", "test-rules" ]
pull_request_target:
branches:
- "main"
- 'ci-testing**'
workflow_dispatch: {}
issue_comment:
types: [ created ]
merge_group: {}
Note that we don't actually run MQL Mimic for the merge_group. issue_comment is probably the most relevant retrigger for MQL Mimic since that's what test exceptions go through.
get_base_ref is good context and maybe all you need?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When PRs contain merge commits, the workflow can incorrectly detect many unchanged rules as having changes.
Uses three-dot diff (
git diff origin/main...HEAD) to better isolate PR changes from main's changes.Includes test script to validate the detection logic.