feat: local issue cache and draft-then-push workflow
Replace fetch_issue.py with four scripts around a flat, greppable cache in tmp/issues/. Planning stays offline and issues reach Gitea in one push: - issue_get.py: fetch by key or by filter (--milestone/--label/-q). The list endpoint carries issue bodies, so a whole milestone costs one request per 50 issues. Gitea silently ignores an unresolvable milestones= filter and returns the entire backlog, so the milestone is resolved up front and every returned issue is re-checked locally. --deps walks the dependency graph downwards via the structured sections plus native dependencies and writes tree-<slug>.md. - issue_push.py: validate a local draft against the canonical format, create missing labels with the right colors and exclusivity, POST, delete the draft. - issue_list.py: discovery to stdout, writes nothing. - issue_index.py: rebuild INDEX.md from what is on disk. Files use one metadata field per line with inline lists so plain grep works without a parser. This is a cache and a drafting area, not a mirror: no drift tracking, no sync back. Projects are not fetchable — the projects API is 404 on Gitea 1.26; documented alongside the milestone caveat. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Executable
+94
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
issue_index.py — rebuild tmp/issues/INDEX.md from what is on disk. No network.
|
||||
|
||||
The index is a map of the cache, nothing else: issues that were never fetched
|
||||
do not appear. issue_get.py and issue_push.py call it automatically; run it by
|
||||
hand only after deleting files.
|
||||
|
||||
Usage:
|
||||
issue_index.py [--out tmp/issues]
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from _tea import ISSUE_ROOT, parse_meta, read_file, write_file # noqa: E402
|
||||
|
||||
|
||||
def cell(v):
|
||||
if isinstance(v, list):
|
||||
return ", ".join(v) or "—"
|
||||
v = (v or "").strip()
|
||||
return v.replace("|", "\\|") or "—"
|
||||
|
||||
|
||||
def build(root):
|
||||
rows = []
|
||||
for name in sorted(os.listdir(root)) if os.path.isdir(root) else []:
|
||||
m = re.match(r'^(\d+)\.md$', name)
|
||||
if not m:
|
||||
continue
|
||||
n = int(m.group(1))
|
||||
meta, title, _ = parse_meta(read_file(os.path.join(root, name)))
|
||||
labels = meta.get("labels") or []
|
||||
if isinstance(labels, str):
|
||||
labels = [labels]
|
||||
types = [l for l in labels if l.startswith("type/")]
|
||||
rest = [l for l in labels if not l.startswith("type/")]
|
||||
has_comments = os.path.isfile(os.path.join(root, "%d.comments.md" % n))
|
||||
rows.append({
|
||||
"n": n,
|
||||
"state": cell(meta.get("state")),
|
||||
"type": cell(types[0].split("/", 1)[1] if types else ""),
|
||||
"labels": cell(rest),
|
||||
"title": cell(title),
|
||||
"milestone": cell(meta.get("milestone")),
|
||||
"depends": cell(meta.get("depends")),
|
||||
"comments": ("[%s](%d.comments.md)" % (cell(meta.get("comments")), n)
|
||||
if has_comments else "—"),
|
||||
"fetched": cell(meta.get("fetched"))[:10],
|
||||
})
|
||||
rows.sort(key=lambda r: r["n"])
|
||||
|
||||
trees = sorted(f for f in (os.listdir(root) if os.path.isdir(root) else [])
|
||||
if re.match(r'^tree-\d+\.md$', f))
|
||||
|
||||
out = ["# Issue cache", "",
|
||||
"Local cache of fetched issues — not a mirror. Refresh with "
|
||||
"`issue_get.py <n>`; issues absent here were never fetched.", ""]
|
||||
if rows:
|
||||
out += ["| # | state | type | labels | title | milestone | depends | comments | fetched |",
|
||||
"|---|---|---|---|---|---|---|---|---|"]
|
||||
out += ["| [#%d](%d.md) | %s | %s | %s | %s | %s | %s | %s | %s |" % (
|
||||
r["n"], r["n"], r["state"], r["type"], r["labels"], r["title"],
|
||||
r["milestone"], r["depends"], r["comments"], r["fetched"]) for r in rows]
|
||||
else:
|
||||
out.append("_empty_")
|
||||
if trees:
|
||||
out += ["", "## Dependency trees", ""]
|
||||
out += ["- [%s](%s)" % (t, t) for t in trees]
|
||||
|
||||
drafts_dir = os.path.join(root, "drafts")
|
||||
drafts = sorted(f for f in (os.listdir(drafts_dir) if os.path.isdir(drafts_dir) else [])
|
||||
if f.endswith(".md"))
|
||||
if drafts:
|
||||
out += ["", "## Drafts (not yet pushed)", ""]
|
||||
out += ["- [drafts/%s](drafts/%s)" % (d, d) for d in drafts]
|
||||
|
||||
out.append("")
|
||||
return write_file(os.path.join(root, "INDEX.md"), "\n".join(out)), len(rows)
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description="Rebuild the issue cache index (no network)")
|
||||
ap.add_argument("--out", default=ISSUE_ROOT, help="cache root (default: tmp/issues)")
|
||||
args = ap.parse_args()
|
||||
path, n = build(args.out)
|
||||
print("%s — %d issue(s)" % (path, n))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user