Commit 4f496c52 authored by 刘正强's avatar 刘正强

fix: push_config_fixed.py 兼容本地 remote_sync.py (pull|push)

- 当 issues-ops 远端仓库不存在时,先准备本地缓存 - 远端仓库创建后,重跑本脚本即可完成 push 和 registry 登记
parent c4eb1f13
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""push_config.py 的本地兼容版本。 r"""push_config.py 的本地兼容版本。
修复:本地 bos-issue-ledger/scripts/remote_sync.py 只支持 --cmd pull|push, 修复:本地 bos-issue-ledger/scripts/remote_sync.py 只支持 --cmd pull|push,
不支持 push-mr;本脚本使用 --cmd push 并去掉不支持的参数。 不支持 push-mr;本脚本使用 --cmd push 并去掉不支持的参数。
...@@ -59,7 +59,7 @@ def main(): ...@@ -59,7 +59,7 @@ def main():
git_root = os.path.join(cache_dir, project_slug) git_root = os.path.join(cache_dir, project_slug)
target_dir = os.path.join(git_root, subdir) if subdir else git_root target_dir = os.path.join(git_root, subdir) if subdir else git_root
# 如果缓存不存在,先尝试 clone;失败则初始化裸缓存并加 remote # 如果缓存不存在,先尝试 clone;失败则初始化本地缓存并加 remote,等远端可用后再推
if not os.path.isdir(os.path.join(git_root, ".git")): if not os.path.isdir(os.path.join(git_root, ".git")):
print(json.dumps({"step": "clone", "repo": repo}, ensure_ascii=False)) print(json.dumps({"step": "clone", "repo": repo}, ensure_ascii=False))
r = subprocess.run( r = subprocess.run(
...@@ -69,19 +69,17 @@ def main(): ...@@ -69,19 +69,17 @@ def main():
"--cache-dir", cache_dir], "--cache-dir", cache_dir],
capture_output=True, text=True) capture_output=True, text=True)
if r.returncode != 0: if r.returncode != 0:
# 远端不存在或无法访问:初始化本地缓存,等远端可用后再推
print(json.dumps({ print(json.dumps({
"ok": False,
"step": "clone/pull", "step": "clone/pull",
"error": (r.stderr or r.stdout).strip()[:500], "note": "远端仓库可能尚未创建或无访问权限,转为本地缓存准备。"
"note": "远端仓库可能尚未创建或无访问权限。已在本地准备缓存,远端可用后请重跑本脚本。"
}, ensure_ascii=False)) }, ensure_ascii=False))
sys.exit(1) os.makedirs(git_root, exist_ok=True)
subprocess.run(["git", "init"], cwd=git_root, capture_output=True)
subprocess.run(["git", "remote", "add", "origin", repo], cwd=git_root, capture_output=True)
# 把当前 KB 文件同步到缓存目录 # 把当前 KB 文件同步到缓存目录
if os.path.abspath(kb) != os.path.abspath(target_dir): if os.path.abspath(kb) != os.path.abspath(target_dir):
os.makedirs(target_dir, exist_ok=True) os.makedirs(target_dir, exist_ok=True)
# 复制 list-config.md 及 issues/、assets/ 等
for item in os.listdir(kb): for item in os.listdir(kb):
src = os.path.join(kb, item) src = os.path.join(kb, item)
dst = os.path.join(target_dir, item) dst = os.path.join(target_dir, item)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment