fix(wiki): публикатор ищет существующие страницы через /wiki/pages
wiki-sync / Publish docs/wiki to Gitea wiki (push) Successful in 24s

Gitea хранит страницы с суффиксом «.-» (decision-x.-.md) и GET /wiki/page/<title>
для них отдаёт 404 — скрипт пытался создать их заново и получал 400 «already
exists». Теперь берём словарь title → sub_url из списка страниц и обновляем по
sub_url (проверено: 9 страниц обновлены, 0 ошибок).
This commit is contained in:
2026-11-01 20:06:56 +00:00
parent 859596b030
commit ca55982d29
+20 -4
View File
@@ -97,6 +97,20 @@ def api(method: str, endpoint: str, payload: dict | None = None) -> tuple[int, d
return exc.code, {"error": exc.read().decode("utf-8")[:200]} return exc.code, {"error": exc.read().decode("utf-8")[:200]}
def existing_pages() -> dict[str, str]:
"""title → sub_url для уже созданных страниц.
Gitea хранит часть страниц с суффиксом «.-» (`decision-x.-.md`), поэтому
GET /wiki/page/<title> для них отвечает 404. Список страниц отдаёт и
настоящий title, и рабочий sub_url — по нему и адресуем.
"""
status, body = api("GET", "/pages")
if status != 200 or not isinstance(body, list):
return {}
return {page.get("title", ""): page.get("sub_url") or page.get("title", "")
for page in body if page.get("title")}
def main() -> int: def main() -> int:
parser = argparse.ArgumentParser(description="Публикация docs/wiki в вики Gitea") parser = argparse.ArgumentParser(description="Публикация docs/wiki в вики Gitea")
parser.add_argument("--dry-run", action="store_true", help="Только показать план") parser.add_argument("--dry-run", action="store_true", help="Только показать план")
@@ -114,6 +128,7 @@ def main() -> int:
return 1 return 1
created = updated = failed = 0 created = updated = failed = 0
pages = existing_pages()
for path in files: for path in files:
name = page_name(path) name = page_name(path)
if args.only and name != args.only: if args.only and name != args.only:
@@ -122,12 +137,13 @@ def main() -> int:
message = args.message or f"wiki: {path.relative_to(WIKI_DIR).as_posix()}" message = args.message or f"wiki: {path.relative_to(WIKI_DIR).as_posix()}"
if args.dry_run: if args.dry_run:
print(f"[dry] {path.relative_to(WIKI_DIR)} → {name} ({len(content)} симв.)") action = "обновить" if name in pages else "создать"
print(f"[dry] {path.relative_to(WIKI_DIR)} → {name} ({action}, {len(content)} симв.)")
continue continue
status, _ = api("GET", f"/page/{urllib.parse.quote(name, safe='')}") if name in pages:
if status == 200: target = urllib.parse.quote(pages[name], safe="")
status, body = api("PATCH", f"/page/{urllib.parse.quote(name, safe='')}", status, body = api("PATCH", f"/page/{target}",
{"title": name, "content": content, "message": message}) {"title": name, "content": content, "message": message})
action = "обновлена" action = "обновлена"
else: else: