Skip to content

Commit b088ba2

Browse files
committed
gh-381: Add test and fix when base branch isn't a maintenance branch. Fixes #381.
1 parent ad03d53 commit b088ba2

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

bedevere/backport.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ async def manage_labels(event, gh, *args, **kwargs):
6767
await _copy_over_labels(gh, original_issue, backport_issue)
6868

6969

70+
def targets_maintenance_branch(ref):
71+
"""
72+
Return True if the ref refers to a maintenance branch.
73+
"""
74+
maintenance_branch_pattern = r'\d+\.\d+'
75+
return bool(re.fullmatch(maintenance_branch_pattern, ref))
76+
77+
7078
@router.register("pull_request", action="opened")
7179
@router.register("pull_request", action="reopened")
7280
@router.register("pull_request", action="edited")
@@ -84,7 +92,7 @@ async def validate_maintenance_branch_pr(event, gh, *args, **kwargs):
8492
pull_request = event.data["pull_request"]
8593
base_branch = pull_request["base"]["ref"]
8694

87-
if base_branch == "main":
95+
if not targets_maintenance_branch(base_branch):
8896
return
8997

9098
title = util.normalize_title(pull_request["title"],

tests/test_backport.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,41 @@ async def test_not_valid_maintenance_branch_pr_title(action):
328328
assert post[1]['target_url'] == 'https://devguide.python.org/committing/#backport-pr-title'
329329

330330

331+
@pytest.mark.parametrize('action', ['opened', 'reopened', 'edited', 'synchronize'])
332+
async def test_not_maintenance_branch_pr_title(action):
333+
title = 'Fix some typo'
334+
data = {
335+
'action': action,
336+
'number': 2248,
337+
'pull_request': {
338+
'title': title,
339+
'body': '',
340+
'issue_url': 'https://api.github.com/issue/2248',
341+
'base': {
342+
'ref': 'gh-1234/dependent-change',
343+
},
344+
'statuses_url': 'https://api.github.com/repos/python/cpython/statuses/somehash',
345+
},
346+
'repository': {'issues_url': 'https://api.github.com/issue{/number}'},
347+
'changes': {'title': title},
348+
}
349+
event = sansio.Event(data, event='pull_request',
350+
delivery_id='1')
351+
getitem = {
352+
'https://api.github.com/issue/1234':
353+
{'labels': [{'name': 'CLA signed'}]},
354+
'https://api.github.com/issue/2248': {},
355+
}
356+
gh = FakeGH(getitem=getitem)
357+
await backport.router.dispatch(event, gh)
358+
post = gh.post_[0]
359+
assert post[0] == 'https://api.github.com/repos/python/cpython/statuses/somehash'
360+
assert not any(
361+
post_item['context'] == 'bedevere/maintenance-branch-pr'
362+
for post_item in post
363+
)
364+
365+
331366
@pytest.mark.parametrize('action', ['opened', 'reopened', 'edited', 'synchronize'])
332367
async def test_maintenance_branch_pr_status_not_posted_on_main(action):
333368
title = 'Fix some typo'

0 commit comments

Comments
 (0)