Skip to content

Commit ed94b7b

Browse files
committed
Guard list_contributions call with getattr; rename test
- Wrap storage.list_contributions call in getattr/callable check, consistent with how other optional storage methods are accessed in this module (list_pending_issue_requests, list_recent_notifications). - Remove redundant getattr on snapshot_config.include_raw_events; field is now a real Pydantic field with a default, so direct access is safe. - Rename test_raw_events_excluded_by_default -> test_raw_events_excluded_when_false; the old name implied the test exercised the default, but it passed include_raw_events=False explicitly.
1 parent 1de9ebc commit ed94b7b

2 files changed

Lines changed: 23 additions & 22 deletions

File tree

src/ghdcbot/engine/snapshots.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _write_snapshots(
114114
contribution_summaries=contribution_summaries,
115115
run_id=run_id,
116116
generated_at=now,
117-
include_raw_events=getattr(snapshot_config, "include_raw_events", False),
117+
include_raw_events=snapshot_config.include_raw_events,
118118
)
119119

120120
# Write each snapshot file to GitHub
@@ -315,26 +315,27 @@ def _collect_snapshot_data(
315315
}
316316

317317
if include_raw_events:
318-
raw_events = storage.list_contributions(period_start)
319-
events_data = [
320-
{
321-
"github_user": event.github_user,
322-
"event_type": event.event_type,
323-
"repo": event.repo,
324-
"created_at": event.created_at.isoformat(),
325-
"payload": event.payload,
318+
list_contributions = getattr(storage, "list_contributions", None)
319+
if callable(list_contributions):
320+
events_data = [
321+
{
322+
"github_user": event.github_user,
323+
"event_type": event.event_type,
324+
"repo": event.repo,
325+
"created_at": event.created_at.isoformat(),
326+
"payload": event.payload,
327+
}
328+
for event in list_contributions(period_start)
329+
]
330+
files["events.json"] = {
331+
"schema_version": SCHEMA_VERSION,
332+
"generated_at": generated_at.isoformat(),
333+
"org": org,
334+
"run_id": run_id,
335+
"period_start": period_start.isoformat(),
336+
"period_end": period_end.isoformat(),
337+
"data": events_data,
326338
}
327-
for event in raw_events
328-
]
329-
files["events.json"] = {
330-
"schema_version": SCHEMA_VERSION,
331-
"generated_at": generated_at.isoformat(),
332-
"org": org,
333-
"run_id": run_id,
334-
"period_start": period_start.isoformat(),
335-
"period_end": period_end.isoformat(),
336-
"data": events_data,
337-
}
338339

339340
return files
340341

tests/test_snapshots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ def _make_config(*, snapshots: "SnapshotConfig | None" = None) -> "BotConfig":
359359
)
360360

361361

362-
def test_raw_events_excluded_by_default() -> None:
363-
"""events.json is not written when include_raw_events is False (default)."""
362+
def test_raw_events_excluded_when_false() -> None:
363+
"""events.json is not written when include_raw_events is False."""
364364
storage = MockStorage()
365365
storage.contributions = [
366366
ContributionEvent(

0 commit comments

Comments
 (0)