You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.1 KiB

2 days ago
# -*- coding: utf-8 -*-
"""按 patch 文件更新票 03/04 的 Answer 与 map.md 决策索引(幂等)。"""
import io, json, sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
base = '.scratch/a4-doc-fields/'
for ticket, marker, patch in [
('issues/03-build-static-reflector.md', '### v2 修复', 'patch_t3.md'),
('issues/04-verify-coverage.md', '### v2 复核', 'patch_t4.md'),
]:
path = base + ticket
txt = open(path, encoding='utf-8').read().rstrip('\n')
if marker in txt:
print(f'skip (already applied): {ticket}')
continue
add = open(base + patch, encoding='utf-8').read().rstrip('\n')
open(path, 'w', encoding='utf-8', newline='').write(txt + '\n' + add + '\n')
print(f'updated: {ticket}')
mpath = base + 'map.md'
txt = open(mpath, encoding='utf-8').read()
pairs = json.load(open(base + 'patch_map.json', encoding='utf-8'))
hit = 0
for p in pairs:
if p['old'] in txt:
txt = txt.replace(p['old'], p['new'], 1)
hit += 1
open(mpath, 'w', encoding='utf-8', newline='').write(txt)
print(f'map rows replaced: {hit}')