publish.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. """Generate a deterministic GitHub write plan for the connected Hilda-Bot account.
  2. The agent executes this plan through the GitHub connector; no PAT is stored locally.
  3. """
  4. import argparse
  5. import json
  6. import subprocess
  7. from pathlib import Path
  8. from pipeline import ROOT, LIB
  9. def plan(paths, branch, title):
  10. elements = []
  11. for item in paths:
  12. path = (ROOT/item).resolve()
  13. if not path.is_relative_to(LIB.resolve()) or path.suffix != '.md':
  14. raise ValueError('Only version Markdown files may be published')
  15. content = path.read_text()
  16. if '\nllm-transalte: true\n' not in content or '\nwip:' in content:
  17. raise ValueError('Apply translation packet before publishing')
  18. elements.append({'path':str(path.relative_to(ROOT)), 'mode':'100644','type':'blob','content':content})
  19. if not elements:
  20. raise ValueError('No translations')
  21. base = subprocess.check_output(['git','rev-parse','HEAD'],cwd=ROOT,text=True).strip()
  22. tree = subprocess.check_output(['git','rev-parse','HEAD^{tree}'],cwd=ROOT,text=True).strip()
  23. return {'repository_full_name':'Hilda-Bot/PCL2-NewsHomepage','pr_repository_full_name':'Light-Beacon/PCL2-NewsHomepage','head':'Hilda-Bot:'+branch,'account':'Hilda-Bot','email':'[email protected]','branch':branch,'base':'main','parent_sha':base,'base_tree_sha':tree,'tree_elements':elements,'message':title,'pr_title':title,'pr_body':'以 Minecraft.net 官方更新日志为原文、中文 Minecraft Wiki 为译名参考。使用固定版本 SPXX 转换,LLM 翻译;已校验源链接和 MC 漏洞编号,移除 wip 并标记 llm-transalte: true。\n\n请人工复核译文。'}
  24. if __name__ == '__main__':
  25. parser = argparse.ArgumentParser(description=__doc__)
  26. parser.add_argument('--branch',required=True)
  27. parser.add_argument('--title',required=True)
  28. parser.add_argument('paths',nargs='+')
  29. args = parser.parse_args()
  30. print(json.dumps(plan(args.paths,args.branch,args.title),ensure_ascii=False,indent=2))