-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreviewer_bot.py
More file actions
823 lines (543 loc) · 26.8 KB
/
reviewer_bot.py
File metadata and controls
823 lines (543 loc) · 26.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
#!/usr/bin/env python3
"""
Reviewer Bot for Safety-Critical Rust Coding Guidelines
This bot manages round-robin assignment of reviewers for coding guideline and
FLS audit issues and PRs. It supports commands for passing reviews, vacations,
and label management.
All commands must be prefixed with @guidelines-bot /<command>:
@guidelines-bot /pass [reason]
- Skip the assigned reviewer for this issue/PR and assign the next person
- The skipped reviewer stays in queue position for future assignments
@guidelines-bot /away YYYY-MM-DD [reason]
- Remove yourself from the queue until the specified date
- Automatically assigns the next available reviewer
@guidelines-bot /claim
- Assign yourself as the reviewer for this issue/PR
- Removes any existing reviewer assignment
@guidelines-bot /release [@username] [reason]
- Release your assignment from this issue/PR (or someone else's with triage+ permission)
- Does NOT auto-assign the next reviewer (use /pass for that)
@guidelines-bot /rectify
- Reconcile this issue/PR's review state from GitHub review history
- Useful when cross-repo review events cannot persist state immediately
@guidelines-bot /r? @username
- Assign a specific reviewer
@guidelines-bot /r? producers
- Assign the next reviewer from the round-robin queue
- Useful for requesting a reviewer on an already-open issue/PR
@guidelines-bot /label +label-name
- Add a label to the issue/PR
@guidelines-bot /label -label-name
- Remove a label from the issue/PR
@guidelines-bot /accept-no-fls-changes
- Update spec.lock and open a PR when the audit reports no guideline impact
@guidelines-bot /sync-members
- Manually trigger sync of the queue with members.md
@guidelines-bot /queue
- Show current queue status and who's next up
@guidelines-bot /commands
- Show all available commands
"""
import sys
from collections.abc import Iterable
from datetime import datetime
from datetime import timezone as _timezone
from pathlib import Path
from typing import Any
# GitHub API interaction
timezone = _timezone
import scripts.reviewer_bot_lib.automation as automation_module
import scripts.reviewer_bot_lib.commands as commands_module
import scripts.reviewer_bot_lib.comment_routing as comment_routing_module
import scripts.reviewer_bot_lib.events as events_module
import scripts.reviewer_bot_lib.github_api as github_api_module
import scripts.reviewer_bot_lib.lease_lock as lease_lock_module
import scripts.reviewer_bot_lib.lifecycle as lifecycle_module
import scripts.reviewer_bot_lib.maintenance as maintenance_module
import scripts.reviewer_bot_lib.reconcile as reconcile_module
import scripts.reviewer_bot_lib.reviews as reviews_module
import scripts.reviewer_bot_lib.state_store as state_store_module
from scripts.reviewer_bot_lib import app as app_module
# Exported runtime config surface used by extracted modules and tests.
# Exported runtime types used by extracted modules and tests.
# Internal-only config consumed directly by the entrypoint adapter.
from scripts.reviewer_bot_lib.config import ( # noqa: F401 # noqa: F401
AUTHOR_ASSOCIATION_TRUST_ALLOWLIST,
BOT_MENTION,
BOT_NAME,
COMMANDS,
DEFERRED_ARTIFACT_RETENTION_DAYS,
DEFERRED_DISCOVERY_BOOTSTRAP_WINDOW_SECONDS,
DEFERRED_DISCOVERY_OVERLAP_SECONDS,
DEFERRED_MISSING_RUN_WINDOW_SECONDS,
EVENT_INTENT_MUTATING,
EVENT_INTENT_NON_MUTATING_DEFER,
EVENT_INTENT_NON_MUTATING_READONLY,
FLS_AUDIT_LABEL,
FRESHNESS_RUNTIME_EPOCH_LEGACY,
FRESHNESS_RUNTIME_EPOCH_V18,
LOCK_API_RETRY_LIMIT,
LOCK_BLOCK_END_MARKER,
LOCK_BLOCK_START_MARKER,
LOCK_COMMIT_MARKER,
LOCK_LEASE_TTL_SECONDS,
LOCK_MAX_WAIT_SECONDS,
LOCK_METADATA_KEYS,
LOCK_REF_BOOTSTRAP_BRANCH,
LOCK_REF_NAME,
LOCK_RENEWAL_WINDOW_SECONDS,
LOCK_RETRY_BASE_SECONDS,
LOCK_SCHEMA_VERSION,
MANDATORY_TRIAGE_APPROVER_LABEL,
MANDATORY_TRIAGE_ESCALATION_TEMPLATE,
MANDATORY_TRIAGE_SATISFIED_TEMPLATE,
MAX_RECENT_ASSIGNMENTS,
REVIEW_DEADLINE_DAYS,
REVIEW_FRESHNESS_RUNBOOK_PATH,
REVIEW_LABELS,
REVIEWER_REQUEST_422_TEMPLATE,
STATE_BLOCK_END_MARKER,
STATE_BLOCK_START_MARKER,
STATE_ISSUE_NUMBER,
STATE_READ_RETRY_BASE_SECONDS,
STATE_READ_RETRY_LIMIT,
STATE_SCHEMA_VERSION,
STATUS_AWAITING_CONTRIBUTOR_RESPONSE_LABEL,
STATUS_AWAITING_REVIEW_COMPLETION_LABEL,
STATUS_AWAITING_REVIEWER_RESPONSE_LABEL,
STATUS_AWAITING_WRITE_APPROVAL_LABEL,
STATUS_LABEL_CONFIG,
STATUS_LABELS,
TRANSITION_PERIOD_DAYS,
AssignmentAttempt,
GitHubApiResult,
LeaseContext,
StateIssueBodyParts,
StateIssueSnapshot,
get_commands_help,
)
from scripts.reviewer_bot_lib.guidance import ( # noqa: F401
get_fls_audit_guidance,
get_issue_guidance,
get_pr_guidance,
)
from scripts.reviewer_bot_lib.members import fetch_members # noqa: F401
from scripts.reviewer_bot_lib.queue import (
get_next_reviewer as queue_get_next_reviewer,
)
from scripts.reviewer_bot_lib.queue import (
process_pass_until_expirations as queue_process_pass_until_expirations,
)
from scripts.reviewer_bot_lib.queue import (
record_assignment as queue_record_assignment,
)
from scripts.reviewer_bot_lib.queue import (
reposition_member_as_next as queue_reposition_member_as_next,
)
from scripts.reviewer_bot_lib.queue import (
sync_members_with_queue as queue_sync_members_with_queue,
)
requests = github_api_module.requests
random = lease_lock_module.random
time = lease_lock_module.time
# ==============================================================================
# GitHub API Helpers
# ==============================================================================
ACTIVE_LEASE_CONTEXT: LeaseContext | None = None
TOUCHED_ISSUE_NUMBERS: set[int] = set()
def _runtime_bot() -> Any:
return sys.modules[__name__]
def get_github_token() -> str:
return github_api_module.get_github_token()
def github_api_request(
method: str,
endpoint: str,
data: dict | None = None,
extra_headers: dict[str, str] | None = None,
*,
suppress_error_log: bool = False,
) -> GitHubApiResult:
return github_api_module.github_api_request(
_runtime_bot(),
method,
endpoint,
data,
extra_headers,
suppress_error_log=suppress_error_log,
)
def github_api(method: str, endpoint: str, data: dict | None = None) -> Any | None:
return github_api_module.github_api(_runtime_bot(), method, endpoint, data)
def post_comment(issue_number: int, body: str) -> bool:
return github_api_module.post_comment(_runtime_bot(), issue_number, body)
def get_repo_labels() -> set[str]:
return github_api_module.get_repo_labels(_runtime_bot())
def add_label(issue_number: int, label: str) -> bool:
return github_api_module.add_label(_runtime_bot(), issue_number, label)
def remove_label(issue_number: int, label: str) -> bool:
return github_api_module.remove_label(_runtime_bot(), issue_number, label)
def add_label_with_status(issue_number: int, label: str) -> bool:
return github_api_module.add_label_with_status(_runtime_bot(), issue_number, label)
def remove_label_with_status(issue_number: int, label: str) -> bool:
return github_api_module.remove_label_with_status(_runtime_bot(), issue_number, label)
def ensure_label_exists(
label: str,
*,
color: str | None = None,
description: str | None = None,
) -> bool:
return github_api_module.ensure_label_exists(
_runtime_bot(),
label,
color=color,
description=description,
)
def collect_touched_item(issue_number: int | None) -> None:
"""Record an issue/PR number for centralized status-label sync."""
if isinstance(issue_number, int) and issue_number > 0:
TOUCHED_ISSUE_NUMBERS.add(issue_number)
def drain_touched_items() -> list[int]:
"""Return touched issue numbers and clear the collector."""
touched = sorted(TOUCHED_ISSUE_NUMBERS)
TOUCHED_ISSUE_NUMBERS.clear()
return touched
def get_issue_or_pr_snapshot(issue_number: int) -> dict | None:
"""Fetch issue metadata used for derived status labels."""
result = github_api("GET", f"issues/{issue_number}")
if isinstance(result, dict):
return result
return None
def get_issue_or_pr_labels(issue_number: int) -> set[str] | None:
"""Fetch the current label set for an issue or PR."""
item = get_issue_or_pr_snapshot(issue_number)
if not isinstance(item, dict):
return None
labels = item.get("labels", [])
if not isinstance(labels, list):
return set()
result = set()
for label in labels:
if isinstance(label, dict):
name = label.get("name")
if isinstance(name, str):
result.add(name)
elif isinstance(label, str):
result.add(label)
return result
def request_reviewer_assignment(issue_number: int, username: str) -> AssignmentAttempt:
return github_api_module.request_reviewer_assignment(_runtime_bot(), issue_number, username)
def assign_reviewer(issue_number: int, username: str) -> bool:
return github_api_module.assign_reviewer(_runtime_bot(), issue_number, username)
def get_assignment_failure_comment(reviewer: str, attempt: AssignmentAttempt) -> str | None:
return github_api_module.get_assignment_failure_comment(_runtime_bot(), reviewer, attempt)
def get_issue_assignees(issue_number: int) -> list[str]:
return github_api_module.get_issue_assignees(_runtime_bot(), issue_number)
def add_reaction(comment_id: int, reaction: str) -> bool:
return github_api_module.add_reaction(_runtime_bot(), comment_id, reaction)
def remove_assignee(issue_number: int, username: str) -> bool:
return github_api_module.remove_assignee(_runtime_bot(), issue_number, username)
def remove_pr_reviewer(issue_number: int, username: str) -> bool:
return github_api_module.remove_pr_reviewer(_runtime_bot(), issue_number, username)
def unassign_reviewer(issue_number: int, username: str) -> bool:
return github_api_module.unassign_reviewer(_runtime_bot(), issue_number, username)
def check_user_permission(username: str, required_permission: str = "triage") -> bool:
return github_api_module.check_user_permission(_runtime_bot(), username, required_permission)
# ==============================================================================
# State Management
# ==============================================================================
def get_state_issue() -> dict | None:
return state_store_module.get_state_issue(_runtime_bot())
def default_state_issue_prefix() -> str:
return state_store_module.default_state_issue_prefix()
def split_state_issue_body(body: str) -> StateIssueBodyParts:
return state_store_module.split_state_issue_body(body)
def extract_fenced_block(inner_block: str, language_pattern: str) -> str | None:
return state_store_module.extract_fenced_block(inner_block, language_pattern)
def normalize_lock_metadata(lock_meta: dict | None) -> dict:
return state_store_module.normalize_lock_metadata(lock_meta)
def parse_state_yaml_from_issue_body(body: str) -> dict:
return state_store_module.parse_state_yaml_from_issue_body(body)
def parse_lock_metadata_from_issue_body(body: str) -> dict:
return state_store_module.parse_lock_metadata_from_issue_body(body)
def render_marked_fenced_block(
start_marker: str,
end_marker: str,
language: str,
content: str,
) -> str:
return state_store_module.render_marked_fenced_block(start_marker, end_marker, language, content)
def render_state_issue_body(
state: dict,
lock_meta: dict,
base_body: str | None = None,
*,
preserve_state_block: bool = False,
) -> str:
return state_store_module.render_state_issue_body(
state,
lock_meta,
base_body,
preserve_state_block=preserve_state_block,
)
def parse_state_from_issue(issue: dict) -> dict:
return state_store_module.parse_state_from_issue(issue)
def get_state_issue_snapshot() -> StateIssueSnapshot | None:
return state_store_module.get_state_issue_snapshot(_runtime_bot())
def conditional_patch_state_issue(body: str, etag: str | None = None) -> GitHubApiResult:
return state_store_module.conditional_patch_state_issue(_runtime_bot(), body, etag)
def assert_lock_held(operation: str) -> None:
state_store_module.assert_lock_held(_runtime_bot(), operation)
def load_state(*, fail_on_unavailable: bool = False) -> dict:
return state_store_module.load_state(_runtime_bot(), fail_on_unavailable=fail_on_unavailable)
def save_state(state: dict) -> bool:
return state_store_module.save_state(_runtime_bot(), state)
def parse_iso8601_timestamp(value: Any) -> datetime | None:
return state_store_module.parse_iso8601_timestamp(value)
def lock_is_currently_valid(lock_meta: dict, now: datetime | None = None) -> bool:
return lease_lock_module.lock_is_currently_valid(_runtime_bot(), lock_meta, now)
def get_lock_owner_context() -> tuple[str, str, str]:
return lease_lock_module.get_lock_owner_context()
def build_lock_metadata(
lock_token: str,
lock_owner_run_id: str,
lock_owner_workflow: str,
lock_owner_job: str,
) -> dict:
return lease_lock_module.build_lock_metadata(
_runtime_bot(), lock_token, lock_owner_run_id, lock_owner_workflow, lock_owner_job
)
def clear_lock_metadata() -> dict:
return lease_lock_module.clear_lock_metadata(_runtime_bot())
def normalize_lock_ref_name(ref_name: str) -> str:
return lease_lock_module.normalize_lock_ref_name(ref_name)
def get_lock_ref_name() -> str:
return lease_lock_module.get_lock_ref_name(_runtime_bot())
def get_lock_ref_display() -> str:
return lease_lock_module.get_lock_ref_display(_runtime_bot())
def get_state_issue_html_url() -> str:
return lease_lock_module.get_state_issue_html_url(_runtime_bot())
def extract_ref_sha(payload: Any) -> str | None:
return lease_lock_module.extract_ref_sha(payload)
def extract_commit_tree_sha(payload: Any) -> str | None:
return lease_lock_module.extract_commit_tree_sha(payload)
def extract_commit_sha(payload: Any) -> str | None:
return lease_lock_module.extract_commit_sha(payload)
def render_lock_commit_message(lock_meta: dict) -> str:
return lease_lock_module.render_lock_commit_message(_runtime_bot(), lock_meta)
def parse_lock_metadata_from_lock_commit_message(message: str) -> dict:
return lease_lock_module.parse_lock_metadata_from_lock_commit_message(_runtime_bot(), message)
def ensure_lock_ref_exists() -> str:
return lease_lock_module.ensure_lock_ref_exists(_runtime_bot())
def get_lock_ref_snapshot() -> tuple[str, str, dict]:
return lease_lock_module.get_lock_ref_snapshot(_runtime_bot())
def create_lock_commit(parent_sha: str, tree_sha: str, lock_meta: dict) -> GitHubApiResult:
return lease_lock_module.create_lock_commit(_runtime_bot(), parent_sha, tree_sha, lock_meta)
def cas_update_lock_ref(new_sha: str) -> GitHubApiResult:
return lease_lock_module.cas_update_lock_ref(_runtime_bot(), new_sha)
def ensure_state_issue_lease_lock_fresh() -> bool:
return lease_lock_module.ensure_state_issue_lease_lock_fresh(_runtime_bot())
def renew_state_issue_lease_lock(context: LeaseContext) -> bool:
return lease_lock_module.renew_state_issue_lease_lock(_runtime_bot(), context)
def acquire_state_issue_lease_lock() -> LeaseContext:
return lease_lock_module.acquire_state_issue_lease_lock(_runtime_bot())
def release_state_issue_lease_lock() -> bool:
return lease_lock_module.release_state_issue_lease_lock(_runtime_bot())
def sync_members_with_queue(state: dict) -> tuple[dict, list[str]]:
return queue_sync_members_with_queue(_runtime_bot(), state)
def reposition_member_as_next(state: dict, username: str) -> bool:
return queue_reposition_member_as_next(state, username)
def process_pass_until_expirations(state: dict) -> tuple[dict, list[str]]:
return queue_process_pass_until_expirations(state)
# ==============================================================================
# Reviewer Assignment
# ==============================================================================
def get_next_reviewer(state: dict, skip_usernames: set[str] | None = None) -> str | None:
return queue_get_next_reviewer(state, skip_usernames)
def record_assignment(state: dict, github: str, issue_number: int,
issue_type: str) -> None:
queue_record_assignment(
state,
github,
issue_number,
issue_type,
max_recent_assignments=MAX_RECENT_ASSIGNMENTS,
)
# ==============================================================================
# Command Parsing & Handling
# ==============================================================================
def strip_code_blocks(comment_body: str) -> str:
return commands_module.strip_code_blocks(comment_body)
def parse_command(comment_body: str) -> tuple[str, list[str]] | None:
return commands_module.parse_command(_runtime_bot(), comment_body)
def handle_pass_command(state: dict, issue_number: int, comment_author: str,
reason: str | None) -> tuple[str, bool]:
return commands_module.handle_pass_command(_runtime_bot(), state, issue_number, comment_author, reason)
def handle_pass_until_command(state: dict, issue_number: int, comment_author: str,
return_date: str, reason: str | None) -> tuple[str, bool]:
return commands_module.handle_pass_until_command(_runtime_bot(), state, issue_number, comment_author, return_date, reason)
def handle_label_command(state: dict, issue_number: int, label_string: str) -> tuple[str, bool, bool]:
return commands_module.handle_label_command(_runtime_bot(), state, issue_number, label_string)
def parse_issue_labels() -> list[str]:
return commands_module.parse_issue_labels()
def run_command(command: list[str], cwd: Path, check: bool = True) -> Any:
return automation_module.run_command(command, cwd, check=check)
def summarize_output(result: Any, limit: int = 20) -> str:
return automation_module.summarize_output(result, limit=limit)
def list_changed_files(repo_root: Path) -> list[str]:
return automation_module.list_changed_files(repo_root)
def get_default_branch() -> str:
return automation_module.get_default_branch(_runtime_bot())
def find_open_pr_for_branch(branch: str) -> dict | None:
return automation_module.find_open_pr_for_branch(_runtime_bot(), branch)
def resolve_workflow_run_pr_number() -> int:
return commands_module.resolve_workflow_run_pr_number(_runtime_bot())
def create_pull_request(branch: str, base: str, issue_number: int) -> dict | None:
return automation_module.create_pull_request(_runtime_bot(), branch, base, issue_number)
def handle_accept_no_fls_changes_command(issue_number: int, comment_author: str) -> tuple[str, bool]:
return automation_module.handle_accept_no_fls_changes_command(_runtime_bot(), issue_number, comment_author)
def handle_sync_members_command(state: dict) -> tuple[str, bool]:
return commands_module.handle_sync_members_command(_runtime_bot(), state)
def handle_queue_command(state: dict) -> tuple[str, bool]:
return commands_module.handle_queue_command(_runtime_bot(), state)
def handle_commands_command() -> tuple[str, bool]:
return commands_module.handle_commands_command(_runtime_bot())
def handle_claim_command(state: dict, issue_number: int,
comment_author: str) -> tuple[str, bool]:
return commands_module.handle_claim_command(_runtime_bot(), state, issue_number, comment_author)
def handle_release_command(state: dict, issue_number: int,
comment_author: str, args: list | None = None) -> tuple[str, bool]:
return commands_module.handle_release_command(_runtime_bot(), state, issue_number, comment_author, args)
def handle_assign_command(state: dict, issue_number: int,
username: str) -> tuple[str, bool]:
return commands_module.handle_assign_command(_runtime_bot(), state, issue_number, username)
def handle_assign_from_queue_command(state: dict, issue_number: int) -> tuple[str, bool]:
return commands_module.handle_assign_from_queue_command(_runtime_bot(), state, issue_number)
# ==============================================================================
# Event Handlers
# ==============================================================================
def ensure_review_entry(state: dict, issue_number: int, create: bool = False) -> dict | None:
return reviews_module.ensure_review_entry(state, issue_number, create=create)
def set_current_reviewer(state: dict, issue_number: int, reviewer: str,
assignment_method: str = "round-robin") -> None:
reviews_module.set_current_reviewer(state, issue_number, reviewer, assignment_method=assignment_method)
def update_reviewer_activity(state: dict, issue_number: int, reviewer: str) -> bool:
return reviews_module.update_reviewer_activity(state, issue_number, reviewer)
def mark_review_complete(
state: dict,
issue_number: int,
reviewer: str | None,
source: str,
) -> bool:
return reviews_module.mark_review_complete(state, issue_number, reviewer, source)
def is_triage_or_higher(username: str) -> bool:
return reviews_module.is_triage_or_higher(_runtime_bot(), username)
def trigger_mandatory_approver_escalation(state: dict, issue_number: int) -> bool:
return reviews_module.trigger_mandatory_approver_escalation(_runtime_bot(), state, issue_number)
def satisfy_mandatory_approver_requirement(
state: dict,
issue_number: int,
approver: str,
) -> bool:
return reviews_module.satisfy_mandatory_approver_requirement(
_runtime_bot(), state, issue_number, approver
)
def handle_pr_approved_review(
state: dict,
issue_number: int,
review_author: str,
completion_source: str,
) -> bool:
return reviews_module.handle_pr_approved_review(
_runtime_bot(), state, issue_number, review_author, completion_source
)
def parse_github_timestamp(value: str | None) -> datetime | None:
return reviews_module.parse_github_timestamp(value)
def get_pull_request_reviews(issue_number: int) -> list[dict] | None:
return reviews_module.get_pull_request_reviews(_runtime_bot(), issue_number)
def project_status_labels_for_item(
issue_number: int,
state: dict,
*,
issue_snapshot: dict | None = None,
) -> tuple[set[str] | None, dict[str, str | None]]:
return reviews_module.project_status_labels_for_item(
_runtime_bot(), issue_number, state, issue_snapshot=issue_snapshot
)
def sync_status_labels(issue_number: int, desired_labels: set[str], actual_labels: Iterable[str]) -> bool:
return reviews_module.sync_status_labels(_runtime_bot(), issue_number, desired_labels, actual_labels)
def sync_status_labels_for_items(state: dict, issue_numbers: Iterable[int]) -> bool:
return reviews_module.sync_status_labels_for_items(_runtime_bot(), state, issue_numbers)
def list_open_items_with_status_labels() -> list[int]:
return reviews_module.list_open_items_with_status_labels(_runtime_bot())
def handle_rectify_command(state: dict, issue_number: int, comment_author: str) -> tuple[str, bool, bool]:
"""Handle /rectify for the current issue/PR only.
Permission model:
- Allowed for the currently assigned reviewer.
- Allowed for users with triage+ permissions.
Returns (message, success, state_changed).
"""
review_data = ensure_review_entry(state, issue_number)
current_reviewer = review_data.get("current_reviewer") if review_data else None
is_current_reviewer = (
isinstance(current_reviewer, str)
and current_reviewer.lower() == comment_author.lower()
)
has_triage = False
if not is_current_reviewer:
has_triage = check_user_permission(comment_author, "triage")
if not is_current_reviewer and not has_triage:
if current_reviewer:
return (
f"❌ Only the assigned reviewer (@{current_reviewer}) or a maintainer with triage+ "
"permission can run `/rectify`.",
False,
False,
)
return (
"❌ Only maintainers with triage+ permission can run `/rectify` when no assigned "
"reviewer is tracked.",
False,
False,
)
return reconcile_module.reconcile_active_review_entry(
_runtime_bot(),
state,
issue_number,
)
def handle_transition_notice(state: dict, issue_number: int, reviewer: str) -> bool:
return lifecycle_module.handle_transition_notice(_runtime_bot(), state, issue_number, reviewer)
def handle_issue_or_pr_opened(state: dict) -> bool:
return lifecycle_module.handle_issue_or_pr_opened(_runtime_bot(), state)
def handle_labeled_event(state: dict) -> bool:
return lifecycle_module.handle_labeled_event(_runtime_bot(), state)
def handle_issue_edited_event(state: dict) -> bool:
return lifecycle_module.handle_issue_edited_event(_runtime_bot(), state)
def handle_pull_request_target_synchronize(state: dict) -> bool:
return lifecycle_module.handle_pull_request_target_synchronize(_runtime_bot(), state)
def maybe_record_head_observation_repair(issue_number: int, review_data: dict) -> bool:
return lifecycle_module.maybe_record_head_observation_repair(_runtime_bot(), issue_number, review_data)
def handle_pull_request_review_event(state: dict) -> bool:
return events_module.handle_pull_request_review_event(_runtime_bot(), state)
def handle_workflow_run_event(state: dict) -> bool:
return reconcile_module.handle_workflow_run_event(_runtime_bot(), state)
def handle_closed_event(state: dict) -> bool:
return lifecycle_module.handle_closed_event(_runtime_bot(), state)
def handle_comment_event(state: dict) -> bool:
return comment_routing_module.handle_comment_event(_runtime_bot(), state)
def build_pr_comment_observer_payload(issue_number: int) -> dict:
return comment_routing_module.build_pr_comment_observer_payload(_runtime_bot(), issue_number)
def handle_manual_dispatch(state: dict) -> bool:
return maintenance_module.handle_manual_dispatch(_runtime_bot(), state)
def handle_scheduled_check(state: dict) -> bool:
return maintenance_module.handle_scheduled_check(_runtime_bot(), state)
# ==============================================================================
# Main
# ==============================================================================
def classify_event_intent(event_name: str, event_action: str) -> str:
return app_module.classify_event_intent(_runtime_bot(), event_name, event_action)
def event_requires_lease_lock(event_name: str, event_action: str) -> bool:
"""Backwards-compatible helper for tests and call sites."""
return app_module.event_requires_lease_lock(_runtime_bot(), event_name, event_action)
def main():
app_module.main(_runtime_bot())
if __name__ == "__main__":
main()