From db76eafb441ac2a87a30ced72435868c734df194 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Fri, 6 Dec 2019 22:10:40 +0000 Subject: [PATCH] handle issue comments --- my/coding/github.py | 47 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/my/coding/github.py b/my/coding/github.py index 6139f64..b3b3e1a 100644 --- a/my/coding/github.py +++ b/my/coding/github.py @@ -85,14 +85,26 @@ def _parse_dt(s: str) -> datetime: return pytz.utc.localize(datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ')) def _parse_repository(d: Dict) -> Event: + url = d['url'] name = d['name'] return Event( dt=_parse_dt(d['created_at']), + link=url, summary='created ' + name, - link=d['url'], eid='created_' + name, # TODO ?? ) +def _parse_issue_comment(d: Dict) -> Event: + url = d['url'] + return Event( + dt=_parse_dt(d['created_at']), + link=url, + summary=f'commented on issue {url}', + eid='issue_comment_' + url, + body=d['body'], # TODO FIXME it's markdown, could use it somehow.. + ) + + def _parse_event(d: Dict) -> Event: summary, link = _get_summary(d) body = d.get('payload', {}).get('comment', {}).get('body') @@ -110,19 +122,32 @@ def iter_gdpr_events() -> Iterator[Res[Event]]: Parses events from GDPR export (https://github.com/settings/admin) """ files = list(sorted(paths.github.gdpr_dir.glob('*.json'))) + handler_map = { + 'schema': None, + 'repositories_': _parse_repository, + 'issue_comments_': _parse_issue_comment, + } for f in files: - fn = f.name - if fn == 'schema.json': - continue - elif fn.startswith('repositories_'): - j = json.loads(f.read_text()) - for r in j: - try: - yield _parse_repository(r) - except Exception as e: - yield e + handler: Any + for prefix, h in handler_map.items(): + if not f.name.startswith(prefix): + continue + handler = h + break else: yield RuntimeError(f'Unhandled file: {f}') + continue + + if handler is None: + # ignored + continue + + j = json.loads(f.read_text()) + for r in j: + try: + yield handler(r) + except Exception as e: + yield e def iter_events():