diff --git a/src/generate_repo_overview/policy_sync.py b/src/generate_repo_overview/policy_sync.py index 4a90185..bbff781 100644 --- a/src/generate_repo_overview/policy_sync.py +++ b/src/generate_repo_overview/policy_sync.py @@ -226,7 +226,7 @@ def fetch_policy_report( gh_runner: Callable[[list[str], str | None], str] | None = None, status_prefix: str = "repo-overview", ) -> bool: - """Fetch the latest completed configured workflow artifact. + """Fetch the latest completed artifact from a scheduled ``main`` run. A false return value means that no usable artifact was available. Fetching is deliberately best-effort because it is an enhancement to the Pages @@ -250,6 +250,13 @@ def fetch_policy_report( config.workflow, "--status", "completed", + # Manual dispatches can select a different policy-sync + # mode, so only consume reports produced by the scheduled + # workflow on the repository's main branch. + "--event", + "schedule", + "--branch", + "main", "--limit", "1", "--json", diff --git a/tests/test_policy_sync.py b/tests/test_policy_sync.py index 64037e9..1554ad5 100644 --- a/tests/test_policy_sync.py +++ b/tests/test_policy_sync.py @@ -198,7 +198,7 @@ def test_policy_report_config_rejects_duplicate_aliases(tmp_path: Path) -> None: load_org_config(path) -def test_fetch_policy_report_downloads_latest_completed_artifact( +def test_fetch_policy_report_downloads_latest_scheduled_main_artifact( tmp_path: Path, monkeypatch: pytest.MonkeyPatch ) -> None: monkeypatch.delenv("GITHUB_TOKEN", raising=False) @@ -215,6 +215,8 @@ def test_fetch_policy_report_downloads_latest_completed_artifact( def fake_gh(args: list[str], token: str | None) -> str: assert token is None if args[:2] == ["run", "list"]: + assert args[args.index("--event") + 1] == "schedule" + assert args[args.index("--branch") + 1] == "main" return "11\n" if args[:2] == ["run", "download"]: download_dir = Path(args[args.index("--dir") + 1]) @@ -240,6 +242,8 @@ def test_fetch_policy_report_is_non_fatal_when_no_run_exists(tmp_path: Path) -> def fake_gh(args: list[str], token: str | None) -> str: del token assert args[:2] == ["run", "list"] + assert args[args.index("--event") + 1] == "schedule" + assert args[args.index("--branch") + 1] == "main" return "null\n" assert fetch_policy_report(config, token="secret", gh_runner=fake_gh) is False