Skip to content

Commit c15c8b6

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

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,40 @@ async def test_maintenance_branch_pr_status_not_posted_on_main(action):
358358
assert len(gh.post_) == 0
359359

360360

361+
@pytest.mark.parametrize('action', ['opened', 'reopened', 'edited', 'synchronize'])
362+
async def test_not_maintenance_branch_pr_status_not_posted_alt_base(action):
363+
"""
364+
When a PR is proposed against a non-maintenance branch, such
365+
as another PR, it pass without status (same as with main). See
366+
#381 for a detailed justification.
367+
"""
368+
title = 'Fix some typo'
369+
data = {
370+
'action': action,
371+
'number': 2248,
372+
'pull_request': {
373+
'title': title,
374+
'body': '',
375+
'issue_url': 'https://api.github.com/issue/2248',
376+
'base': {
377+
'ref': 'gh-1234/dependent-change',
378+
},
379+
'statuses_url': 'https://api.github.com/repos/python/cpython/statuses/somehash',
380+
},
381+
'repository': {'issues_url': 'https://api.github.com/issue{/number}'},
382+
'changes': {'title': title},
383+
}
384+
event = sansio.Event(data, event='pull_request', delivery_id='1')
385+
getitem = {
386+
'https://api.github.com/issue/1234':
387+
{'labels': [{'name': 'CLA signed'}]},
388+
'https://api.github.com/issue/2248': {},
389+
}
390+
gh = FakeGH(getitem=getitem)
391+
await backport.router.dispatch(event, gh)
392+
assert not gh.post_
393+
394+
361395
@pytest.mark.parametrize('ref', ['3.9', '4.0', '3.10'])
362396
async def test_maintenance_branch_created(ref):
363397
event_data = {

0 commit comments

Comments
 (0)