@@ -39,6 +39,18 @@ def _dec(func):
39
39
return _dec
40
40
41
41
42
+ def dd (name : str ) -> str :
43
+ """Create an key for Dinghy-specfic data. (dd == Dinghy Data)
44
+
45
+ Dinghy adds extra data to GitHub responses. All of the keys for this data
46
+ are prefixed, created with this function.
47
+ """
48
+ return f"dinghy_{ name } "
49
+
50
+
51
+ DD_children = dd ("children" )
52
+
53
+
42
54
class Digester :
43
55
"""
44
56
Use GitHub GraphQL to get data about recent changes.
@@ -78,8 +90,8 @@ async def get_org_project_entries(self, org, number, home_repo="", title=None):
78
90
entries = await self ._process_entries (entries )
79
91
for entry in entries :
80
92
entry ["other_repo" ] = entry ["repository" ]["nameWithOwner" ] != home_repo
81
- if "children" not in entry :
82
- entry ["children" ] = entry ["comments" ]["nodes" ]
93
+ if DD_children not in entry :
94
+ entry [DD_children ] = entry ["comments" ]["nodes" ]
83
95
project = glom (project , "data.organization.project" )
84
96
container = {
85
97
"url" : project ["url" ],
@@ -332,7 +344,7 @@ async def _process_issue(self, issue):
332
344
issue (dict): the issue to populate.
333
345
"""
334
346
await self .get_more (issue ["comments" ], "issue_comments.graphql" , issue ["id" ])
335
- issue ["children" ] = self ._trim_unwanted (issue ["comments" ]["nodes" ])
347
+ issue [DD_children ] = self ._trim_unwanted (issue ["comments" ]["nodes" ])
336
348
337
349
async def _process_pull_request (self , pull ):
338
350
"""
@@ -377,7 +389,7 @@ async def _process_pull_request(self, pull):
377
389
378
390
# Make a map of the reviews.
379
391
for rev in pull ["reviews" ]["nodes" ]:
380
- rev ["review_state" ] = rev ["state" ]
392
+ rev [dd ( "review_state" ) ] = rev ["state" ]
381
393
reviews [rev ["id" ]] = rev
382
394
383
395
# For each thread, attach the thread as a child of the review. Each
@@ -387,24 +399,24 @@ async def _process_pull_request(self, pull):
387
399
# comment 1.
388
400
for thread in pull ["reviewThreads" ]["nodes" ]:
389
401
com0 = thread ["comments" ]["nodes" ][0 ]
390
- com0 ["children" ] = thread ["comments" ]["nodes" ][1 :]
402
+ com0 [DD_children ] = thread ["comments" ]["nodes" ][1 :]
391
403
com0 ["isResolved" ] = thread ["isResolved" ]
392
404
rev_id = com0 ["pullRequestReview" ]["id" ]
393
- review_comments = reviews [rev_id ].setdefault ("children" , [])
405
+ review_comments = reviews [rev_id ].setdefault (DD_children , [])
394
406
review_comments .append (com0 )
395
407
396
408
# For each review, show it if it has a body, or if it has children, or
397
409
# if it's not just "COMMENTED".
398
410
for rev in reviews .values ():
399
- if rev ["bodyText" ] or rev .get ("children" ) or rev ["state" ] != "COMMENTED" :
411
+ if rev ["bodyText" ] or rev .get (DD_children ) or rev ["state" ] != "COMMENTED" :
400
412
com = children .setdefault (rev ["id" ], dict (rev ))
401
- com ["review_state" ] = rev ["state" ]
413
+ com [dd ( "review_state" ) ] = rev ["state" ]
402
414
403
- if not rev ["bodyText" ] and len (rev .get ("children" , ())) == 1 :
415
+ if not rev ["bodyText" ] and len (rev .get (DD_children , ())) == 1 :
404
416
# A review with just one comment and no body: the comment should
405
417
# go where the review would have been.
406
- com = rev ["children" ][0 ]
407
- com ["review_state" ] = rev ["review_state" ]
418
+ com = rev [DD_children ][0 ]
419
+ com [dd ( "review_state" ) ] = rev [dd ( "review_state" ) ]
408
420
children [rev ["id" ]] = com
409
421
410
422
# Comments are simple: they all get shown.
@@ -414,7 +426,7 @@ async def _process_pull_request(self, pull):
414
426
# Examine all the resulting threads (children). Keep a thread if it has
415
427
# any comments newer than our since date. Mark older comments as old.
416
428
kids , _ = self ._trim_unwanted_tree (children .values ())
417
- pull ["children" ] = kids
429
+ pull [DD_children ] = kids
418
430
419
431
def _trim_unwanted_tree (self , nodes ):
420
432
"""
@@ -429,12 +441,12 @@ def _trim_unwanted_tree(self, nodes):
429
441
any_interesting = True
430
442
else :
431
443
any_interesting = False
432
- node ["boring" ] = True
444
+ node [dd ( "boring" ) ] = True
433
445
kids , any_interesting_kids = self ._trim_unwanted_tree (
434
- node .get ("children" , ())
446
+ node .get (DD_children , ())
435
447
)
436
448
if any_interesting or any_interesting_kids :
437
- node ["children" ] = kids
449
+ node [DD_children ] = kids
438
450
keep .append (node )
439
451
any_interesting_total = True
440
452
keep = sorted (keep , key = operator .itemgetter ("updatedAt" ))
@@ -451,7 +463,7 @@ def _add_reasons(self, entry):
451
463
# write "reasonCreated" based on "createdAt", etc.
452
464
for slug in ["Created" , "Closed" , "Merged" ]:
453
465
at = slug .lower () + "At"
454
- entry [f"reason{ slug } " ] = bool (entry .get (at ) and entry [at ] > self .since )
466
+ entry [dd ( f"reason{ slug } " ) ] = bool (entry .get (at ) and entry [at ] > self .since )
455
467
456
468
457
469
def coro_from_item (digester , item ):
0 commit comments