"""The plan items whose chunk left its pull request ready for a person's merge, under `merge = "human"`. The chunk finished them on its branch only, so the default branch's plan holds each until that merge, and no chunk may start from one.""" import dataclasses from failure import Failure from forge.commands import Forge, Run from git_cli.git_repo import Git, git from plan_store.plans import Plan, PlanStore from forge.pulls import ready_pulls from plan_store import stores def awaiting(ref: str, plan: PlanStore, root: str, forge: Forge, forge_run: Run, run: Git = git) -> dict[int, str] | Failure: """Each plan item, by ID, that awaits a person's merge, with its pull request as `# `: an item that the plan held at the commit where the pull request's branch left ref, the default branch, and that the plan at the pull request's head no longer holds. A pull request whose head the checkout hasn't fetched, or whose plan can't be read, names none.""" pulls = ready_pulls(forge, forge_run) if isinstance(pulls, Failure): return pulls found: dict[int, str] = {} for pull in pulls: base = run("merge-base", ref, pull.head, cwd=root) if isinstance(base, Failure): continue before, after = stores.held_at(base.strip(), plan, root, run), stores.held_at(pull.head, plan, root, run) if isinstance(before, Plan) and isinstance(after, Plan): found.update(dict.fromkeys({item.id for item in before.items} - {item.id for item in after.items}, f"#{pull.number} {pull.url}")) return found def marked(plan: Plan, awaited: dict[int, str]) -> Plan: """plan, with each item whose ID awaited holds marked as awaiting that pull request's merge, so the item waits.""" return dataclasses.replace(plan, items=[dataclasses.replace(item, awaits_merge=awaited.get(item.id, "")) for item in plan.items])