diff --git a/src/githubbot_core/typed_actions.py b/src/githubbot_core/typed_actions.py index ec24dfd..ff64db9 100644 --- a/src/githubbot_core/typed_actions.py +++ b/src/githubbot_core/typed_actions.py @@ -833,6 +833,9 @@ def exec_push_branch(transport, params: dict, config: dict): return None, "target repository unreadable for the configured bot account" if error or not isinstance(repository, dict) or not isinstance(repository.get("default_branch"), str): return None, "target repository unreadable for the configured bot account" + permissions = repository.get("permissions") + if isinstance(permissions, dict) and permissions.get("push") is False: + return None, "configured bot account has no push permission for the target repository" default = repository["default_branch"] if branch == default: return None, "never pushes the default branch" diff --git a/tests/test_typed_actions.py b/tests/test_typed_actions.py index a8d037c..f9a5457 100644 --- a/tests/test_typed_actions.py +++ b/tests/test_typed_actions.py @@ -537,6 +537,27 @@ def missing_reader(providers): assert calls == [] +def test_push_branch_stops_when_bot_has_no_push_permission(monkeypatch): + token, _ = _mock_push_token(monkeypatch) + transport = TokenTransport( + {f"repos/{REPO}": {"default_branch": "main", "permissions": {"push": False}}}, + login="example-bot", + ) + git_calls = [] + + def git(cmd, **kwargs): + git_calls.append(cmd) + return _fake_git_output(cmd, origin=f"https://github.com/{REPO}.git") + + monkeypatch.setattr(typed_actions, "_git", git) + receipt = actions.apply([_push_action()], transport, config())["receipts"][0] + + assert receipt["status"] == "failed" + assert receipt["detail"] == "configured bot account has no push permission for the target repository" + assert transport.token_reads == [(token, "user"), (token, f"repos/{REPO}")] + assert git_calls == [] + + def test_push_branch_stops_before_network_push_for_client_certificate_policy(monkeypatch): _mock_push_token(monkeypatch) calls = []