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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ not a silent override. `permissions.enabled` must stay inside the ceiling.
| `pr.review` | disabled | submits `COMMENT`, `APPROVE` or `REQUEST_CHANGES` to `POST …/pulls/{n}/reviews` with mandatory `sha`/body; requires the configured account and reads review ID, actor, commit, body and state back |
| `pr.close` | disabled | closes a PR only after its exact head is proven contained in the pinned current default branch; requires an explicit repository allowlist, configured account and closed-state readback |
| `actions.dispatch` | disabled | `POST …/actions/workflows/{workflow}/dispatches` for an active workflow |
| `actions.rerun` | disabled | `POST …/actions/runs/{id}/rerun` for a completed, non-fork run of the exact `sha` |
| `actions.rerun` | disabled | Re-run a completed, non-fork run of the exact `sha`. Set `failed_only: true` to re-run failed jobs and their dependents when the run conclusion is `failure`. |
| `pr.create` | disabled | `POST …/pulls` from a bot-prefixed branch onto the default branch |
| `git.push_branch` | disabled | `git push origin <sha>:refs/heads/<branch>` without force, bot prefix only (`typed_actions.push_branch_prefix`, default `bot/`), never the default branch. Requires `multi_bot.merge_account` and the existing `GH_TOKEN` credential reader; the same token is checked against that account before Git runs. Only one exact HTTPS `github.com/<owner>/<repo>` fetch and push URL is accepted. Per-call AskPass disables credential-helper fallback; readback must match the exact SHA and ref. |

Expand Down
13 changes: 10 additions & 3 deletions src/githubbot_core/typed_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,11 @@ def param_denial(kind: str, params: dict, config: dict) -> Optional[str]:
return "workflow must be a workflow file name or id"
if not BRANCH.fullmatch(str(params.get("ref", ""))) or ".." in str(params.get("ref")):
return "ref must be a branch name"
if kind == "actions.rerun" and not str(params.get("run_id", "")).isdecimal():
return "run_id must be numeric"
if kind == "actions.rerun":
if not str(params.get("run_id", "")).isdecimal():
return "run_id must be numeric"
if not isinstance(params.get("failed_only", False), bool):
return "failed_only must be a boolean"
if kind in ("pr.create", "git.push_branch"):
branch = str(params.get("branch", ""))
if not BRANCH.fullmatch(branch) or ".." in branch or branch.endswith((".lock", "/")):
Expand Down Expand Up @@ -569,7 +572,11 @@ def exec_rerun(transport, params: dict, config: dict):
return None, "run is outside the 30-day re-run window; not re-run"
except ValueError:
pass
_, error = transport.request("POST", f"repos/{repo}/actions/runs/{run_id}/rerun", None)
failed_only = params.get("failed_only", False)
if failed_only and run.get("conclusion") != "failure":
return None, "failed_only requires a completed run with conclusion failure"
endpoint = "rerun-failed-jobs" if failed_only else "rerun"
_, error = transport.request("POST", f"repos/{repo}/actions/runs/{run_id}/{endpoint}", None)
return (None, error) if error else ({"readback": {"rerun": run_id}}, None)


Expand Down
26 changes: 26 additions & 0 deletions tests/test_typed_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,32 @@ def test_rerun_refuses_fork_runs_other_heads_and_running_runs():
assert transport.writes == [("POST", f"repos/{REPO}/actions/runs/5/rerun", None)]


def test_rerun_failed_only_uses_the_failed_jobs_endpoint():
run = {"head_sha": SHA, "status": "completed", "conclusion": "failure", "head_repository": {"full_name": REPO}}
action = Action("actions.rerun", {"repo": REPO, "run_id": 5, "sha": SHA, "failed_only": True})
run_path = f"repos/{REPO}/actions/runs/5"
transport = Transport({run_path: run})

assert actions.apply([action], transport, config())["receipts"][0]["status"] == "applied"
assert transport.writes == [("POST", f"{run_path}/rerun-failed-jobs", None)]

for run_id, overrides in enumerate(({"conclusion": "success"}, {"head_sha": OTHER}, {"status": "queued"}), 6):
blocked_action = Action("actions.rerun", {**action.params, "run_id": run_id})
transport = Transport({f"repos/{REPO}/actions/runs/{run_id}": {**run, **overrides}})
assert actions.apply([blocked_action], transport, config())["receipts"][0]["status"] == "failed"
assert transport.writes == []


def test_rerun_failed_only_requires_a_boolean():
action = Action("actions.rerun", {"repo": REPO, "run_id": 5, "sha": SHA, "failed_only": "false"})
transport = Transport({})
receipt = actions.apply([action], transport, config())["receipts"][0]

assert receipt["status"] == "denied"
assert "failed_only must be a boolean" in receipt["detail"]
assert transport.writes == []


def test_rerun_outside_30_day_window_is_refused_without_a_request():
# GitHub only allows a re-run up to 30 days after the initial run; the POST
# would answer 403, which the transport treats as a host-wide policy HOLD.
Expand Down
Loading