handle issue comments
This commit is contained in:
parent
841454b1fe
commit
db76eafb44
1 changed files with 36 additions and 11 deletions
|
@ -85,14 +85,26 @@ 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'))
|
||||||
|
|
||||||
def _parse_repository(d: Dict) -> Event:
|
def _parse_repository(d: Dict) -> Event:
|
||||||
|
url = d['url']
|
||||||
name = d['name']
|
name = d['name']
|
||||||
return Event(
|
return Event(
|
||||||
dt=_parse_dt(d['created_at']),
|
dt=_parse_dt(d['created_at']),
|
||||||
|
link=url,
|
||||||
summary='created ' + name,
|
summary='created ' + name,
|
||||||
link=d['url'],
|
|
||||||
eid='created_' + name, # TODO ??
|
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:
|
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')
|
||||||
|
@ -110,19 +122,32 @@ def iter_gdpr_events() -> Iterator[Res[Event]]:
|
||||||
Parses events from GDPR export (https://github.com/settings/admin)
|
Parses events from GDPR export (https://github.com/settings/admin)
|
||||||
"""
|
"""
|
||||||
files = list(sorted(paths.github.gdpr_dir.glob('*.json')))
|
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:
|
for f in files:
|
||||||
fn = f.name
|
handler: Any
|
||||||
if fn == 'schema.json':
|
for prefix, h in handler_map.items():
|
||||||
continue
|
if not f.name.startswith(prefix):
|
||||||
elif fn.startswith('repositories_'):
|
continue
|
||||||
j = json.loads(f.read_text())
|
handler = h
|
||||||
for r in j:
|
break
|
||||||
try:
|
|
||||||
yield _parse_repository(r)
|
|
||||||
except Exception as e:
|
|
||||||
yield e
|
|
||||||
else:
|
else:
|
||||||
yield RuntimeError(f'Unhandled file: {f}')
|
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():
|
def iter_events():
|
||||||
|
|
Loading…
Add table
Reference in a new issue