Files
PX4-Autopilot/Tools/ci/test_check_pr_title.py
Ramon Roche 40fee1673f ci(commit_checks): accept a backport tag in release branch PR titles
Backport PRs are titled "[BACKPORT 1.18] fix(mavlink): ...". The PR title
check anchors on the conventional commit type, so it fails all of them
even though the header after the tag is valid. Replaying the check over
the 210 PRs opened against release/1.16, release/1.17 and release/1.18,
62 fail only because of the tag.

Skip a leading backport tag before validating the header. The header
after the tag still has to be a conventional commit. The tag is accepted
only on PRs that target a release/* branch, so a backport opened against
main by mistake fails with a comment that says so. The title suggested
in the failure comment keeps the tag.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Ramon Roche <mrpollo@gmail.com>
2026-11-16 10:33:46 -08:00

52 lines
2.0 KiB
Python

"""Exercise the PR title check on backport titles."""
import contextlib
import io
import unittest
from check_pr_title import check_title, format_markdown, suggest_title
def passes(title, base_ref=None):
with contextlib.redirect_stderr(io.StringIO()):
return check_title(title, base_ref)
class BackportTitleTest(unittest.TestCase):
def test_backport_tag_in_front_of_a_valid_header_passes(self):
for title in (
'fix(mavlink): let a UDP client reconnect from a new port',
'[BACKPORT 1.18] fix(mavlink): let a UDP client reconnect from a new port',
'[BACKPORT v1.18] feat(boards/ark_fpv)!: add the LSM6DSV32X revision',
'[Backport 1.17] docs(docs): dynamically fetched navbar',
'[BACKPORT] fix(boards/matek-h743): correct board ID',
):
with self.subTest(title=title):
self.assertTrue(passes(title))
def test_backport_tag_does_not_exempt_the_header(self):
for title in (
'[BACKPORT 1.18] Fix the UDP client reconnect',
'[BACKPORT 1.18] mavlink: let a UDP client reconnect',
'[BACKPORT 1.18]',
'[Docs] fix(mavlink): let a UDP client reconnect from a new port',
):
with self.subTest(title=title):
self.assertFalse(passes(title))
def test_backport_tag_needs_a_release_base_branch(self):
title = '[BACKPORT 1.18] fix(mavlink): let a UDP client reconnect from a new port'
self.assertTrue(passes(title, 'release/1.18'))
self.assertFalse(passes(title, 'main'))
self.assertIn('targets `main`', format_markdown(title, 'main'))
self.assertTrue(passes('fix(mavlink): let a UDP client reconnect from a new port', 'main'))
def test_suggestion_keeps_the_backport_tag(self):
self.assertEqual(
suggest_title('[BACKPORT 1.18] mavlink: let a UDP client reconnect'),
'[BACKPORT 1.18] feat(mavlink): let a UDP client reconnect')
if __name__ == '__main__':
unittest.main()