Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/reviewer-bot-tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def clear_env():
"COMMENT_BODY",
"COMMENT_AUTHOR",
"COMMENT_ID",
"COMMENT_SOURCE_EVENT_KEY",
"ALLOW_EMPTY_ACTIVE_REVIEWS_WRITE",
"EVENT_ACTION",
"EVENT_NAME",
Expand Down
36 changes: 36 additions & 0 deletions .github/reviewer-bot-tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def test_classify_event_intent_same_repo_dismissed_review_is_non_mutating_defer(
assert intent == reviewer_bot.EVENT_INTENT_NON_MUTATING_DEFER


def test_classify_event_intent_review_comment_is_non_mutating_defer(monkeypatch):
intent = reviewer_bot.classify_event_intent("pull_request_review_comment", "created")
assert intent == reviewer_bot.EVENT_INTENT_NON_MUTATING_DEFER


def test_classify_event_intent_workflow_run_dismissed_review_is_mutating(monkeypatch):
monkeypatch.setenv("WORKFLOW_RUN_EVENT", "pull_request_review")
monkeypatch.setenv("WORKFLOW_RUN_EVENT_ACTION", "dismissed")
Expand Down Expand Up @@ -157,6 +162,37 @@ def fake_acquire():
assert acquire_called["value"] is True


def test_main_workflow_run_review_comment_reconcile_acquires_lock(monkeypatch):
monkeypatch.setenv("EVENT_NAME", "workflow_run")
monkeypatch.setenv("EVENT_ACTION", "completed")
monkeypatch.setenv("WORKFLOW_RUN_EVENT", "pull_request_review_comment")

acquire_called = {"value": False}

def fake_acquire():
acquire_called["value"] = True
return reviewer_bot.LeaseContext(
lock_token="token",
lock_owner_run_id="run",
lock_owner_workflow="workflow",
lock_owner_job="job",
state_issue_url="https://example.com/issues/314",
lock_ref="refs/heads/reviewer-bot-state-lock",
lock_expires_at="2999-01-01T00:00:00+00:00",
)

monkeypatch.setattr(reviewer_bot, "acquire_state_issue_lease_lock", fake_acquire)
monkeypatch.setattr(reviewer_bot, "release_state_issue_lease_lock", lambda: True)
monkeypatch.setattr(reviewer_bot, "load_state", lambda *args, **kwargs: make_state())
monkeypatch.setattr(reviewer_bot, "process_pass_until_expirations", lambda state: (state, []))
monkeypatch.setattr(reviewer_bot, "sync_members_with_queue", lambda state: (state, []))
monkeypatch.setattr(reviewer_bot, "handle_workflow_run_event", lambda state: False)

reviewer_bot.main()

assert acquire_called["value"] is True


def test_main_reloads_state_before_syncing_status_labels(monkeypatch):
monkeypatch.setenv("EVENT_NAME", "issue_comment")
monkeypatch.setenv("EVENT_ACTION", "created")
Expand Down
Loading
Loading