Skip to content

Commit

Permalink
fix: comments can have @ghost authors. #23
Browse files Browse the repository at this point in the history
Look for "author" == None anywhere in returned data, and correct them to @ghost.
  • Loading branch information
nedbat committed Oct 25, 2022
1 parent d0d5d5a commit 730227e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
7 changes: 7 additions & 0 deletions scriv.d/20221025_115913_nedbat_bug23.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Fixed
.....

- Comments by deleted GitHub users would cause a crash. This is now fixed
(`issue 23`_).

.. _issue 23: https://github.com/nedbat/dinghy/issues/23
28 changes: 20 additions & 8 deletions src/dinghy/digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,25 @@ def _trim_unwanted(self, nodes):
nodes = sorted(nodes, key=operator.itemgetter("updatedAt"))
return nodes

def _fix_ghosts(self, obj):
"""
GitHub has a @ghost account for deleted users. That shows up in our
data as None. Fix those to have data we can use.
"""
if isinstance(obj, list):
for elt in obj:
self._fix_ghosts(elt)
elif isinstance(obj, dict):
for key in obj:
if key == "author":
if obj["author"] is None:
obj["author"] = {
"__typename": "User",
"login": "ghost",
}
else:
self._fix_ghosts(obj[key])

async def _process_entries(self, entries):
"""
Process entries after they've been retrieved.
Expand All @@ -253,14 +272,7 @@ async def _process_entries(self, entries):
else:
await json_save(entry, f"save_{kind}_{num}.json")

# GitHub has a @ghost account for deleted users. That shows up in our
# data as a None author. Fix those.
for entry in entries:
if entry["author"] is None:
entry["author"] = {
"__typename": "User",
"login": "ghost",
}
self._fix_ghosts(entries)

entries = self._trim_unwanted(entries)
entries = await asyncio.gather(*map(self._process_entry, entries))
Expand Down

0 comments on commit 730227e

Please sign in to comment.