Skip to content

fix: use last PR number in commit subject for revert commits#277

Open
skyc1e wants to merge 1 commit intoMetaMask:mainfrom
skyc1e:fix/revert-commit-pr-number
Open

fix: use last PR number in commit subject for revert commits#277
skyc1e wants to merge 1 commit intoMetaMask:mainfrom
skyc1e:fix/revert-commit-pr-number

Conversation

@skyc1e
Copy link
Copy Markdown

@skyc1e skyc1e commented Mar 28, 2026

Summary

Fixes #213

When a revert commit includes the original PR number in its quoted title, the regex matched the first (#NNNN) instead of the actual revert PR number:

Revert "Remove useRequestQueue toggle (#4941)" (#5065)
^^^^^ ^^^^^
matched ignored (actual PR)

This caused the revert commit to be filtered out as a duplicate because #4941 was already in the changelog from a previous release.

Fix

Changed subject.match(/\(#(\d+)\)/u) (returns first match) to subject.matchAll() + take the last match. GitHub always appends the actual PR number at the end of the subject on squash merge, so the last (#NNNN) is always the correct one.

Test

Added a dedicated test case that simulates a revert commit with the original PR already logged — confirms the revert is now correctly included with its own PR number.

Test plan

  • All 14 get-new-changes tests pass (including new revert test)
  • Existing tests unaffected — normal commits still extract PR number correctly

Note

Low Risk
Low risk: a small, targeted change to PR-number extraction from git commit subjects plus a focused unit test; main risk is altered parsing for unusual subjects containing multiple (#NNNN) patterns.

Overview
Fixes PR-number extraction in getNewChangeEntries to use the last (#NNNN) occurrence in a commit subject (via matchAll), preventing revert commits that mention the original PR from being mis-identified and incorrectly deduplicated.

Adds a unit test covering a revert subject like Revert "... (#4941)" (#5065) to ensure the revert PR (#5065) is kept even when the original PR is already logged.

Written by Cursor Bugbot for commit a8ef164. This will update automatically on new commits. Configure here.

When a revert commit includes the original PR number in its quoted
title (e.g. `Revert "some change (#4941)" (#5065)`), the PR number
regex matched the first occurrence (#4941) instead of the actual
revert PR (#5065). This caused the revert to be incorrectly filtered
out as a duplicate if the original PR was already in the changelog.

Now uses `matchAll` to find all PR number patterns and takes the last
one, which is always the actual PR number appended by GitHub on
squash merge.

Fixes MetaMask#213
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.

Commits that revert other commits don't get copied into the Unreleased section

1 participant