2121from typing import Any
2222
2323from ghdcbot .config .models import BotConfig , IdentityMapping
24+ from ghdcbot .core .interfaces import Storage
2425from ghdcbot .core .models import ContributionEvent , ContributionSummary , Score
2526
2627logger = logging .getLogger ("Snapshots" )
3031
3132
3233def write_snapshots_to_github (
33- storage : Any ,
34+ storage : Storage ,
3435 config : BotConfig ,
3536 github_writer : Any ,
3637 identity_mappings : list [IdentityMapping ],
@@ -83,7 +84,7 @@ def write_snapshots_to_github(
8384
8485
8586def _write_snapshots (
86- storage : Any ,
87+ storage : Storage ,
8788 config : BotConfig ,
8889 github_writer : Any ,
8990 snapshot_config : Any ,
@@ -138,23 +139,21 @@ def _write_snapshots(
138139 },
139140 )
140141 # Audit log
141- append_audit = getattr (storage , "append_audit_event" , None )
142- if callable (append_audit ):
143- append_audit ({
144- "event_type" : "snapshot_written" ,
145- "context" : {
146- "org" : config .github .org ,
147- "repo" : f"{ owner } /{ repo } " ,
148- "snapshot_dir" : snapshot_dir ,
149- "run_id" : run_id ,
150- "files_written" : files_written ,
151- "timestamp" : now .isoformat (),
152- },
153- })
142+ storage .append_audit_event ({
143+ "event_type" : "snapshot_written" ,
144+ "context" : {
145+ "org" : config .github .org ,
146+ "repo" : f"{ owner } /{ repo } " ,
147+ "snapshot_dir" : snapshot_dir ,
148+ "run_id" : run_id ,
149+ "files_written" : files_written ,
150+ "timestamp" : now .isoformat (),
151+ },
152+ })
154153
155154
156155def _collect_snapshot_data (
157- storage : Any ,
156+ storage : Storage ,
158157 config : BotConfig ,
159158 identity_mappings : list [IdentityMapping ],
160159 scores : list [Score ],
@@ -253,21 +252,19 @@ def _collect_snapshot_data(
253252
254253 # Issue requests snapshot
255254 issue_requests_data = []
256- list_pending = getattr (storage , "list_pending_issue_requests" , None )
257- if callable (list_pending ):
258- pending_requests = list_pending ()
259- for req in pending_requests :
260- issue_requests_data .append ({
261- "request_id" : req .get ("request_id" ),
262- "discord_user_id" : req .get ("discord_user_id" ),
263- "github_user" : req .get ("github_user" ),
264- "owner" : req .get ("owner" ),
265- "repo" : req .get ("repo" ),
266- "issue_number" : req .get ("issue_number" ),
267- "issue_url" : req .get ("issue_url" ),
268- "created_at" : req .get ("created_at" ),
269- "status" : req .get ("status" ),
270- })
255+ pending_requests = storage .list_pending_issue_requests ()
256+ for req in pending_requests :
257+ issue_requests_data .append ({
258+ "request_id" : req .get ("request_id" ),
259+ "discord_user_id" : req .get ("discord_user_id" ),
260+ "github_user" : req .get ("github_user" ),
261+ "owner" : req .get ("owner" ),
262+ "repo" : req .get ("repo" ),
263+ "issue_number" : req .get ("issue_number" ),
264+ "issue_url" : req .get ("issue_url" ),
265+ "created_at" : req .get ("created_at" ),
266+ "status" : req .get ("status" ),
267+ })
271268
272269 issue_requests = {
273270 "schema_version" : SCHEMA_VERSION ,
@@ -279,20 +276,18 @@ def _collect_snapshot_data(
279276
280277 # Notifications snapshot (recent sent notifications)
281278 notifications_data = []
282- list_notifications = getattr (storage , "list_recent_notifications" , None )
283- if callable (list_notifications ):
284- recent_notifications = list_notifications (limit = 1000 ) # Last 1000 notifications
285- for notif in recent_notifications :
286- notifications_data .append ({
287- "dedupe_key" : notif .get ("dedupe_key" ),
288- "event_type" : notif .get ("event_type" ),
289- "github_user" : notif .get ("github_user" ),
290- "discord_user_id" : notif .get ("discord_user_id" ),
291- "repo" : notif .get ("repo" ),
292- "target" : notif .get ("target" ),
293- "channel_id" : notif .get ("channel_id" ),
294- "sent_at" : notif .get ("sent_at" ),
295- })
279+ recent_notifications = storage .list_recent_notifications (limit = 1000 )
280+ for notif in recent_notifications :
281+ notifications_data .append ({
282+ "dedupe_key" : notif .get ("dedupe_key" ),
283+ "event_type" : notif .get ("event_type" ),
284+ "github_user" : notif .get ("github_user" ),
285+ "discord_user_id" : notif .get ("discord_user_id" ),
286+ "repo" : notif .get ("repo" ),
287+ "target" : notif .get ("target" ),
288+ "channel_id" : notif .get ("channel_id" ),
289+ "sent_at" : notif .get ("sent_at" ),
290+ })
296291
297292 notifications = {
298293 "schema_version" : SCHEMA_VERSION ,
0 commit comments