Skip to content

Commit 3780a5d

Browse files
committed
fix(reviewer-bot): prefer current-head reviews and track thread replies
1 parent 97dab0f commit 3780a5d

File tree

10 files changed

+1019
-84
lines changed

10 files changed

+1019
-84
lines changed

.github/reviewer-bot-tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def clear_env():
99
"COMMENT_BODY",
1010
"COMMENT_AUTHOR",
1111
"COMMENT_ID",
12+
"COMMENT_SOURCE_EVENT_KEY",
1213
"ALLOW_EMPTY_ACTIVE_REVIEWS_WRITE",
1314
"EVENT_ACTION",
1415
"EVENT_NAME",

.github/reviewer-bot-tests/test_main.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ def test_classify_event_intent_same_repo_dismissed_review_is_non_mutating_defer(
7878
assert intent == reviewer_bot.EVENT_INTENT_NON_MUTATING_DEFER
7979

8080

81+
def test_classify_event_intent_review_comment_is_non_mutating_defer(monkeypatch):
82+
intent = reviewer_bot.classify_event_intent("pull_request_review_comment", "created")
83+
assert intent == reviewer_bot.EVENT_INTENT_NON_MUTATING_DEFER
84+
85+
8186
def test_classify_event_intent_workflow_run_dismissed_review_is_mutating(monkeypatch):
8287
monkeypatch.setenv("WORKFLOW_RUN_EVENT", "pull_request_review")
8388
monkeypatch.setenv("WORKFLOW_RUN_EVENT_ACTION", "dismissed")
@@ -157,6 +162,37 @@ def fake_acquire():
157162
assert acquire_called["value"] is True
158163

159164

165+
def test_main_workflow_run_review_comment_reconcile_acquires_lock(monkeypatch):
166+
monkeypatch.setenv("EVENT_NAME", "workflow_run")
167+
monkeypatch.setenv("EVENT_ACTION", "completed")
168+
monkeypatch.setenv("WORKFLOW_RUN_EVENT", "pull_request_review_comment")
169+
170+
acquire_called = {"value": False}
171+
172+
def fake_acquire():
173+
acquire_called["value"] = True
174+
return reviewer_bot.LeaseContext(
175+
lock_token="token",
176+
lock_owner_run_id="run",
177+
lock_owner_workflow="workflow",
178+
lock_owner_job="job",
179+
state_issue_url="https://example.com/issues/314",
180+
lock_ref="refs/heads/reviewer-bot-state-lock",
181+
lock_expires_at="2999-01-01T00:00:00+00:00",
182+
)
183+
184+
monkeypatch.setattr(reviewer_bot, "acquire_state_issue_lease_lock", fake_acquire)
185+
monkeypatch.setattr(reviewer_bot, "release_state_issue_lease_lock", lambda: True)
186+
monkeypatch.setattr(reviewer_bot, "load_state", lambda *args, **kwargs: make_state())
187+
monkeypatch.setattr(reviewer_bot, "process_pass_until_expirations", lambda state: (state, []))
188+
monkeypatch.setattr(reviewer_bot, "sync_members_with_queue", lambda state: (state, []))
189+
monkeypatch.setattr(reviewer_bot, "handle_workflow_run_event", lambda state: False)
190+
191+
reviewer_bot.main()
192+
193+
assert acquire_called["value"] is True
194+
195+
160196
def test_main_reloads_state_before_syncing_status_labels(monkeypatch):
161197
monkeypatch.setenv("EVENT_NAME", "issue_comment")
162198
monkeypatch.setenv("EVENT_ACTION", "created")

0 commit comments

Comments
 (0)