Skip to content

Close PRs that try to merge a user's maintenance branch into master #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions bedevere/close_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import gidgethub.routing


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

router = gidgethub.routing.Router()

Expand All @@ -15,7 +15,7 @@ async def close_invalid_pr(event, gh, *args, **kwargs):

PR is considered invalid if:
* base_label is 'python:master'
* head_label is 'python:<maint_branch>'
* head_label is '<username>:<maint_branch>'
"""
head_label = event.data["pull_request"]["head"]["label"]
base_label = event.data["pull_request"]["base"]["label"]
Expand All @@ -25,4 +25,3 @@ async def close_invalid_pr(event, gh, *args, **kwargs):
data = {'state': 'closed',
'maintainer_can_modify': True}
await gh.patch(event.data["pull_request"]["url"], data=data)

29 changes: 29 additions & 0 deletions tests/test_close_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,32 @@ async def test_valid_pr_not_closed():
await close_pr.router.dispatch(event, gh)
patch_data = gh.patch_data
assert patch_data is None


@pytest.mark.asyncio
async def test_close_invalid_pr_on_open_not_python_as_head():
data = {
"action": "opened",
"pull_request": {
"statuses_url": "https://api.github.com/blah/blah/git-sha",
"title": "No issue in title",
"issue_url": "issue URL",
"url": "https://api.github.com/org/repo/pulls/123",
"head": {
"label": "username123:3.6"
},
"base": {
"label": "python:master"
}
},
}
pr_data = {
"labels": [
{"name": "non-trivial"},
]
}
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH(getitem=pr_data)
await close_pr.router.dispatch(event, gh)
patch_data = gh.patch_data
assert patch_data["state"] == "closed"