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
9 changes: 8 additions & 1 deletion src/generate_repo_overview/policy_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion tests/test_policy_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand All @@ -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
Expand Down