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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Format: [Keep a Changelog](https://keepachangelog.com/de/1.1.0/), [Semantic Vers

## [Unreleased]

### Behoben / Fixed

- `actions.rerun`: Ein Lauf außerhalb des 30-Tage-Rerun-Fensters von GitHub wird lokal abgelehnt, ohne den POST zu senden. Der sonst folgende HTTP 403 setzte einen persistenten host-weiten `policy_hold` und blockierte alle koordinierten Schreibaktionen / a run older than 30 days is refused locally without sending the POST; its 403 used to set a persistent host-wide policy HOLD. Jeder andere 403 bleibt unverändert fail-closed (Ticket T-20261127-325831929).

## [0.2.2] - 2026-11-22

### Behoben / Fixed
Expand Down
11 changes: 11 additions & 0 deletions src/githubbot_core/typed_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import re
import os
from datetime import datetime, timedelta, timezone
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -534,6 +535,16 @@ def exec_rerun(transport, params: dict, config: dict):
return None, "run comes from a fork; fork runs are never re-run or approved by the bot"
if run.get("status") != "completed":
return None, f"run is {run.get('status')!r}, not completed"
# GitHub re-runs only up to 30 days after the initial run (docs.github.com, "Re-run
# workflows and jobs"). Sending the POST anyway earns a 403, which the transport must
# treat as a host-wide policy HOLD, so refuse locally and never send it. A missing or
# unreadable timestamp changes nothing: the request goes out as before.
try:
started = datetime.fromisoformat(str(run.get("created_at")).replace("Z", "+00:00"))
if datetime.now(timezone.utc) - started > timedelta(days=30):
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)
return (None, error) if error else ({"readback": {"rerun": run_id}}, None)

Expand Down
24 changes: 24 additions & 0 deletions tests/test_typed_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,30 @@ 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_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.
from datetime import datetime, timedelta, timezone

def run(age_days):
stamp = (datetime.now(timezone.utc) - timedelta(days=age_days)).strftime("%Y-%m-%dT%H:%M:%SZ")
return {
"head_sha": SHA,
"status": "completed",
"head_repository": {"full_name": REPO},
"created_at": stamp,
}

action = Action("actions.rerun", {"repo": REPO, "run_id": 5, "sha": SHA})
transport = Transport({f"repos/{REPO}/actions/runs/5": run(46)})
receipt = actions.apply([action], transport, config())["receipts"][0]
assert receipt["status"] == "failed" and "30-day" in receipt["detail"]
assert transport.writes == []
transport = Transport({f"repos/{REPO}/actions/runs/5": run(29)})
assert actions.apply([action], transport, config())["receipts"][0]["status"] == "applied"
assert transport.writes == [("POST", f"repos/{REPO}/actions/runs/5/rerun", None)]


def test_dispatch_needs_an_active_workflow():
action = Action("actions.dispatch", {"repo": REPO, "workflow": "ci.yml", "ref": "bot/fix"})
transport = Transport({f"repos/{REPO}/actions/workflows/ci.yml": {"state": "disabled_manually"}})
Expand Down
Loading