Tools: Improve gitea utils function optional paramenter handling

Two fixes/improvements to `gitea_json_issue_events_filter()`:
- The `username` parameter would be optional, but not setting it would
  make the function do nothing. Ignore it if not set.
- Not passing `event_type` (and not passing `labels`) would make the
  function do nothing. It wasn't optional strictly speaking but the
  default was an empty set, which is more or less the same. Make it
  properly optional so not specifying an event-type will return events
  of any type.
This commit is contained in:
Julian Eisel
2025-02-07 14:25:24 +01:00
parent 190ba72acf
commit 5de40adc9e

View File

@@ -162,7 +162,7 @@ def gitea_json_issue_events_filter(
date_end: datetime.datetime | None = None,
username: str | None = None,
labels: set[str] | None = None,
event_type: set[str] = set(),
event_type: set[str] | None = None,
) -> list[dict[str, Any]]:
"""
Filter all comments and events on the issue list.
@@ -189,12 +189,12 @@ def gitea_json_issue_events_filter(
if not event:
continue
if not event["user"] or event["user"]["username"] != username:
if username and (not event["user"] or event["user"]["username"] != username):
continue
if labels and event["type"] == "label" and event["label"]["name"] in labels:
pass
elif event["type"] in event_type:
elif not event_type or event["type"] in event_type:
pass
else:
continue