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
58 changes: 48 additions & 10 deletions scripts/fleet/repo-universe/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@

Builds the universe list from two sources:

1. GitHub enumeration of the developing-today org and the dezren39
account (`gh api --paginate orgs/developing-today/repos` and
1. GitHub enumeration of the developing-today and
developing-today-forks orgs and the dezren39 account
(`gh api --paginate orgs/developing-today/repos`,
`gh api --paginate orgs/developing-today-forks/repos` and
`gh api --paginate 'user/repos?affiliation=owner'`, authenticated
as dezren39), captured as JSON files. (NOT `users/dezren39/repos`:
that endpoint returns public repos only and silently misses
private owned repos.)
as dezren39), captured as JSON files. The two org captures are
merged before classification: developing-today/opencode and
developing-today/openchamber moved to the developing-today-forks
org on 2026-11-04 (#5615), so enumerating only developing-today
would lose them on a full regeneration. (NOT
`users/dezren39/repos`: that endpoint returns public repos only
and silently misses private owned repos.)
2. The 2026-10-27 all-repos census (goal-workspace
`hidden_files/git-cleanup-2026-10-27/all-repos-census.md`): every
clone remote on laptop + sandbox, including the nested clones
Expand Down Expand Up @@ -37,7 +43,8 @@
on unchanged inputs produces a zero diff (idempotent).

Usage:
generate.py --org-json org.json --user-json user.json \
generate.py --org-json org.json --forks-org-json forks-org.json \
--user-json user.json \
--census /path/to/all-repos-census.md \
--census-label 'hidden_files/git-cleanup-2026-10-27/all-repos-census.md (repo-health goal workspace)' \
--output doc/fleet/repo-universe.yaml
Expand All @@ -57,6 +64,10 @@
from pathlib import Path

OWNED_OWNERS = {"developing-today", "developing-today-forks", "dezren39"}
# The two orgs enumerated for the universe (#5615): opencode and
# openchamber moved from developing-today to developing-today-forks
# on 2026-11-04, so both orgs are captured and merged.
ORGS = ("developing-today", "developing-today-forks")
CLASSES = ("owned", "fork", "upstream-dependency", "archive-nested")
WATCHES = ("issues", "inventory-only")

Expand Down Expand Up @@ -95,6 +106,18 @@ def load_enumeration(path: str | None) -> list[dict]:
return decode_pages(Path(path).read_text())


def merge_repos(*groups: list[dict]) -> list[dict]:
"""Merge enumeration captures into one list, deduped by
full_name (first capture wins). A repo lives in exactly one org,
but the org and user captures can overlap, and the two org
captures are merged before classification (#5615)."""
merged: dict[str, dict] = {}
for group in groups:
for repo in group:
merged.setdefault(repo["full_name"], repo)
return list(merged.values())


EXPECTED_USER_LOGIN = "dezren39"


Expand Down Expand Up @@ -220,7 +243,7 @@ def build(
lines.append("#")
lines.append("# Generated by scripts/fleet/repo-universe/generate.py from:")
lines.append(
"# - GitHub enumeration: orgs/developing-today/repos + user/repos?affiliation=owner (as dezren39)"
"# - GitHub enumeration: orgs/developing-today/repos + orgs/developing-today-forks/repos + user/repos?affiliation=owner (as dezren39)"
)
lines.append(f"# - Census: {census_label}")
lines.append(
Expand Down Expand Up @@ -277,7 +300,11 @@ def main(argv: list[str] | None = None) -> int:
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument(
"--org-json",
help="captured `gh api --paginate orgs/developing-today/repos` JSON",
help="captured `gh api --paginate orgs/developing-today/repos` JSON (the developing-today half of the two-org enumeration; merged with --forks-org-json before classification)",
)
ap.add_argument(
"--forks-org-json",
help="captured `gh api --paginate orgs/developing-today-forks/repos` JSON (the developing-today-forks half of the two-org enumeration; merged with --org-json before classification)",
)
ap.add_argument(
"--user-json",
Expand All @@ -299,7 +326,15 @@ def main(argv: list[str] | None = None) -> int:

if args.live:
require_expected_account()
org_repos = fetch_live("orgs/developing-today/repos?per_page=100&type=all")
# Both orgs (#5615): developing-today-forks holds opencode and
# openchamber since 2026-11-04; enumerating developing-today
# alone would drop them from a full regeneration.
org_repos = merge_repos(
*(
fetch_live(f"orgs/{org}/repos?per_page=100&type=all")
for org in ORGS
)
)
# user/repos?affiliation=owner, NOT users/dezren39/repos: the
# latter returns public repos only and silently misses private
# owned repos (dezren39/hatch-personal among them, found at
Expand All @@ -321,7 +356,10 @@ def main(argv: list[str] | None = None) -> int:
ap.error(
"offline mode requires " + " and ".join(missing) + " (or use --live)"
)
org_repos = load_enumeration(args.org_json)
org_repos = merge_repos(
load_enumeration(args.org_json),
load_enumeration(args.forks_org_json),
)
user_repos = load_enumeration(args.user_json)

census_text = Path(args.census).read_text()
Expand Down
86 changes: 86 additions & 0 deletions scripts/fleet/repo-universe/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ def repo(name: str, fork: bool = False) -> dict:
USER = [repo(n) for n in FLEET_AND_SIDE if n.startswith("dezren39/")]
USER.append(repo("dezren39/scratch"))

# The developing-today-forks org capture (#5615): opencode and
# openchamber moved there on 2026-11-04 and are GitHub forks;
# some-tool is a forks-org-owned non-fork repo.
FORKS_ORG = [
repo("developing-today-forks/opencode", fork=True),
repo("developing-today-forks/openchamber", fork=True),
repo("developing-today-forks/some-tool"),
]

CENSUS = """# All-repos census — fixture

| /home/user/git/code | https://github.com/developing-today/code.git | main |
Expand All @@ -57,6 +66,7 @@ class GenerateTest(unittest.TestCase):
def setUp(self) -> None:
self.dir = Path(tempfile.mkdtemp())
(self.dir / "org.json").write_text(json.dumps(ORG))
(self.dir / "forks-org.json").write_text(json.dumps(FORKS_ORG))
(self.dir / "user.json").write_text(json.dumps(USER))
(self.dir / "census.md").write_text(CENSUS)
self.out = self.dir / "repo-universe.yaml"
Expand All @@ -68,6 +78,8 @@ def run_gen(self) -> str:
str(GENERATE),
"--org-json",
str(self.dir / "org.json"),
"--forks-org-json",
str(self.dir / "forks-org.json"),
"--user-json",
str(self.dir / "user.json"),
"--census",
Expand Down Expand Up @@ -125,6 +137,80 @@ def fake_run(cmd, **kwargs):
)
self.assertFalse(live_out.exists())

def test_forks_org_repos_are_enumerated(self) -> None:
# #5615: the forks-org capture is merged before classification,
# so forks-org repos land in the artifact from the GitHub
# enumeration itself, not via census or overrides.
artifact = self.run_gen()
self.assertIn(
"- name: developing-today-forks/some-tool\n"
" url: https://github.com/developing-today-forks/some-tool\n"
" class: owned\n watch: issues\n sources: [github]",
artifact,
)
self.assertIn(
"- name: developing-today-forks/opencode\n"
" url: https://github.com/developing-today-forks/opencode\n"
" class: fork\n watch: inventory-only\n sources: [github]",
artifact,
)
self.assertIn(
"- name: developing-today-forks/openchamber\n"
" url: https://github.com/developing-today-forks/openchamber\n"
" class: fork\n watch: inventory-only\n sources: [github]",
artifact,
)

def test_live_fetches_both_orgs(self) -> None:
# --live must enumerate orgs/developing-today-forks/repos
# alongside orgs/developing-today/repos (#5615) and merge the
# captures before classification.
spec = importlib.util.spec_from_file_location("generate", GENERATE)
gen = importlib.util.module_from_spec(spec)
spec.loader.exec_module(gen)
requested: list[str] = []

def fake_run(cmd, **kwargs):
if "--paginate" in cmd:
endpoint = cmd[-1]
requested.append(endpoint)
if "developing-today-forks" in endpoint:
payload = FORKS_ORG
elif "user/repos" in endpoint:
payload = USER
else:
payload = ORG
return subprocess.CompletedProcess(
cmd, 0, stdout=json.dumps(payload), stderr=""
)
return subprocess.CompletedProcess(
cmd, 0, stdout=json.dumps({"login": "dezren39"}), stderr=""
)

live_out = self.dir / "live-out.yaml"
with mock.patch.object(gen.subprocess, "run", side_effect=fake_run):
rc = gen.main(
[
"--live",
"--census",
str(self.dir / "census.md"),
"--output",
str(live_out),
]
)
self.assertEqual(rc, 0)
self.assertTrue(
any(e.startswith("orgs/developing-today/repos") for e in requested),
f"developing-today org not enumerated: {requested}",
)
self.assertTrue(
any(e.startswith("orgs/developing-today-forks/repos") for e in requested),
f"developing-today-forks org not enumerated: {requested}",
)
out = live_out.read_text()
self.assertIn("developing-today-forks/some-tool", out)
self.assertIn("developing-today-forks/opencode", out)

def test_offline_mode_requires_both_captures(self) -> None:
# Omitting a capture without --live must fail, not silently
# regenerate with that source emptied (deleting every
Expand Down