handle remaining gdpr files

This commit is contained in:
Dima Gerasimov 2019-12-06 22:41:20 +00:00
parent 2d1a0b7732
commit ed25ee91bf

View file

@ -85,6 +85,7 @@ def _parse_dt(s: str) -> datetime:
return pytz.utc.localize(datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ')) return pytz.utc.localize(datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ'))
# TODO extract to separate gdpr module?
# TODO typing.TypedDict could be handy here.. # TODO typing.TypedDict could be handy here..
def _parse_common(d: Dict) -> Dict: def _parse_common(d: Dict) -> Dict:
url = d['url'] url = d['url']
@ -113,7 +114,6 @@ def _parse_issue_comment(d: Dict) -> Event:
) )
# Event(dt=datetime.datetime(2019, 10, 15, 22, 50, 57, tzinfo=<UTC>), summary='opened issue Make seting up easier', eid='10638242494', link='https://github.com/karlicoss/my/issues/1', body=None),
def _parse_issue(d: Dict) -> Event: def _parse_issue(d: Dict) -> Event:
url = d['url'] url = d['url']
title = d['title'] title = d['title']
@ -124,6 +124,36 @@ def _parse_issue(d: Dict) -> Event:
) )
def _parse_pull_request(d: Dict) -> Event:
url = d['url']
title = d['title']
return Event(
**_parse_common(d),
# TODO distinguish incoming/outgoing?
# TODO action? opened/closed??
summary=f'PR {title}',
eid='pull_request_' + url,
)
def _parse_release(d: Dict) -> Event:
tag = d['tag_name']
return Event(
**_parse_common(d),
summary=f'released {tag}',
eid='release_' + tag,
)
def _parse_commit_comment(d: Dict) -> Event:
url = d['url']
return Event(
**_parse_common(d),
summary=f'commented on {url}',
eid='commoit_comment_' + url,
)
def _parse_event(d: Dict) -> Event: def _parse_event(d: Dict) -> Event:
summary, link = _get_summary(d) summary, link = _get_summary(d)
body = d.get('payload', {}).get('comment', {}).get('body') body = d.get('payload', {}).get('comment', {}).get('body')
@ -145,9 +175,13 @@ def iter_gdpr_events() -> Iterator[Res[Event]]:
'schema' : None, 'schema' : None,
'issue_events_': None, # eh, doesn't seem to have any useful bodies 'issue_events_': None, # eh, doesn't seem to have any useful bodies
'attachments_' : None, # not sure if useful 'attachments_' : None, # not sure if useful
'users' : None, # just contains random users
'repositories_' : _parse_repository, 'repositories_' : _parse_repository,
'issue_comments_': _parse_issue_comment, 'issue_comments_': _parse_issue_comment,
'issues_' : _parse_issue, 'issues_' : _parse_issue,
'pull_requests_' : _parse_pull_request,
'releases_' : _parse_release,
'commit_comments': _parse_commit_comment,
} }
for f in files: for f in files:
handler: Any handler: Any