Skip to content

Commit ea0f0df

Browse files
authored
Close PRs that try to merge a user's maintenance branch into master (GH-70)
Close PR that tries to merge the user's maintenance branch into CPython's master.
1 parent 81f8490 commit ea0f0df

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

bedevere/close_pr.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import gidgethub.routing
55

66

7-
PYTHON_MAINT_BRANCH_RE = re.compile(r'^python:\d+.\d+$')
7+
PYTHON_MAINT_BRANCH_RE = re.compile(r'^\w+:\d+.\d+$')
88

99
router = gidgethub.routing.Router()
1010

@@ -15,7 +15,7 @@ async def close_invalid_pr(event, gh, *args, **kwargs):
1515
1616
PR is considered invalid if:
1717
* base_label is 'python:master'
18-
* head_label is 'python:<maint_branch>'
18+
* head_label is '<username>:<maint_branch>'
1919
"""
2020
head_label = event.data["pull_request"]["head"]["label"]
2121
base_label = event.data["pull_request"]["base"]["label"]
@@ -25,4 +25,3 @@ async def close_invalid_pr(event, gh, *args, **kwargs):
2525
data = {'state': 'closed',
2626
'maintainer_can_modify': True}
2727
await gh.patch(event.data["pull_request"]["url"], data=data)
28-

tests/test_close_pr.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,32 @@ async def test_valid_pr_not_closed():
103103
await close_pr.router.dispatch(event, gh)
104104
patch_data = gh.patch_data
105105
assert patch_data is None
106+
107+
108+
@pytest.mark.asyncio
109+
async def test_close_invalid_pr_on_open_not_python_as_head():
110+
data = {
111+
"action": "opened",
112+
"pull_request": {
113+
"statuses_url": "https://api.github.com/blah/blah/git-sha",
114+
"title": "No issue in title",
115+
"issue_url": "issue URL",
116+
"url": "https://api.github.com/org/repo/pulls/123",
117+
"head": {
118+
"label": "username123:3.6"
119+
},
120+
"base": {
121+
"label": "python:master"
122+
}
123+
},
124+
}
125+
pr_data = {
126+
"labels": [
127+
{"name": "non-trivial"},
128+
]
129+
}
130+
event = sansio.Event(data, event="pull_request", delivery_id="12345")
131+
gh = FakeGH(getitem=pr_data)
132+
await close_pr.router.dispatch(event, gh)
133+
patch_data = gh.patch_data
134+
assert patch_data["state"] == "closed"

0 commit comments

Comments
 (0)