Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"action": "closed",
"pull_request": {
"number": 5326,
"merged": False,
"statuses_url": "https://api.github.com/blah/blah/git-sha",
"title": "No issue in title",
"issue_url": "issue URL",
"merge_commit_sha": None,
"comments_url": "https://api.github.com/repos/python/cpython/pulls/5326/comments",
},
"repository": {
"commits_url": "https://api.github.com/repos/python/cpython/commits{/sha}"
}
}
event = sansio.Event(data, event="pull_request", delivery_id="12345")
gh = FakeGH()
await follow_up.router.dispatch(event, gh)
post_data = gh.post_data
assert post_data is None
async def test_labeled_on_merged_pr_no_backport_label():
data = {
"action": "labeled",
"pull_request": {
"merged": True,
"number": 1,
"merged_by": {"login": "Mariatta"},
"user": {"login": "Mariatta"},
"merge_commit_sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9",
},
"repository": {
"issues_url": "https://api.github.com/repos/python/cpython/issues{/number}"
},
"label": {"name": "CLA signed"},
}
event = sansio.Event(data, event="pull_request", delivery_id="1")
gh = FakeGH()
await backport_pr.router.dispatch(event, gh)
assert not hasattr(gh, "post_data")
assert not hasattr(gh, "post_url")
"issue_url": "https://api.github.com/org/repo/issues/123",
"url": "https://api.github.com/org/repo/pulls/123",
"head": {
"label": "python: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"
assert len(gh.post_url) == 2
assert gh.post_url[0] == 'https://api.github.com/org/repo/issues/123/labels'
assert gh.post_data[0] == ['invalid']
assert gh.post_url[1] == 'https://api.github.com/org/repo/issues/123/comments'
assert gh.post_data[1] == {'body': close_pr.INVALID_PR_COMMENT}
async def test_branch_deleted_when_pr_merged():
data = {
"action": "closed",
"pull_request": {
"number": 5722,
"user": {"login": "miss-islington"},
"merged": True,
"merged_by": {"login": "miss-islington"},
"head": {"ref": "backport-17ab8f0-3.7"},
},
}
event = sansio.Event(data, event="pull_request", delivery_id="1")
gh = FakeGH()
await delete_branch.router.dispatch(event, gh)
assert gh.post_data is None # does not leave a comment
assert (
gh.delete_url
== f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}"
)
async def getitem(self, url, url_vars={}):
self.getitem_url = sansio.format_url(url, url_vars)
return self._getitem_return[self.getitem_url]
async def getitem(self, url, url_vars={}):
self.getitem_url = sansio.format_url(url, url_vars)
return self._getitem_return[self.getitem_url]
def get_request_headers():
username = os.environ.get("GH_USERNAME")
gh_auth = os.environ.get("GH_AUTH")
return sansio.create_headers(username, oauth_token=gh_auth)
def __init__(self, requester: str, *, oauth_token: Opt[str] = None,
cache: Opt[CACHE_TYPE] = None) -> None:
self.requester = requester
self.oauth_token = oauth_token
self._cache = cache
self.rate_limit: Opt[sansio.RateLimit] = None