mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 16:00:43 +00:00
73 lines
2.6 KiB
Python
73 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
r"""更新 Gitee 上已有的 v1.7.0 发行版说明(去掉重复标题)。"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import urllib.error
|
|
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
|
|
|
|
# Gitee 的 PATCH 需要 tag_name + target_commitish,光给 body 会 400
|
|
payload = {
|
|
"access_token": TOKEN,
|
|
"tag_name": TAG,
|
|
"name": f"ykxmz {TAG.lstrip(chr(118))}",
|
|
"body": body,
|
|
"prerelease": False,
|
|
"target_commitish": "main",
|
|
}
|
|
try:
|
|
updated = call(f"{API}/releases/{rid}", payload, method="PATCH")
|
|
except urllib.error.HTTPError as exc:
|
|
detail = exc.read().decode("utf-8", "replace")[:300]
|
|
print(f" PATCH 失败 HTTP {exc.code}: {detail}")
|
|
print(" 改用 PUT 再试…")
|
|
updated = call(f"{API}/releases/{rid}", payload, method="PUT")
|
|
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())
|