Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/githubbot_core/typed_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions tests/test_typed_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
Loading