Skip to content

Commit 2b38c28

Browse files
committed
refactor(analytics):improve formatting as per the pre-commit hook
1 parent 9ecd7c2 commit 2b38c28

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

backend/analytics_server/mhq/service/code/sync/etl_code_analytics.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def create_pr_metrics(
2222
) -> PullRequest:
2323
if pr.state == PullRequestState.OPEN:
2424
return pr
25-
25+
2626
non_bot_pr_events = self.filter_non_bot_events(pr_events)
2727
pr_performance = self.get_pr_performance(pr, non_bot_pr_events)
2828

@@ -41,7 +41,11 @@ def create_pr_metrics(
4141
pr_performance.cycle_time if pr_performance.cycle_time != -1 else None
4242
)
4343
pr.reviewers = list(
44-
{e.actor_username for e in non_bot_pr_events if e.actor_username != pr.author}
44+
{
45+
e.actor_username
46+
for e in non_bot_pr_events
47+
if e.actor_username != pr.author
48+
}
4549
)
4650

4751
if pr_commits:
@@ -175,12 +179,17 @@ def get_rework_cycles(
175179
rework_cycles += 1
176180

177181
return rework_cycles
178-
179-
def filter_non_bot_events(self, pr_events: List[PullRequestEvent]) -> List[PullRequestEvent]:
182+
183+
def filter_non_bot_events(
184+
self, pr_events: List[PullRequestEvent]
185+
) -> List[PullRequestEvent]:
180186
"""Filter out events created by bot users using regex patterns."""
181-
182-
bot_pattern = re.compile(r'bot|[bB][oO][tT]|\[bot\]|automated|jenkins|ci-|github-actions', re.IGNORECASE)
183-
187+
188+
bot_pattern = re.compile(
189+
r"bot|[bB][oO][tT]|\[bot\]|automated|jenkins|ci-|github-actions",
190+
re.IGNORECASE,
191+
)
192+
184193
return [
185194
event
186195
for event in pr_events
@@ -191,4 +200,4 @@ def filter_non_bot_events(self, pr_events: List[PullRequestEvent]) -> List[PullR
191200
and event.data.get("user", {}).get("type") == "Bot"
192201
)
193202
)
194-
]
203+
]

backend/analytics_server/tests/service/code/sync/test_etl_code_analytics.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,28 +602,29 @@ def test_create_pr_metrics_no_human_rework_time():
602602
)
603603
assert pr_metrics.rework_time is None
604604

605+
605606
def test_create_pr_metrics_filters_bot_type_events():
606607
pr_service = CodeETLAnalyticsService()
607608
t1 = time_now()
608609
t2 = t1 + timedelta(hours=1)
609610
t3 = t2 + timedelta(hours=1)
610611
pr = get_pull_request(state=PullRequestState.MERGED, created_at=t1, updated_at=t1)
611-
612+
612613
bot_event = get_pull_request_event(
613614
pull_request_id=pr.id,
614615
reviewer="github_app",
615616
state=PullRequestEventState.COMMENTED.value,
616617
created_at=t2,
617618
data={"user": {"type": "Bot"}},
618619
)
619-
620+
620621
human_event = get_pull_request_event(
621622
pull_request_id=pr.id,
622623
reviewer="human_user",
623624
state=PullRequestEventState.APPROVED.value,
624625
created_at=t3,
625626
)
626-
627+
627628
pr_metrics = pr_service.create_pr_metrics(pr, [bot_event, human_event], [])
628629
assert "human_user" in pr_metrics.reviewers
629-
assert "github_app" not in pr_metrics.reviewers
630+
assert "github_app" not in pr_metrics.reviewers

0 commit comments

Comments
 (0)