Repository navigation
Check size budgets against current target before queue admission #1309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,10 +70,12 @@ def review_marker(head: str, kind: str, source: str = "model") -> str: | |
| # --------------------------------------------------------------------------- git / context | ||
|
|
||
|
|
||
| def _git(cwd: Path, *args: str, timeout: float = GIT_TIMEOUT) -> str: | ||
| done = _proc.run(["git", *args], cwd=cwd, env_allowlist=worktree.GIT_ENV, timeout=timeout) | ||
| def _git(cwd: Path, *args: str, timeout: float = GIT_TIMEOUT, | ||
| extra_env: dict[str, str] | None = None) -> str: | ||
| done = _proc.run(["git", *args], cwd=cwd, env_allowlist=worktree.GIT_ENV, | ||
| timeout=timeout, extra_env=extra_env) | ||
| if done.exit_code != 0: | ||
| raise CliError(f"git {' '.join(args)} failed: {_proc.tail(done.stderr, 1)}") | ||
| raise CliError(f"git {' '.join(args)} failed: {_proc.tail(done.stderr or done.stdout, 1)}") | ||
| return done.stdout.strip() | ||
|
|
||
|
|
||
|
|
@@ -1148,6 +1150,36 @@ def _cleanup(wt: Path, pr: github.PR) -> None: | |
| print(f"warning: merged but worktree cleanup failed: {exc}{retry}", file=sys.stderr) | ||
|
|
||
|
|
||
| _SIZE_BUDGET = "scripts/size_budget.sh" | ||
|
|
||
|
|
||
| def _prequeue_size_budget( | ||
| wt: Path, config: Config, pr: github.PR, readiness: github.Readiness, | ||
| ) -> None: | ||
| if not readiness.ready or config.merge_strategy != "mergify" or _SIZE_BUDGET not in config.checks: | ||
| return | ||
| origin = _git(wt, "remote", "get-url", "origin") | ||
| with tempfile.TemporaryDirectory(prefix="loopzero-size-") as directory: | ||
| root = Path(directory) | ||
| env = {"GIT_CONFIG_NOSYSTEM": "1", "GIT_CONFIG_GLOBAL": os.devnull, | ||
| "GIT_ATTR_NOSYSTEM": "1", "GIT_NO_REPLACE_OBJECTS": "1", "PYTHON": sys.executable} | ||
| git = partial(_git, root, extra_env=env) | ||
| git("clone", "--shared", "--no-checkout", "--template=", str(wt), ".") | ||
| # Fetch with the user's credential configuration for private origins. | ||
| _git(root, "fetch", "--no-tags", "--no-recurse-submodules", "--", | ||
| origin, f"refs/heads/{config.base_branch}") | ||
| base = git("rev-parse", "FETCH_HEAD^{commit}") | ||
| script = git("show", f"{base}:{_SIZE_BUDGET}") | ||
| tree = git("merge-tree", "--write-tree", base, pr.head_sha) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Merge conflict with the fresh target gives an unclear error If the PR head no longer merges cleanly with the freshly fetched target, |
||
| # A candidate symlink must not read files outside the temporary checkout. | ||
| git("-c", "core.symlinks=false", "read-tree", "--reset", "-u", tree) | ||
| result = _proc.run(["bash", "-s", "--", base], input=script + "\n", cwd=root, | ||
| env_allowlist=("PATH",), extra_env=env, timeout=GIT_TIMEOUT, | ||
| merge_output=True) | ||
| if result.exit_code: | ||
| raise CliError("current target size budget failed:\n" + result.stdout.rstrip()) | ||
|
|
||
|
|
||
| def cmd_ready(args: argparse.Namespace) -> int: | ||
| wt, config = _context(args, pin_checks=True) | ||
| pr, readiness = _pr_readiness(wt, config, workflow_wait=args.wait is not None) | ||
|
|
@@ -1172,6 +1204,7 @@ def cmd_ready(args: argparse.Namespace) -> int: | |
| return 3 | ||
| pr, readiness, kicked = waited | ||
| assert readiness is not None | ||
| _prequeue_size_budget(wt, config, pr, readiness) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: In |
||
| if readiness.ready and pr.is_draft and not kicked: | ||
| github.mark_ready(config.repo, pr.number) | ||
| if args.wait is not None: | ||
|
|
@@ -1479,7 +1512,7 @@ class _AdmissionDeadline(Exception): | |
|
|
||
|
|
||
| def _merge_with_mergify( | ||
| config: Config, pr: github.PR, | ||
| wt: Path, config: Config, pr: github.PR, | ||
| readiness: github.Readiness, deadline: float | None, admit_by: float | None = None, | ||
| ) -> str | None: | ||
| """Request Mergify after readiness verifies the source gates and queue configuration.""" | ||
|
|
@@ -1506,6 +1539,7 @@ def _merge_with_mergify( | |
| return sha | ||
| raise CliError(f"PR #{pr.number} left Mergify queue {queue} unmerged. {MERGIFY_DEQUEUE_HINT}") | ||
| if not confirmed and not requested: | ||
| _prequeue_size_budget(wt, config, pr, readiness) | ||
| if admit_by is not None and time.monotonic() > admit_by: | ||
| raise _AdmissionDeadline | ||
| mergify.request(config.repo, pr.number, pr.head_sha, queue) | ||
|
|
@@ -1557,7 +1591,7 @@ def cmd_merge(args: argparse.Namespace) -> int: | |
| print(f"PR #{pr.number} was already merged as {sha[:12]}; cleaning up") | ||
| elif config.merge_strategy == "mergify": | ||
| try: | ||
| sha = _merge_with_mergify(config, pr, readiness, deadline, admit_by) | ||
| sha = _merge_with_mergify(wt, config, pr, readiness, deadline, admit_by) | ||
| except _AdmissionDeadline: | ||
| print(f"timed out before requesting Mergify for PR #{pr.number}") | ||
| return 3 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: The fetch skips the hardened scratch environment without saying why
Every other git call in the scratch repo goes through the
gitpartial withGIT_CONFIG_NOSYSTEM,GIT_CONFIG_GLOBAL=/dev/nulland the related settings. The fetch calls_git(root, ...)directly. That is probably on purpose, so the user's credential helper can authenticate toorigin, but the code doesn't say so. A later edit could 'fix' it to usegitand break private-repo fetches. Add a one-line comment explaining that the fetch needs the user's global config for credentials.