"""Shared by the end-to-end tests: each run gets work that can't already be done, and a base branch of its own, so runs never depend on one another or on what earlier runs merged.""" import contextlib import os from collections.abc import Iterator from nisse_dev.gitea import GiteaClient, GiteaError def task(run: str) -> str: """A request no earlier run can have fulfilled.""" return ( f"Add a function vowels_{run}(text) to the sandbox package that returns " "how many of a, e, i, o, u (either case) the text contains, with tests." ) def operator_gitea(url: str) -> GiteaClient: token = os.environ.get("NISSE_OPERATOR_TOKEN", "") assert token.strip(), ( "NISSE_OPERATOR_TOKEN is not set: the test operator's Gitea token" ) return GiteaClient(url, token) @contextlib.contextmanager def base_branch(operator: GiteaClient, repo: str, run: str) -> Iterator[str]: """A branch off main for this run's PRs to target and merge into, so nothing accumulates in main; deleted afterwards.""" name = f"e2e-base-{run}" operator._request( "POST", f"/repos/{repo}/branches", json={"new_branch_name": name, "old_branch_name": "main"}, ) try: yield name finally: with contextlib.suppress(GiteaError): operator._request("DELETE", f"/repos/{repo}/branches/{name}")