Skip to content

Commit

Permalink
fix: ignore bots and ignored users on pull request comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Oct 6, 2022
1 parent 771db81 commit ab944e3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/dinghy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Dinghy daily digest tool.
"""

__version__ = "0.13.3"
__version__ = "0.13.4"
35 changes: 22 additions & 13 deletions src/dinghy/digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,25 @@ 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
users.
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

Expand Down Expand Up @@ -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):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/dinghy/templates/digest.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
.homerepo {
color: #888;
}
.old > p {
.boring > p {
color: #888;
}
.footer {
Expand Down Expand Up @@ -246,7 +246,7 @@
{% if entry.children -%}
<ul class="comments">
{% for child in entry.children recursive -%}
<li{% if child.old %} class="old"{% endif %}>
<li{% if child.boring %} class="boring"{% endif %}>
<p><a href="{{ child.url }}" title="{{ child.updatedAt|datetime() }}">
{% if child.review_state -%}
{% if child.review_state == "APPROVED" -%}
Expand Down

0 comments on commit ab944e3

Please sign in to comment.