Skip to content

Commit 8b9f9cf

Browse files
committed
fix: leave out every trailing " (#N)", not only the last
A title that already ends in a number, such as a backport's " (#12)", gets a second one from the squash merge, and only the last was left out, so a title that passed on the pull request could fail once merged.
1 parent 4e8f4a6 commit 8b9f9cf

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎commit_check/engine.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,10 @@ def _is_third_person(cls, word: str) -> bool:
658658
# GitHub ends the subject of a squash merge with the pull request's number,
659659
# " (#123)". Like a merge subject's length, those characters are GitHub's
660660
# doing, not the author's: a title that fit the limit on the pull request
661-
# must not fail once it lands on the branch.
662-
_SQUASH_PR_NUMBER = re.compile(r" \(#[0-9]+\)$")
661+
# must not fail once it lands on the branch. A title that already ends in
662+
# a number, such as a backport's " (#12)", gets a second one, so the whole
663+
# run is left out. [0-9], not \d, which also matches other scripts' digits.
664+
_SQUASH_PR_NUMBER = re.compile(r"(?: \(#[0-9]+\))+$")
663665

664666

665667
def _characters(count: int) -> str:

‎tests/engine_test.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,22 @@ def test_squash_pr_number_is_not_counted(self, subject):
14371437
ValidationResult.PASS
14381438
)
14391439

1440+
def test_a_title_ending_in_a_number_measures_the_same_after_the_merge(self):
1441+
"""A backport titled "... (#12)" gets " (#34)" too; both are left out,
1442+
so the title that passed on the pull request still passes."""
1443+
title = "feat: " + "x" * 74 + " (#12)"
1444+
rule = ValidationRule(check="subject_max_length", value=80)
1445+
for subject in (title, title + " (#34)"):
1446+
validator = SubjectLengthValidator(rule)
1447+
assert validator.validate(ValidationContext(stdin_text=subject)) == (
1448+
ValidationResult.PASS
1449+
)
1450+
failure = self._failure("subject_max_length", 70, title + " (#34)")
1451+
assert failure["error"] == (
1452+
'Subject is 80 characters, not counting "(#12) (#34)"; '
1453+
"it must be at most 70 characters"
1454+
)
1455+
14401456
def test_squash_pr_number_is_not_counted_toward_the_minimum(self):
14411457
rule = ValidationRule(check="subject_min_length", value=5)
14421458
validator = SubjectLengthValidator(rule)

0 commit comments

Comments
 (0)