# -*- coding: utf-8 -*- r"""更新 Gitee 上已有的 v1.7.0 发行版说明(去掉重复标题)。""" from __future__ import annotations import json import sys import urllib.request from pathlib import Path ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote") TOKEN = (ROOT / "_build" / ".gitee_token").read_text(encoding="utf-8").strip() OWNER, REPO, TAG = "xmz7891", "ykxmz", "v1.7.0" API = f"https://gitee.com/api/v5/repos/{OWNER}/{REPO}" def call(url, payload=None, method="GET", timeout=60): data = json.dumps(payload).encode("utf-8") if payload is not None else None headers = {"User-Agent": "ykxmz"} if payload is not None: headers["Content-Type"] = "application/json;charset=UTF-8" req = urllib.request.Request(url, data=data, headers=headers, method=method) with urllib.request.urlopen(req, timeout=timeout) as resp: text = resp.read().decode("utf-8", "replace") return json.loads(text) if text.strip() else {} def main() -> int: # 从 CHANGELOG 取出这一段,并去掉开头的 "## 1.7.0" text = (ROOT / "_build" / "CHANGELOG.md").read_text(encoding="utf-8-sig") blocks = [b.strip() for b in text.split("\n## ") if b.strip()] body = blocks[0] if blocks else "" lines = body.splitlines() if lines and lines[0].strip().startswith("#"): body = "\n".join(lines[1:]).strip() print(" 准备写入的说明:") for line in body.splitlines(): print(f" {line}") rel = call(f"{API}/releases/tags/{TAG}?access_token={TOKEN}") rid = rel.get("id") print(f"\n 发行版 id = {rid}") if not rid: print(" [失败] 没拿到 id") return 1 updated = call(f"{API}/releases/{rid}", {"access_token": TOKEN, "name": f"ykxmz {TAG.lstrip(chr(118))}", "body": body, "prerelease": False}, method="PATCH") print("\n 更新后的说明:") for line in (updated.get("body") or "").splitlines(): print(f" {line}") print(f"\n ✓ {updated.get('html_url') or f'https://gitee.com/{OWNER}/{REPO}/releases/tag/{TAG}'}") return 0 if __name__ == "__main__": sys.exit(main())