Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{"name": "awaiting merge"},
{"name": AUTOMERGE_LABEL},
{"name": "CLA signed"},
],
"head": {"sha": sha},
"number": 5547,
"title": "bpo-32720: Fixed the replacement field grammar documentation.",
"body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.",
"url": "https://api.github.com/repos/python/cpython/pulls/5547",
"issue_url": "https://api.github.com/repos/python/cpython/issues/5547",
},
"sender": {"login": "Mariatta"},
"label": {"name": AUTOMERGE_LABEL},
}
event = sansio.Event(data, event="pull_request", delivery_id="1")
getitem = {
f"/repos/python/cpython/commits/{sha}/status": {
"state": "success",
"statuses": [
{
"state": "success",
"description": "Issue report skipped",
"context": "bedevere/issue-number",
},
{
"state": "success",
"description": "The Travis CI build passed",
"target_url": "https://travis-ci.org/python/cpython/builds/340259685?utm_source=github_status&utm_medium=notification",
"context": "continuous-integration/travis-ci/pr",
},
async def test_unmerged_pr_is_ignored():
data = {"action": "closed", "pull_request": {"merged": False}}
event = sansio.Event(data, event="pull_request", delivery_id="1")
gh = FakeGH()
await backport_pr.router.dispatch(event, gh)
assert gh.getitem_url is None
data = {
'action': action,
'number': 2248,
'pull_request': {
'title': title,
'body': '',
'issue_url': 'https://api.github.com/issue/2248',
'base': {
'ref': 'master',
},
'statuses_url': 'https://api.github.com/repos/python/cpython/statuses/somehash',
},
'repository': {'issues_url': 'https://api.github.com/issue{/number}'},
'changes': {'title': title},
}
event = sansio.Event(data, event='pull_request',
delivery_id='1')
getitem = {
'https://api.github.com/issue/1234':
{'labels': [{'name': 'CLA signed'}]},
'https://api.github.com/issue/2248': {},
}
gh = FakeGH(getitem=getitem)
await backport.router.dispatch(event, gh)
assert len(gh.post_) == 0
async def test_set_comment_body_already_hyperlinked_bpo(event, action):
data = {
"action": action,
"comment": {
"url": "https://api.github.com/repos/blah/blah/issues/comments/123456",
"body": ("bpo-123"
"[bpo-123](https://bugs.python.org/issue123)"
"[something about bpo-123](https://bugs.python.org/issue123)"
"<a href="https://bugs.python.org/issue123">bpo-123</a>"
)
}
}
event = sansio.Event(data, event=event, delivery_id="123123")
gh = FakeGH()
await bpo.router.dispatch(event, gh)
body_data = gh.patch_data
assert body_data["body"].count("[bpo-123](https://bugs.python.org/issue123)") == 2
assert body_data["body"].count("[something about bpo-123](https://bugs.python.org/issue123)") == 1
assert "123456" in gh.patch_url
async def test_deleting_label():
gh = FakeGH()
event_data = {
"action": "unlabeled",
"pull_request": {
"statuses_url": "https://api.github.com/blah/blah/git-sha",
"title": "An easy fix",
},
}
event = sansio.Event(event_data, event='pull_request', delivery_id='1')
await news.router.dispatch(event, gh)
assert gh.post_data is None
'action': 'opened',
'number': 2248,
'pull_request': {
'title': '[3.6] Backport this (GH-1234)',
'body': 'N/A',
'issue_url': 'https://api.github.com/issue/2248',
'base': {
'ref': '3.6',
},
'statuses_url': 'https://api.github.com/repos/python/cpython/statuses/somehash',
},
'repository': {
'issues_url': 'https://api.github.com/issue{/number}',
},
}
event = sansio.Event(event_data, event='pull_request',
delivery_id='1')
labels_to_test = "CLA signed", "skip news", "type-enhancement", "sprint"
getitem_data = {
'https://api.github.com/issue/1234': {
'labels': [{'name': label} for label in labels_to_test],
'labels_url': 'https://api.github.com/issue/1234/labels{/name}',
'comments_url': 'https://api.github.com/issue/1234/comments',
},
'https://api.github.com/issue/2248': {
'labels_url': 'https://api.github.com/issue/1234/labels{/name}',
},
}
gh = FakeGH(getitem=getitem_data)
await backport.router.dispatch(event, gh)
post = gh.post_[0]
assert post[0] == 'https://api.github.com/issue/1234/labels'
"""GitHubHandler using Aiohttp for HTTP requests
Arguments:
session: Aiohttp Client Session object
requester: Identify self (e.g. user agent)
"""
def create_api_object(self, session: aiohttp.ClientSession,
requester: str, *args, **kwargs) -> None:
self.api = gidgethub.aiohttp.GitHubAPI(
session, requester, oauth_token=self.token,
cache=cachetools.LRUCache(maxsize=500)
)
self.session = session
class Event(gidgethub.sansio.Event):
"""Adds **get(path)** method to Github Webhook event"""
def get(self, path: str, altvalue=KeyError) -> str:
"""Get subkeys from even data using slash separated path"""
data = self.data
try:
for item in path.split("/"):
data = data[item]
except (KeyError, TypeError):
if altvalue == KeyError:
raise KeyError(f"No '{path}' in event type {self.event}") from None
else:
return altvalue
return data
class GitHubAppHandler:
def to_gidgethub(self) -> _GidgetHubEvent:
"""Produce GidgetHub Event from self."""
return _GidgetHubEvent(
data=self.payload,
event=self.name,
delivery_id=str(uuid.uuid4()),
)