From ab944e3378b9681909d76f98b0a18a31c7d590fc Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 6 Oct 2022 19:09:08 -0400 Subject: [PATCH] fix: ignore bots and ignored users on pull request comments --- CHANGELOG.rst | 12 ++++++++++ src/dinghy/__init__.py | 2 +- src/dinghy/digest.py | 35 ++++++++++++++++++----------- src/dinghy/templates/digest.html.j2 | 4 ++-- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2845c3e..55f7e2c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -22,6 +22,18 @@ See the fragment files in the `scriv.d directory`_. .. scriv-insert-here +.. _changelog-0.13.4: + +0.13.4 — 2022-10-06 +------------------- + +Fixed +..... + +- Comments on pull requests were only filtered by their age, not their authors, + so bot comments, and comments by "ignored users" were still included. This + is now fixed. + .. _changelog-0.13.3: 0.13.3 — 2022-09-29 diff --git a/src/dinghy/__init__.py b/src/dinghy/__init__.py index 5a5b6a9..55e81a2 100644 --- a/src/dinghy/__init__.py +++ b/src/dinghy/__init__.py @@ -2,4 +2,4 @@ Dinghy daily digest tool. """ -__version__ = "0.13.3" +__version__ = "0.13.4" diff --git a/src/dinghy/digest.py b/src/dinghy/digest.py index df67f94..ee8feae 100644 --- a/src/dinghy/digest.py +++ b/src/dinghy/digest.py @@ -212,6 +212,17 @@ async def get_more( ) container["nodes"] = all_nodes + def _node_is_interesting(self, node): + """ + Is a node interesting to show? It has to be new enough, by a real user, + and not by someone we want to ignore. + """ + return ( + node["updatedAt"] > self.since + and node["author"]["__typename"] == "User" + and node["author"]["login"] not in self.ignore_users + ) + def _trim_unwanted(self, nodes): """ Trim a list to keep only activity since `self.since`, and only by real @@ -219,9 +230,7 @@ def _trim_unwanted(self, nodes): The returned list is also sorted by updatedAt date. """ - nodes = (n for n in nodes if n["updatedAt"] > self.since) - nodes = (n for n in nodes if n["author"]["__typename"] == "User") - nodes = (n for n in nodes if n["author"]["login"] not in self.ignore_users) + nodes = (n for n in nodes if self._node_is_interesting(n)) nodes = sorted(nodes, key=operator.itemgetter("updatedAt")) return nodes @@ -365,23 +374,23 @@ def _trim_unwanted_tree(self, nodes): """ Trim a nested list to indicate activity since `self.since`. A thread will be kept if any of its children is newer than since. Items older - than that will be get ["old"]=True, and shown grayed in the output. + than that will get ["boring"]=True, and shown grayed in the output. """ keep = [] - any_since_total = False + any_interesting_total = False for node in nodes: - if node["updatedAt"] > self.since: - any_since = True + if self._node_is_interesting(node): + any_interesting = True else: - any_since = False - node["old"] = True - kids, any_since_kids = self._trim_unwanted_tree(node.get("children", ())) - if any_since or any_since_kids: + any_interesting = False + node["boring"] = True + kids, any_interesting_kids = self._trim_unwanted_tree(node.get("children", ())) + if any_interesting or any_interesting_kids: node["children"] = kids keep.append(node) - any_since_total = True + any_interesting_total = True keep = sorted(keep, key=operator.itemgetter("updatedAt")) - return keep, any_since_total + return keep, any_interesting_total def _add_reasons(self, entry): """ diff --git a/src/dinghy/templates/digest.html.j2 b/src/dinghy/templates/digest.html.j2 index 80cd106..0839b07 100644 --- a/src/dinghy/templates/digest.html.j2 +++ b/src/dinghy/templates/digest.html.j2 @@ -109,7 +109,7 @@ .homerepo { color: #888; } - .old > p { + .boring > p { color: #888; } .footer { @@ -246,7 +246,7 @@ {% if entry.children -%}