Skip to content

Commit 3be85e8

Browse files
committed
Skip comments minimized with sertain reasons
1 parent 11614be commit 3be85e8

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

scripts/people.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
from datetime import datetime, timedelta, timezone
88
from math import ceil
99
from pathlib import Path
10-
from typing import Any
10+
from typing import Annotated, Any
1111

1212
import httpx
1313
import yaml
1414
from github import Github
15-
from pydantic import BaseModel, SecretStr
15+
from pydantic import BaseModel, BeforeValidator, SecretStr
1616
from pydantic_settings import BaseSettings
1717

1818
github_graphql_url = "https://api.github.com/graphql"
@@ -21,6 +21,8 @@
2121

2222
POINTS_PER_MINUTE_LIMIT = 84 # 5000 points per hour
2323

24+
MINIMIZED_COMMENTS_REASONS_TO_EXCLUDE = {"abuse", "off-topic", "duplicate", "spam"}
25+
2426

2527
class RateLimiter:
2628
def __init__(self) -> None:
@@ -102,8 +104,10 @@ def update_request_info(self, cost: int, remaining: int, reset_at: str) -> None:
102104
avatarUrl
103105
url
104106
}
107+
minimizedReason
105108
}
106109
}
110+
minimizedReason
107111
}
108112
}
109113
}
@@ -118,6 +122,10 @@ def update_request_info(self, cost: int, remaining: int, reset_at: str) -> None:
118122
}
119123
"""
120124

125+
LowerStr = Annotated[
126+
str, BeforeValidator(lambda v: v.lower() if isinstance(v, str) else v)
127+
]
128+
121129

122130
class Author(BaseModel):
123131
login: str
@@ -128,6 +136,7 @@ class Author(BaseModel):
128136
class CommentsNode(BaseModel):
129137
createdAt: datetime
130138
author: Author | None = None
139+
minimizedReason: LowerStr | None = None
131140

132141

133142
class Replies(BaseModel):
@@ -136,6 +145,7 @@ class Replies(BaseModel):
136145

137146

138147
class DiscussionsCommentsNode(CommentsNode):
148+
minimizedReason: LowerStr | None = None
139149
replies: Replies
140150

141151

@@ -278,7 +288,10 @@ def get_discussions_experts(
278288
discussion_author_name = discussion.author.login
279289
discussion_commentors: dict[str, datetime] = {}
280290
for comment in discussion.comments.nodes:
281-
if comment.author:
291+
if (
292+
comment.minimizedReason not in MINIMIZED_COMMENTS_REASONS_TO_EXCLUDE
293+
and comment.author
294+
):
282295
authors[comment.author.login] = comment.author
283296
if comment.author.login != discussion_author_name:
284297
author_time = discussion_commentors.get(
@@ -288,7 +301,10 @@ def get_discussions_experts(
288301
author_time, comment.createdAt
289302
)
290303
for reply in comment.replies.nodes:
291-
if reply.author:
304+
if (
305+
reply.minimizedReason not in MINIMIZED_COMMENTS_REASONS_TO_EXCLUDE
306+
and reply.author
307+
):
292308
authors[reply.author.login] = reply.author
293309
if reply.author.login != discussion_author_name:
294310
author_time = discussion_commentors.get(

0 commit comments

Comments
 (0)