nisse-review: read code from a git clone kept between runs
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 2m3s
CI / e2e (pull_request) Successful in 4m5s

Archives were downloaded and unpacked afresh for every run, which doesn't
scale to very large repositories. Each repository is now cloned once, with
its whole history, under scratch/repos/<owner>/<name>/ (head/ the clone,
base/ a worktree when read). A run fetches every branch and the PR's
refs/pull/N/head, checks out the head exactly, and fails if that head is
gone. Only the latest repository is kept for now.

Git runs walled off: none of the host's git configuration, links checked
out as plain files, no hooks, submodules or LFS, only the Gitea URL's
protocol, and the token as an http.extraHeader for that URL in git's
environment only. A stop ends a git command; a cut-short first clone is
removed. The reader never shows .git. GiteaClient.archive is gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J5Utyfzw7gF7UhjRDEtjTk
This commit is contained in:
dongarandClaude Opus 5.5 committed 2026-10-17 20:37:12 +00:00
1 parent a85e855fc2
commit 3813ad55d6
11 files changed
+642 -139

No files matched your search

+34 -14
View File
@@ -1,8 +1,7 @@
"""A Gitea and a model to review against, in memory."""
import io
import tarfile
from dataclasses import dataclass, field, replace
from pathlib import Path
from typing import Any
from nisse_core.gitea import (
@@ -32,15 +31,39 @@ DIFF = """diff --git a/count.py b/count.py
"""
def archive(files: dict[str, str], *, top: str = "demo") -> bytes:
out = io.BytesIO()
with tarfile.open(fileobj=out, mode="w:gz") as tar:
for path, text in files.items():
raw = text.encode()
info = tarfile.TarInfo(f"{top}/{path}")
info.size = len(raw)
tar.addfile(info, io.BytesIO(raw))
return out.getvalue()
class FakeSources:
"""The repository's code as plain folders: ``gitea.files`` at head,
and at base unless ``base`` is given."""
def __init__(self, gitea: "FakeGitea", root: Path) -> None:
self._gitea = gitea
self._root = root
self.base: dict[str, str] | None = None
self.opened: list[tuple[str, int, str, str]] = []
def open(self, repo: str, number: int, head: str, base: str) -> "FakeTrees":
self.opened.append((repo, number, head, base))
return FakeTrees(self, len(self.opened))
class FakeTrees:
def __init__(self, sources: FakeSources, n: int) -> None:
self._sources = sources
self._n = n
self.made: list[str] = []
def tree(self, ref: str) -> Path:
root = self._sources._root / f"run{self._n}" / ref
if not root.exists():
self.made.append(ref)
files = self._sources._gitea.files
if ref == "base" and self._sources.base is not None:
files = self._sources.base
for path, text in files.items():
(root / path).parent.mkdir(parents=True, exist_ok=True)
(root / path).write_text(text)
root.mkdir(parents=True, exist_ok=True)
return root
def pr(number: int = 7, **more: Any) -> PullRequest:
@@ -172,9 +195,6 @@ class FakeGitea:
def checks(self, repo: str, sha: str) -> str:
return self.ci.get(sha, "success")
def archive(self, repo: str, ref: str) -> bytes:
return archive(self.files)
def issue(self, repo: str, index: int) -> Issue:
return Issue(index, "Counting is wrong", f"in {repo}", "don", ())